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);