Difference Findwindow,findwindowex,enumwindows,enumchildwindows

Source: Internet
Author: User

1. FindWindow ()

HWND FindWindow (LPCSTR lpclassname, LPCSTR lpwindowname); functions:finds the top-level window that matches the specified window class name and window name, which does not search child windows. Parameter: If lpclassname is null, any window matching the Lpwindowname parameter will be found, and if lpwindowname is null, all window names are matched. Return value: The window handle was successfully returned. Otherwise, NULL is returned.

2.FindWindowEx ()HWND
WINAPI
FINDWINDOWEXW (
_in_opt_ HWND hWndParent,
_in_opt_ HWND Hwndchildafter,
_in_opt_ LPCWSTR Lpszclass,
_in_opt_ lpcwstr Lpszwindow);
Function: looks for the first child window in the window list that matches the specified criteria. The function obtains a handle to a window that matches the given string with the class name and window name. This function finds the child window, starting at the next subwindow that follows the given child window. is not case-sensitive when searching. Parameters: (1) hwndparent: Handle to the parent window where the child window to find is locatedif hWndParent is set, it means that the child window is searched from the parent window to which the hwndparent points。
If hWndParent is 0, the function takes the desktop window as the parent window, looking for all child windows of the desktop window。
If hWndParent is Hwnd_message, the function only looks for all message windows.
(2) Hwndchildafter: child window handle. The lookup starts with the next child window in the Z-order.the child window must be a direct child window of the hWndParent window and not a descendant window。 If Hwndchildafter is null, the lookup starts at the first child window of hwndparent. If hwndparent and hwndchildafter are null at the same time, the function finds all the top-level windows and the message window.
(3) Lpszclass: A pointer to an empty end string that specifies the class name, or a member that identifies the class name string.
(4) Lpszwindow: Point to an empty end string that specifies the window name (window caption). If the parameter is NULL, all Windows match.
return value:
If the function succeeds, the return value is the window handle with the specified class name and window name. If the function fails, the return value is null.

3. EnumWindows ()BOOL EnumWindows (Wndenumproc lpenumfunc,lparam LPARAM) Features:This function enumerates the top-level windows on all screens and transmits the window handle to the application-defined callback function. The callback function returns false to stop the enumeration, otherwise the EnumWindows function continues until all the top-level windows are enumerated. Parameters: Lpenumfunc: Point to an application-defined callback function pointer lpararm: Specifies an application-defined value return value that is passed to the callback function: If the function succeeds, the return value is not 0; if the function fails, the return value is zero.
callback function Prototypes:BOOL CALLBACK Enumwindowsproc (HWND hwnd, LPARAM LParam); HWND: Handle of the top-level window lparam: A value of the application definition (that is, EnumWindows lparam)

4 enumchildindows ()BOOL Enumchildwindows (HWND hwndparent, Wndenumproc Lpenumfunc, LPARAM LPARAM); functions:enumerates all child windows of a parent window. If the callback function returns TRUE, the enumeration continues until the enumeration is complete, and if False is returned, the enumeration is aborted. Parameter: hwndparent: Parent Window Handle Lpenumfunc: Address of callback function lparam: Custom parameter return value: If the function succeeds, the return value is not 0; if the function fails, the return value is zero.
callback function Prototypes:BOOL CALLBACK Enumwindowsproc (HWND hwnd, LPARAM LParam); HWND: Handle of the top-level window lparam: A value of the application definition (that is, EnumWindows lparam)

Similarities and differences point: 1. FindWindow finds the top-level window without searching for child windows. The FindWindowEx is a child window that looks for a window. Same point: It is only one time to find the return window handle, and no return null is found. Can form a loop with the while. 2. EnumWindows enumerates all the top-level windows on the screen, while Enumchildwindows enumerates all the child windows of a parent window. The same point is implemented by the callback function, which blocks until the enumeration is complete, or the enumeration aborts. 3. FindWindow (null, NULL) while loop is the same as EnumWindows (); 4. FindWindowEx (.., NULL, ...) while loop is the same as enumchildwindows ();
For example:
void Find ()  {      hwnd hwnd = NULL;      HWND Afterhwnd = NULL;      while (true)      {             hwnd =:: FindWindowEx (null, Afterhwnd, _t ("#32770"), null);                  if (!hwnd)        {break            ;        }        else          {              TCHAR Sztitle[max_path] = {0};              :: GetWindowText (hwnd, SzTitle, MAX_PATH))                          if (Wcsstr ( Strtitle, _t ("Test"))! = 0)              {  //... Related code            }          }          Afterhwnd = hwnd;      }  }  




Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Difference Findwindow,findwindowex,enumwindows,enumchildwindows

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.