VC Windows API obtains the handle of all Windows on the desktop.
VC Windows API application GetDesktopWindow -- method for obtaining all Windows handles on the desktop
Windows API
In addition to coordinating application execution, allocating memory, and managing resources, Windows Multi-job system... In addition, it is also a large service center that calls various services of this Service Center (each service is a function ), it can help applications enable Windows, depict graphics, and use peripheral devices. Because these function services are intended for applications, they are called Application Programming interfaces, API functions. WIN32 API is the Application Programming Interface of Microsoft Windows 32-bit platform.
Getasktopwindow
Function: Return the handle of the desktop window. The desktop window overwrites the entire screen. A desktop window is the area on which all icons and other windows are to be drawn.
Function prototype: HWND getasktopwindow (VOID)
Parameters: None.
Return Value: Return the handle of the desktop window.
Fast Query: Windows NT: 3.1 or later; Windows: 95 or later :;
Header file: Winuser. h; library file: user32.lib.
[Statement]
Vb
Public Declare Function GetDesktopWindow Lib "user32" Alias "GetDesktopWindow" () As Long
Vb_net
Public Declare Function GetDesktopWindow Lib "user32" Alias "GetDesktopWindow" () As Integer
C #
[DllImport ("user32.dll", EntryPoint = "getshorttopwindow", CharSet = CharSet. Auto, SetLastError = true)]
Static extern IntPtr getasktopwindow ();
[Description]
Obtain a window (desktop window) handle representing the entire Screen
[Return value]
Long: the handle of the desktop window.
How to obtain the handle of all windows on the desktop Create a project
File-> New-> project...
Writing Method
// Getmediatopwindow. cpp: defines the entry point of the console application. # Include "stdafx. h "# define _ AFXDLL # include <afxwin. h> // question hovertree.com//error 1 error C1189: # error: Building MFC application with/MD [d] (CRT dll version) requires MFC shared dll version. // Please # define _ AFXDLL or do not use/MD [d] e: \ programfilesx86 \ microsoftvisualstudio10 \ vc \ atlmfc \ include \ afx. h 24 1 GetDesktopWindowint _ tmain (int argc, _ TCHAR * argv []) {// 1. first obtain the desktop window CWnd * p0000topwnd = CWnd: G Etasktopwindow (); // 2. Obtain a subwindow CWnd * pWnd = p0000topwnd-> GetWindow (GW_CHILD); // 3. cyclically retrieve all subwindows on the desktop while (pWnd! = NULL) {// obtain the window class name CString strClassName = _ T ("");: GetClassName (pWnd-> GetSafeHwnd (), strClassName. getBuffer (256), 256); // obtain the window title CString strWindowText = _ T ("");: GetWindowText (pWnd-> GetSafeHwnd (), strWindowText. getBuffer (256), 256); // continue to the next sub-window pWnd = pWnd-> GetWindow (GW_HWNDNEXT);} return 0 ;}
Recommended: http://www.cnblogs.com/roucheng/p/3456005.html
Http://www.cnblogs.com/roucheng/p/wendang.html