Question

I have just used spy++ to find the handle of a window that I need, but spy++ is giving me a number:

Window Handle: 00010080

And I mean... usually when you declare a handle its done like:

HWND windowHandle;

Question:: So I am guessing that 00010080 is some sort of ID or something, but how do I use it to declare the right handle that I want in my code?

I mean I cant do HWND windowHandle = 00010080; (haha if you know what I mean, so how do I use this number to get the window handle?)

Was it helpful?

Solution

The value given to you by Spy++ is the same one returned by calls like CreateWindow. Using Spy++ to acquire this value and then using it in your program is not the most optimal solution as the value will change each time the target application starts.

Instead I suggest you use FindWindow, FindWindowEx or even EnumWindows. These are the same calls used by Spy++ to get a list of windows. For example the following will search for the first top level window created using a class name of SomeWindowClass.

HWND hwnd = ::FindWindowEx(NULL, NULL, "SomeWindowClass", NULL);

OTHER TIPS

HWND is as HANDLE

HANDLE is PVOID

So, just assign your number to variable:

HWND hwnd = (HWND) 0x00010080;

don't forget that hwnd is different for each application run.

reference http://msdn.microsoft.com/en-us/library/windows/desktop/aa383751(v=vs.85).aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top