Einzelnen Beitrag anzeigen

Blamaster

Registriert seit: 20. Jul 2007
230 Beiträge
 
#10

Re: Firefox und Downloadmanager ?

  Alt 7. Apr 2010, 15:21
Mit

SetString(CmdLine, PChar(lpData), cbData div SizeOf(Char)); Wird ja CmdLine nun der Programmpfad und Parameter übergeben. Sprich beides müsste in lpData liegen.

Nur an welcher stelle kommt der Pfad in lpData ?

Hier mal der Code: (Auszug aus der OneInstance.pas)

Delphi-Quellcode:
function UtilWindowProc(hWnd: HWND; Msg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT;
  stdcall;
const
  Results: array[Boolean] of LRESULT = (INSTANCE_DENY, INSTANCE_ALLOW);
var
  ProcessId: Cardinal;
  CmdLine: string;
  Allow: Boolean;
begin
  if (Msg = WM_COPYDATA) and (wParam = 0) and (lParam <> 0) then
  begin
    Allow := False;
    with PCopyDataStruct(lParam)^ do
    begin
      ProcessId := hWnd;
      SetString(CmdLine, PChar(lpData), cbData div SizeOf(Char));
    end;
    frmMain.OnSecondInstance(ProcessId, CmdLine, Allow);
    Result := Results[Allow];
  end else
    Result := DefWindowProc(hWnd, Msg, wParam, lParam);
end;

function CreateUtilWnd: HWND;
var
  UtilWndClass: TWndClass;
begin
  FillChar(UtilWndClass, SizeOf(UtilWndClass), 0);
  UtilWndClass.hInstance := HInstance;
  UtilWndClass.lpfnWndProc := @UtilWindowProc;
  UtilWndClass.lpszClassName := PChar(UtilWndClassName);
  RegisterClass(UtilWndClass);
  Result := CreateWindowEx(WS_EX_TOOLWINDOW, UtilWndClass.lpszClassName,
    '', WS_POPUP, 0, 0, 0, 0, 0, 0, HInstance, nil);
end;

procedure CheckInstance;
var
  hMain: HWND;
  CDS: TCopyDataStruct;
begin
  hMain := FindWindow(PChar(UtilWndClassName), nil);
  if hMain <> 0 then // Anwendungsinstanz vorhanden
  begin
    with CDS do
    begin
      dwData := GetCurrentProcessId;
      lpData := GetCommandLine;
      cbData := StrLen(lpData) * SizeOf(Char);
    end;
    if SendMessage(hMain, WM_COPYDATA, 0, LPARAM(@CDS)) = INSTANCE_DENY then
      Halt; // Anwendung abbrechen. Anmerkung: Finalization-Abschnitte für bereits
              // initialisierte Units werden noch abgearbeitet.
  end;
end;

initialization
  UtilWndClassName := 'OneInstUtilWnd:' + ParamStr(0);
  CheckInstance;
  hUtil := CreateUtilWnd;

finalization
  if hUtil <> 0 then DestroyWindow(hUtil);
  Mit Zitat antworten Zitat