Write a search window program for class Spy + +

Source: Internet
Author: User
Tags error handling

We have used the VC generation of the tool Spy + +, it can use the mouse to capture the window, get the window information.

A related api:realchildwindowfrompoint is found in MSDN:

HWND RealChildWindowFromPoint(
 HWND hwndParent,      // handle to window
 POINT ptParentClientCoords // client coordinates
);
The RealChildWindowFromPoint function retrieves a handle to the child window at the
specified point. The search is restricted to immediate child windows; grandchildren
and deeper descendant windows are not searched. 
As MSDN says, the Realchildwindowfrompoint function can only find a child window from ptparentclientcoords, but not a window that really points to the deepest, meaning that if two windows overlap, The following window is not available, and this is often the case (as shown in Figure one).

Figure I

(These two red box up windows overlap, if you use Realchildwindowfrompoint can only get a comprehensive set of windows, but not to the "No Landing prompt box" check box). So you simply call this function is not able to implement Spy + + functionality.

The following function can get the most "deep" window to achieve the function of Spy + +.#define ZOU_PROCESS_ERROR (condition)
if (!) ( condition))
Goto Exit0; Error handling macro Definition
int Cgetwindowinfo::getrealwindow (HWND *phwnd, point Ptpoint)
{
int nresult = false;
int nretcode = false;
HWND hwndtop = NULL;
HWND hwndchild = NULL;
Point ptcoochild = {0};
LONG Lwindowstyle = 0;
First get the Ptpoint Point (sub) window
Hwndtop =:: Windowfrompoint (Ptpoint);
Zou_process_error (Hwndtop);
Ptcoochild = Ptpoint;
Lwindowstyle = GetWindowLong (Hwndtop, Gwl_style);

Through this judgment to find the top of the parent window (that is, the above picture in the "QQ Settings" main window)
if (! GetParent (hwndtop) | |
GetDesktopWindow () = = GetParent (hwndtop) | |
! (Lwindowstyle & Ws_childwindow))
{
*phwnd = Hwndtop;
}
Else
{
*phwnd = GetParent (hwndtop);
}

Convert relative coordinates
:: ScreenToClient (*phwnd, &ptcoochild);

Look up the child window one layer at a parent window until you find the bottommost child window
while (TRUE) {
Hwndchild = Realchildwindowfrompoint (*phwnd, ptcoochild);
if (Hwndchild && (hwndchild!= *phwnd))
*phwnd = Hwndchild;
Else
Break
}
Nresult = true;
Exit0:
return nresult;
}

Get its handle by looking at the parent window first and then down until you find the child window. When you get the handle, you can do a lot of things with the window. I have implemented in the enclosed source code to modify the window text function (program screen as shown in Figure II).

Figure II

I hope you have some inspiration and help.

This article supporting source code

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.