For the first time to write a document, the text is not smooth, and the mistakes of understanding the mistakes will be a lot of friends.
This article is a simple discussion on how to get window handles, and which functions are available! It can be applied to VC, BCB (other I didn't try, estimated), I tried in the BCB environment.
First, I will listen out some Win32 API functions that get the handle, then simply talk about their use! Finally, tell me how I understand and apply. Laugh!
Available Win32 API functions:
1.hWnd FindWindow (LPCTSTR LPCLASSNAME, LPCTSTR LPWINDOWNAME)
HWnd FindwindowEx (HWND HWNDPARENT, HWND HWNDCHILDAFTER, LPCTSTSTSTSTSTLASSNAME, LPCTSTR LPWINDOWNAME)
2.hWnd WindowFromPoint (Point & Point)
3. Bool Callback EnumchildProc (HWND HWND, LPARAM LPARAM)
Bool Callback EnumchildWindows (HWND HWNDPARENT, WNDENUMPROC LPENUMFUNC, LPARAM LPARAM)
Bool Callback Enumwindows (WndenumProc Lpenumfunc, LParam LPARAM)
Bool Callback EnumwindowsProc (HWND HWND, LPARAM LPARAM)
General purpose:
For the first, everyone is familiar, is a conventional weapon to capture the handle, these two brothers can accept one of the class names of the capture object or one of the window titles, returns an HWnd. But for the general masses, not necessarily knowing all the names of all windows (including the title bar, buttons, etc.)! - Can be simply for example, do you know the class name of the desktop icon? For window titles, there may be the same title, there are two windows - refer to two processes of a program, this is a trouble! Ok, this problem is put first, continue the next group.
The second group, through the Win32 defined Point structure (Typedef struct tagpoint {long x; long y;} point), the window hWnd of the current mouse cursor position is the most intuitive weapon! The routine operation is as follows: First get the Cursor's Point (Bool getCursorpos (LPPOINT) function, use WindowFromPoint. In this way, we can get any HWnd with any open function with the window! Then get class names by getting the win32 API function of the class name - the LPClassName here is best to use the character array address, nmaxcount is the number of Size, at the same time, this method Solved the trouble of the first question! - I can put my mouse anywhere! * ^ _ ^ *
The third group, these are superior weapons used to list and handle any windows! By combining EnumWindows and EnumWindowsProc, EnumChildWindows and EnumChildProc, you can scan all windows of your desktop and processed it!
My understanding: (This part uses task-driven teaching methods - who makes the younger brother is a teacher! Xi xi) Task: get all the names of the window.
Solution 1: We will first think of the third group first, you can start from the desktop window (it is the ancestor of all windows), sequentially scans, get the class name. A little bit like Visual Stdio spy , or Borland's Winsight32, the specific method is as follows: (BCB)
In the main program, call EnumWindows, get the first parameter of the function address that younumProc, don't forget to convert to the WndenumProc type. The second reference can be NULL. :: Enumwindows (ReinterPret_Cast
In the younumproc function, if the first entangled hWnd = = NULL, it will be jumped out of (return false;), it can be ended!
Then, prepare the class named group, get the class name, save it.
Returns the true value and continues the next scan.
It is not complicated, it is a function recursive. But I will explain! Face! : p
Second solution: Simple, intuitive - you think about it, quite
First prepare a clock, a class method (I use TMEMO)
In the timer processing function:
1, get the current Cursor point location
2, use WindowFromPoint,
3, then get class name, put it in TMEMO
This allows you to get the window you want (including buttons, etc.) as soon as the mouse is put on the window. . . Haha
The third method: It should also be possible to use the FindWindow and the loop structure.
Summary: In fact, there are many ways to get HWnd, such as knowing the window level, and sweep it in turn. . . That's the third kind! But I think, my method is most effective, what do you say?
Welcome everyone to contact me and discuss this problem! I have many questions about this problem, such as the transformation of HWnd and ID, in the HWND or ID of the form control in the IE page, or other stuff, in short, it is possible to identify his. . . I am very confused, no way!
Unclear, everyone should refer to MSDN! (Good things!)
My QQ: 21445102, contact me!