|
Previous Top Next |
Prototype: | (String pCaption, Byte pFindInCaption=True, Byte pFullMatch=False),Long,VIRTUAL |
pCaption | String to find |
pFindInCaption | Indicates if the Caption or the EXE name should be searched. This parameter defaults to True |
pFullMatch | If true the stirng is compared directly. If False the string is compared with Instring. This parameter defaults to False. The search is ALWAYS case insensitive! |
Returns | Window handle if a window was found. If no window was found the return value is 0 (zero) |
This method searches the caption text of all top windows using Instring. Note that the TopWindows property is loaded with the enumerated top windows after a call to this method, so you can perform more detailed search if the FindWindow returns zero. Please note that this will return the first window found and not indicate if there are more windows that fit the search criteria. For that type of code, please see the examples for EnumTopWin and the code in the Example Program for EnumTopWin.
NEW Beta 3.3
This method can now be used to search for a top window where the EXE name matches the pCaption parameter. The other new parameter can be used to specify exact search string, i.e. it will not find "NOTEPAD" in "NOTEPAD.EXE" if this parameter is set to TRUE. If the parameter is false it would find "NOTEPAD" in "NOTEPAD.EXE" Note that when you pass a executable name in pCaption, it is stripped to the filename and extension only and then compared to the ModuleEXEName which also contains just the filename and extension. If the pCaption contains a '\' then it is treated as a possible path and only the filename and extension are extracted from it.
PLEASE NOTE: This method simply returns the first window handle that matches. There may be multiple top windows for a given process. Our next release will have a method that enumerates all top windows for a given executable along with more information about each window that is enumerated.
Example:
ITW ITWindowsClass
Code
TestFindWindow ROUTINE
Data
hWnd Long
Code
hWnd = ITW.FindWindow(Loc:Search,Loc:SearchInCaption)
If hWnd
Message('Window found, handle returned = ' & hWnd,'Window found',ICON:Exclamation)
Else
Message('Window not found','Window not found',ICON:Hand)
End
If Loc:Search contains "Notepad.exe" and Loc:SearchInCaption is true, then this will search for a top window belonging to Notepad.exe.
See also: