Einzelnen Beitrag anzeigen

Benutzerbild von sakura
sakura

Registriert seit: 10. Jun 2002
Ort: München
11.412 Beiträge
 
Delphi 11 Alexandria
 

Auslesen der Eigenschaften eines Control-Panel-Applets

  Alt 3. Aug 2003, 13:28
Jedes Control-Panel-Applet muss die Funktion CPlApplet exportieren. Diese Funktion übernimmt die gesamte Steuerung des Applets nach aussen.

Die folgende Funktion liesst die Anzeige-Namen aller Sub-Module einer CPL-Datei aus.
Delphi-Quellcode:
uses
  Cpl;

...

// PROC: GetCPLCaptions
// Returns the Captions of all CPL-Sub-Modules in a string list.
// NOTE: One CPL-File may display multiple sub-modules in the system settings
procedure GetCPLCaptions(CPLFileName: String; Strings: TStrings);
var
  DLLHandle: Cardinal;
  I, SubModuleCount: Integer;
  CPLAppletFunc: Pointer;
  CPLInfo: TCPLInfo;
  ResStringRec: TResStringRec;
begin
  // load library
  DLLHandle := LoadLibrary(PChar(CPLFileName));
  if DLLHandle <> INVALID_HANDLE_VALUE then
  try
    // library loaded successfully
    // load entry-point procedure
    CPLAppletFunc := GetProcAddress(DLLHandle, 'CPlApplet');
    if CPLAppletFunc <> nil then
    begin
      // entry-point found
      // get count of sub modules within CPL-file
      SubModuleCount := TCPLApplet(CPLAppletFunc)(HInstance, CPL_GETCOUNT, 0,
          0);
      // iterate all sub-modules (0-based list)
      for I := 0 to Pred(SubModuleCount) do
      begin
        // get resource ids for current sub-module
        TCPLApplet(CPLAppletFunc)(HInstance, CPL_INQUIRE, I, Integer(@CPLInfo));
        // load string resource for caption
        ResStringRec.Module := @DLLHandle;
        ResStringRec.Identifier := CPLInfo.idName;
        // and insert into string list
        Strings.Add(LoadResString(@ResStringRec));
      end;
    end;
  finally
    // unload library
    FreeLibrary(DLLHandle);
  end;
end;
Der Prozedur muss nur der Name der DLL (inkl. Pfad) und eine StringListe zur Aufnahme der Captions übergeben werden. Folgender Code zeigt ein Beispiel zur Nutzung
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
begin
  Memo1.Clear;
  GetCPLCaptions('C:\WINNT\system32\hdwwiz.cpl', Memo1.Lines);
end;
Viel Erfolg

......
Daniel W.
Ich bin nicht zurück, ich tue nur so
  Mit Zitat antworten Zitat