Enumwindow enumeration window

Source: Internet
Author: User

(
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.