L'utilisation est la suivante:
nparentHandle: hwnd;
nchildHandle: hwnd;
nparentHandle: = findwindow (nil, '' notepad '');
Si nparentHandle <> 0 alors
nchildHandle: = findchildwindow (nparentHandle, '' SomeChildEditsClassName '');
------ Code de fonction ------
var
hwndfindchildwindow: hwnd;
fonction enumwindowsforfindchildwindowproc (whandle: hwnd; lparam: lparam): bool;
const
Max_window_name_len = 80;
var
StarGetClassName: String;
nhandle: hwnd;
ScurrClassName: String;
Bresult: Boolean;
Commencer
if (hwndfindchildwindow <> 0) alors
sortie;
StarGetClassName: = pChar (lparam);
ScurrClassName: = GetWindowClass (whandle);
BRESULT: = comparetext (ScurrClassName, StarGetClassName) = 0;
Si (Bresult) alors
hwndfindchildwindow: = whandle
autre
FindChildWindow (Whandle, Pchar (lparam));
fin;
fonction findchildwindow (hwndparent: hwnd; classname: phar): hwnd;
Commencer
essayer
EnumChildWindows (Hwndparent, @enumwindowsforfindchildwindowproc, longInt (pChar (className)));
Résultats: = HwndFindChildWindow;
sauf
à l'exception faire
Résultats: = 0;
fin;
fin;
// Revenez au formulaire actuel avec Focus
fonction getFocusedWindowFrombarent (parentWnd: hwnd): hwnd;
var
Autrethread,
Tampon: dword;
idCurrThread: dword;
Commencer
AutreThread: = getWindowThreadProcessId (parentWnd, @Buffer);
idCurrThread: = getCurrentThreadId;
Si fixthaRedInput (idcurrThread, autre, vrai) alors commencez
Résultat: = getFocus;
AttachThreadInput (idcurrThread, autre, false);
fin
autre
Résultat: = getFocus;
fin;
// Obtenez la sous-forme qui se concentre actuellement, même si c'est la forme d'autres applications
fonction getFocusedChildWindow: hwnd;
Commencer
Résultat: = GetFocusedWindowFrombarent (getForegroundWindow);
fin;
// Obtenez le texte du formulaire
fonction eigetwIntext (nhandle: entier): chaîne;
var
pcText: Array [0..32768] de char;
Commencer
SendMessage (nhandle, wm_getText, 32768, longInt (@pcText));
Résultats: = pcText;
fin;
// Définit le texte du formulaire
Procédure eisetWIntext (nhandle: entier; const SnewText: String);
Commencer
SendMessage (nhandle, wm_settext, longueur (snewText), longInt (pChar (trim (snewText))));
fin;
// Renvoie le nom de classe du formulaire
fonction eigetwindowClass (const nhandle: hwnd): string;
var
szclassname: array [0..255] de char;
Commencer
GetClassName (nhandle, szclassname, 255);
Résultat: = szClassName;
fin;