Learning using the Windows API enmuwindows

Source: Internet
Author: User

Recently has been tangled in the use of Enmuwindows, later only to understand, and now put their own test code to paste out, the following code to do an explanation.

1#include <windows.h>2#include <string>3 /****************************************************************************4 when you have finished calling EnumWindows (Enumwindowsproc, NULL); The system automatically enumerates all the Windows5 whenever you enumerate to a window, it automatically enters Enumwindowsproc, and you can use the HWND handle in the function6 things you want to do, like getting a window title. Exit the function when you are done with the code you need to process. System and7 enumerates the next window, and again enters EnumWindows (Enumwindowsproc, NULL) when the next window is obtained8 ****************************************************************************/9 BOOL CALLBACK Enumwindowsproc (HWND hwnd, LPARAM LPARAM)Ten { One     if(GetParent (hwnd) = = NULL && iswindowvisible (hwnd))//determine if the top-level window is visible A{//You can do what you need in this function. -         Charwindowtitle[ -]; -:: GetWindowText (HWnd, WindowTitle, -);//Get WindowTitle the         if(strcmp (WindowTitle, (Char*) lParam) = =0)//if two strings are the same -         { -  -:: MessageBox (NULL, windowtitle, NULL, MB_OK);//if the match is printed as a dialog box +             //Stop enumeration returns false -             return false; +         }     A     } at     return true; - } -  intWINAPI WinMain (hinstance hinstance, hinstance hprevinstance, LPSTR lpCmdLine,intncmdshow) - { -     Chartesttitle[ -] ="httpd";//For convenience I set the string here for the wincaption of the window -EnumWindows (Enumwindowsproc, (LPARAM) testtitle);//The first parameter is the callback function, and the second is the second parameter of the callback function.  in      -}

BOOL EnumWindows (Wndenumproc lpenumfunc, LPARAM LPARAM ); This function enumerates the top-level windows on all screens and transmits the window handle to the application-defined callback function. Where lparam is the parameter passed to Lpenumfunc. The callback function returns false to stop the enumeration, otherwise the EnumWindows function continues until all the top-level windows are enumerated.

The function of this example is to enter the wincaption of a window in the main function, which is the wincaption of the window you want to find, and then enumerate all the desktop Windows to invoke the Enumwindowsproc function. Use the MessageBox () function to display the name of the wincaption until you find the window you want to find. Stops the enumeration. It is so simple that this program creates a Win32 application that can be run directly. Test pass on the vs2015.

Learning using the Windows API enmuwindows

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.