Type
Tmainwindow = packed record
Processid:thandle;
Mainwindow:thandle;
End;
Pmainwindow =^ Tmainwindow;
function Ismainwindow (ahandle:thandle): Boolean;
beginResult: = (GetWindow (ahandle, gw_owner) =
0)
and (IsWindowVisible (Ahandle));
End;
{Ismainwindow}
function Ffindmainwindow (hwnd:thandle; lparam:pmainwindow): BOOL;
stdcall;
varVprocessid:thandle;
beginGetWindowThreadProcessId (hWnd, vprocessid);
if (lparam^. ProcessID = vprocessid)
and Ismainwindow (hWnd)
Then
begin lparam^. MainWindow: = hWnd;Result: = False;
End
else Result: = True;
end;
function FindMainWindow (aprocessid:thandle): Thandle;
varVmainwindow:tmainwindow;
beginVmainwindow.processid: = Aprocessid;Vmainwindow.mainwindow: =
0;EnumWindows (@fFindMainWindow, Integer (@vMainWindow));Result: = Vmainwindow.mainwindow;
End;
{FindMainWindow}
procedure Tform1.button1click (sender:tobject);
beginCaption: = Format (
' Application.handle:%d, FindMainWindow ():%d ', [Application.handle, FindMainWindow (GETCURRENTPROCESSID)]);
end;
http://blog.csdn.net/zswang/article/details/1598516
Delphi obtains a Process main form (GetWindow (Ahandle, Gw_owner) equals 0 of the form is the main form, and to iswindowvisible Exclude application window)