国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Delphi > 正文

獲得其他程序的子窗體

2019-09-08 23:08:58
字體:
供稿:網(wǎng)友
                                                                                                                                                       
                       通過一個父窗體的句柄,遞歸的枚舉它的子窗體,我們可以最終找到需要的子窗體。

  用法如下:

  nParentHandle: HWnd;
  nChildHandle: HWnd;

  nParentHandle := FindWindow(nil, ''Notepad'');
  if nParentHandle <> 0 then
    nChildHandle := FindChildWindow(nParentHandle, ''SomeChildEditsClassName'');

------函數(shù)代碼------

var
hwndFindChildWindow : HWND;

function EnumWindowsForFindChildWindowProc(WHandle: HWND; lParam: LPARAM): BOOL; export; stdcall;
const
MAX_WINDOW_NAME_LEN = 80;
var
sTargetClassName: string;
nHandle: HWnd;
sCurrClassName: string;
bResult: Boolean;
begin
if (hwndFindChildWindow <> 0) then
exit;
sTargetClassName := PChar(lParam);
sCurrClassName := GetWindowClass(WHandle);
bResult := CompareText(sCurrClassName, sTargetClassName) = 0;
If (bResult) then
hwndFindChildWindow := WHandle
else
FindChildWindow(WHandle, PChar(lParam));
end;

function FindChildWindow(hwndParent: HWnd; ClassName: PChar) : HWnd;
begin
try
EnumChildWindows(hwndParent, @EnumWindowsForFindChildWindowProc, LongInt(PChar(ClassName)));
Result := hwndFindChildWindow;
except
on Exception do
Result := 0;
end;
end;

//返回當前獲得焦點的窗體
function GetFocusedWindowFromParent(ParentWnd:HWnd):HWnd;
var
OtherThread,
Buffer : DWord;
idCurrThread: DWord;
begin
OtherThread := GetWindowThreadProcessID(ParentWnd, @Buffer);
idCurrThread := GetCurrentThreadID;
if AttachThreadInput(idCurrThread, OtherThread, true) then begin
Result := GetFocus;
AttachThreadInput(idCurrThread, OtherThread, false);
end
else
Result:= GetFocus;
end;

//獲得當前獲得焦點的子窗體,即使它是其他應用程序的窗體
function GetFocusedChildWindow: HWnd;
begin
Result := GetFocusedWindowFromParent(GetForegroundWindow);
end;

//獲得窗體的文本
function EIGetWinText(nHandle: Integer): string;
var
pcText: array[0..32768] of char;
begin
SendMessage(nHandle, WM_GETTEXT, 32768, LongInt(@pcText));
Result := pcText;
end;

//設(shè)定窗體的文本
procedure EISetWinText(nHandle: Integer; const sNewText: string);
begin
SendMessage(nHandle, WM_SETTEXT, Length(sNewText), LongInt(PChar(Trim(sNewText))));
end;

//返回窗體的類名
function EIGetWindowClass(const nHandle: HWnd): string;
var
szClassName: array[0..255] of char;
begin
GetClassName(nHandle, szClassName, 255);
Result := szClassName;
end;

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 兴安县| 临洮县| 英吉沙县| 通海县| 休宁县| 邻水| 连城县| 昆山市| 嘉祥县| 枝江市| 纳雍县| 满洲里市| 都兰县| 方正县| 太康县| 宾川县| 临沭县| 盈江县| 阿坝县| 响水县| 油尖旺区| 孟州市| 信阳市| 喀喇| 邹城市| 临泉县| 潮州市| 搜索| 军事| 西乡县| 平乐县| 吉林省| 临西县| 临洮县| SHOW| 本溪市| 金秀| 大足县| 郑州市| 云和县| 天水市|