การใช้งานมีดังนี้:
nparenthandle: hwnd;
nchildhandle: hwnd;
nparenthandle: = findwindow (ไม่มี, '' notepad '');
ถ้า nparenthandle <> 0 แล้ว
nchildhandle: = findchildwindow (nparenthandle, '' somechildeditsclassname '');
------ รหัสฟังก์ชัน -------
วาจา
hwndfindchildwindow: hwnd;
ฟังก์ชั่น enumwindowsforfindhildwindowproc (whandle: hwnd; lparam: lparam): bool;
const
max_window_name_len = 80;
วาจา
StargetClassName: String;
nhandle: hwnd;
ScurrclassName: String;
Bresult: บูลีน;
เริ่ม
ถ้า (hwndfindchildwindow <> 0) แล้ว
ออก;
stargetClassName: = PCHAR (LPARAM);
scurrclassName: = getWindowClass (Whandle);
bresult: = compartext (scurrclassName, stargetClassName) = 0;
ถ้า (bresult) แล้ว
hwndfindchildwindow: = Whandle
อื่น
Findchildwindow (Whandle, Pchar (LParam));
จบ;
ฟังก์ชั่น findchildwindow (hwndparent: hwnd; classname: pchar): hwnd;
เริ่ม
พยายาม
enumchildwindows (hwndparent, @enumwindowsforfindhildwindowproc, longint (pchar (classname)));
ผลลัพธ์: = HWNDFINDCHILDWINDOW;
ยกเว้น
ในข้อยกเว้นทำ
ผลลัพธ์: = 0;
จบ;
จบ;
// กลับไปที่แบบฟอร์มปัจจุบันโดยโฟกัส
ฟังก์ชั่น getFocusedWindowFromparent (parentWnd: hwnd): hwnd;
วาจา
อื่น ๆ
บัฟเฟอร์: DWORD;
idcurrThread: DWORD;
เริ่ม
otherThread: = getWindowThreadProcessId (parentwnd, @buffer);
idcurrThread: = getCurrentThreadId;
ถ้า attachThreadInput (idCurrThread, otherthread, true) จากนั้นเริ่มต้น
ผลลัพธ์: = getFocus;
atthethReadInput (idcurrthread, otherthread, false);
จบ
อื่น
ผลลัพธ์: = getFocus;
จบ;
// รับ subform ที่ได้รับโฟกัสในปัจจุบันแม้ว่าจะเป็นรูปแบบของแอปพลิเคชันอื่น ๆ
ฟังก์ชั่น getFocusedChildWindow: hwnd;
เริ่ม
ผลลัพธ์: = getFocusedWindowFromparent (getForegroundWindow);
จบ;
// รับข้อความของแบบฟอร์ม
ฟังก์ชั่น eigetwintext (nhandle: จำนวนเต็ม): สตริง;
วาจา
pctext: array [0..32768] ของถ่าน;
เริ่ม
sendMessage (nhandle, wm_gettext, 32768, longint (@pctext));
ผลลัพธ์: = pctext;
จบ;
// ตั้งค่าข้อความของแบบฟอร์ม
ขั้นตอน eisetwintext (nhandle: จำนวนเต็ม; const snewtext: string);
เริ่ม
SendMessage (nhandle, WM_SETTEXT, ความยาว (snewtext), longint (pchar (trim (snewtext))));
จบ;
// ส่งคืนชื่อคลาสของแบบฟอร์ม
ฟังก์ชั่น eigetWindowClass (const nhandle: hwnd): สตริง;
วาจา
szclassName: อาร์เรย์ [0..255] ของถ่าน;
เริ่ม
getClassName (Nhandle, szclassname, 255);
ผลลัพธ์: = szclassName;
จบ;