Einzelnen Beitrag anzeigen

Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#8

Re: Handle eines Fensters über die Processid?

  Alt 26. Jul 2007, 13:53
So geht es:
Delphi-Quellcode:
function EnumWindowsProc(hWnd: THandle; lp: LPARAM): LongBool; stdcall;
var
  ID : DWORD;
  len : Integer;
  Caption : PChar;
begin
  if IsWindow(hWnd) and IsWindowVisible(hWnd) then
  begin
    GetWindowThreadProcessId(hWnd, ID);
    if GetCurrentProcessId = ID then
    begin
      len := SendMessage(hWnd, WM_GETTEXTLENGTH, 0, 0);
      Caption := GetMemory(len + 1);
      try
        SendMessage(hWnd, WM_GETTEXT, len, Integer(Caption));
        MessageBox(0, Caption, 'Test', 0);
      finally
        Freememory(Caption);
      end;
    end;
  end;
  Result := True;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  EnumWindows(@EnumWindowsProc, 0);
end;
GetWindowThreadID gibt nicht die ProzesID als Funktionsrückgabewert zurück, sondern im zweiten Parameter. Und wieder hilft es die Hilfe zu lesen:
Zitat:
Code:
hWnd
[in] Handle to the window.
lpdwProcessId
[out] Pointer to a variable that receives the process identifier. If this parameter is not NULL, GetWindowThreadProcessId copies the identifier of the process to the variable; otherwise, it does not.
Und
Zitat:
Code:
Return Value

The return value is the identifier of the thread that created the window.
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat