Findwindow (lpclassname, {Class Name of the window} lpwindowname: pchar {Title of the window}): hwnd; {handle of the returned window; returns 0} // find1_wex, which has two more handle parameters than findwindow: find1_wex (parent: hwnd; {the parent window handle for the Child window to be searched} Child: hwnd; {sub-window handle} classname: pchar; {} windowname: pchar {}): hwnd; {If parent is 0, the function uses the desktop window as the parent window, find all subwindows In the desktop window. If it is hwnd_message, the function only looks for all message windows. The subwindow must be a direct subwindow in the parent window. If the child is 0, searches start from the first subwindow of parent. If parent and child are both 0, the function searches for all top-level windows and message windows .}
// Test 1: try to create a new one. Program Main Window handle var H: hwnd; begin {now we know the title of the window is: form1, the Class Name of the window is: tform1} H: = findwindow ('tform1 ', 'form1 '); showmessage (inttostr (h); {656180; this is random. Each start window must be different.} {if you do not know the class name} H: = findwindow (nil, 'form1 '); showmessage (inttostr (h); {656180} {if you do not know the title name} H: = findwindow ('tform1', nil ); showmessage (inttostr (h); {656180} {in fact, the handle of this window is not self. handle?} showmessage (inttostr (handle); {656180} end;
// Test 2: Find the handle of the calculator window (open the calculator first) var H: hwnd; begin {if it is not a simplified Chinese system, this may not work} H: = findwindow (nil, 'calculator'); showmessage (inttostr (h); {1508334} {it is best to do this, but you must know in advance that the class name of the calculator window is: scic1c} h: = findwindow ('scical', nil); showmessage (inttostr (h); {1508334} end;