全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1302
推到 Plurk!
推到 Facebook!

獲得其他程式的子表單

 
jackkcg
站務副站長


發表:891
回覆:1050
積分:848
註冊:2002-03-23

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-01-26 15:45:38 IP:61.64.xxx.xxx 未訂閱
此為轉貼資料 獲得其他程式的子表單 (http://www.tommstudio.com/newclub30/) -------------------------------------------------------------------------------- 通過一個父表單的控制碼,遞迴的枚舉它的子表單,我們可以最終找到需要的子表單。 用法如下: nParentHandle: HWnd; nChildHandle: HWnd; nParentHandle := FindWindow(nil, 'Notepad'); if nParentHandle <> 0 then nChildHandle := FindChildWindow(nParentHandle, 'SomeChildEditsClassName'); ------函數代碼------ 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; //設定表單的文本 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; ********************************************************* 哈哈&兵燹 最會的2大絕招 這個不會與那個也不會 哈哈哈 粉好 Delphi K.Top的K.Top分兩個字解釋Top代表尖端的意思,希望本討論區能提供Delphi的尖端新知 K.表Knowlege 知識,就是本站的標語:Open our mind to make knowledge together! 希望能大家敞開心胸,將知識寶庫結合一起
------
**********************************************************
哈哈&兵燹
最會的2大絕招 這個不會與那個也不會 哈哈哈 粉好

Delphi K.Top的K.Top分兩個字解釋Top代表尖端的意思,希望本討論區能提供Delphi的尖端新知
K.表Knowlege 知識,就是本站的標語:Open our mind
系統時間:2024-05-12 13:54:43
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!