不知道窗体类名及窗口标题,如何获取窗口句柄?

LiuFan 2003-08-18 07:46:43
如题!
...全文
930 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
thomas_cat 2003-11-28
  • 打赏
  • 举报
回复
type
TWndInfRec = record
Wnd: HWND;
Caption: string;
Handle: string[8];
ClassName: string;
Rect: string[51];
Owner: HWND;
ProcessID: string[8];
ThreadID: string[8];
end;

// 获得句柄的相关信息
function GetWindowInformation(Wnd: HWND; var WndInfRec: TWndInfRec): Boolean;
var
Buf : array [0..255] of Char;
R : TRect;
ThreadID,
ProcessID : DWORD;
begin
Result := False;
if Wnd = 0 then Exit;
WndInfRec.Handle := IntToHex(Wnd, 8);
if GetWindowText(Wnd, Buf, sizeof(Buf)) = 0 then Exit;
WndInfRec.Caption := Buf;
if GetClassName(Wnd, Buf, sizeof(Buf))= 0 then Exit;
WndInfRec.ClassName := Buf;
if not GetWindowRect(Wnd, R) then Exit;
WndInfRec.Rect := format('(%d,%d)-(%d,%d) %dx%d',
[R.left, R.top, R.right, R.bottom, R.right - R.left, R.bottom - R.top]);
WndInfRec.Owner := GetWindow(Wnd, GW_OWNER);

ThreadID := GetWindowThreadProcessId(Wnd, ProcessId);

WndInfRec.ProcessID := IntToStr(ProcessId);
WndInfRec.ThreadID := IntToStr(ThreadId);

{ BOOL GetGUIThreadInfo(
DWORD idThread, // thread identifier
LPGUITHREADINFO lpgui // thread information
);}

end;

function GetApplicationWindow(ParentWnd: HWND; Pt: TPoint): HWND;
var
R: TRect;
begin
Result := GetWindow(ParentWnd, GW_CHILD); // 取得第一個子視窗
while Result <> 0 do
begin
GetWindowRect(Result, R); // 取得視窗矩形區域
if IsWindowVisible(Result) and PtInRect(R, Pt) then
begin
if Result = frmWndExplorer.Form.Handle then // 忽略程式的 Main Form
begin
Result := 0;
Exit;
end;
Exit;
end;
Result := GetWindow(Result, GW_HWNDNEXT); // 取得下一個 siblings 視窗
end;
Result := ParentWnd; // 找不到, 它就是我們要找的
end;

thomas_cat 2003-11-28
  • 打赏
  • 举报
回复
枚举窗口句柄,然后用API函数判断句柄的进程……

DWORD GetWindowThreadProcessId(
HWND hWnd, // handle to window
LPDWORD lpdwProcessId // process identifier
);
cumtyangjin 2003-11-28
  • 打赏
  • 举报
回复
你可以用MS VS6.0 Tools 里面SPY++获取窗口句柄,并发现类名和窗口标题。
fjyhs 2003-11-27
  • 打赏
  • 举报
回复
看看这个
http://www.newhua.com/soft/15963.htm
minizhuxianchun 2003-11-27
  • 打赏
  • 举报
回复
GetWindowsPos
westfly 2003-08-18
  • 打赏
  • 举报
回复
用EnumWindows枚举再判断是否满足条件
LiuFan 2003-08-18
  • 打赏
  • 举报
回复
知道文件名、进程ID。
Cipherliu 2003-08-18
  • 打赏
  • 举报
回复
这真有点难,不过你总得有点条件吧,不然怎么知道是不是你要的窗口?

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧