(
1
)
Enumwindow
Function:
Enumerate all top-level windows. After a function is called, The system calls a callback function for each top-level window. The parameters are the window handle and an additional parameter. It can be used in the callback function.
Getwindowtext
Function to get the window title, and then use
Strstr
Function search keyword to determine the existence of a window.
Function prototype:
Bool enumwindows (
Wndenumproc lpenumfunc, // pointer to callback function
Lparam
// Application-defined value
);
Parameter description:
Lpenumfunc
: Point to the defined callback function.
Lparam
: Points to
32
The value passed to the callback function.
Return Value:
Zero is returned if the operation is successful. If the operation is unsuccessful, zero is returned.
Note:
Do not enumerate subwindows.
Getwindow
Enumeration is better.
Other window functions
Findwindow
,
Getforegroundwindow
,
Findwindow
Use the class name or window name to obtain the window handle,
Getforegroundwindow
Return to the front-end window (the current work window of the user ).
(
2
)
Enumwindow
Callback Function
Enumwindowsproc
Callback function concept:
In
Windows
In programming, a callback function is not directly called by a function or process in the program, but
Windows
The function called by the operating system. The corresponding parameters defined in the callback function allow
Windows
Directly communicate with the application.
Function prototype:
Bool callback enumwindowsproc (
Hwnd, // handle to parent window
Lparam
// Application-defined value
);
Parameter description:
Hwnd
: The top-level window handle passed by the system.
Lparam
: Additional Parameters
Return Value:
Continue enumeration. The returned value is hypocritical.
True
; The return value for stopping enumeration is
False
.
(
3
)
Win32
Compiled
Enumwindow
Function usage
Instance
. 386
. Model flat, stdcall
Option Casemap: None
Include windows. inc
Include user32.inc
Includelib user32.lib
Include kernel32.inc
Includelib kernel32.lib
Include
Shlwapi. inc
Includelib shlwapi. Lib
; Strstr
. Const
Sztitle
DB
'Ollydbg', 0
Szcaption
DB
'
Result
', 0
Szfindod
DB
'
Target window discovered
', 0
Sztext
DB
'
Enumeration ended
,
If no target is displayed, the target window is not found.
', 0
. Code
;
Define callback Functions
_ Closewnd proc uses ebx edi esi, _ hwnd, _ lparam
Local
@ Szbuffer [1024]: byte
;
Receiving Window title
Invoke iswindowvisible, _ hwnd
. If eax;
Whether the window is visible
Invoke getwindowtext, _ hwnd, ADDR @ szbuffer, sizeof @ szbuffer
Invoke strstri, ADDR @ szbuffer, offset sztitle;
Search for strings in the title
,
Without
I
Case Sensitive
. If eax
Invoke
MessageBox, null, ADDR szfindod, ADDR szcaption, mb_ OK
Invoke
Postmessage, _ hwnd, wm_close, 0, 0;
Close target
. Endif
. Endif
MoV eax, true;
Return
True
,
Enumwindows
Continue to enumerate the next window,
False
Exit Enumeration
.
RET
_ Closewnd endp
Start:
Invoke
Enumwindows, ADDR _ closewnd, null
; Enumwindows
Calls. The system enumerates all top-level windows and calls the callback function once for each window.
Invoke
MessageBox, null, ADDR sztext, ADDR szcaption, mb_ OK
Invoke
Exitprocess, null
End start