I use:
Hwnd hStart = ::FindWindow ("Shell_TrayWnd",NULL); // get HWND of taskbar first
hStart = ::FindWindowEx (hStart, NULL,"BUTTON", NULL); // get HWND of start button
to get start button’s handle. It’s running properly on Windows XP,
but in Windows 7, ::FindWindowEx (hStart, NULL,"BUTTON", NULL) always returns 0, and GetLastError() returns 0, too.
Why is that?
In Windows 7 the start button, which has class name
"Button", is a child of the desktop window. Your code assumes that the start button is a child of the window named"Shell_TrayWnd"which does indeed appear to be the way the taskbar and start menu were implemented on XP.For Windows 7 you want to use something like this:
Although I think it would be better search for it by name to be sure that you get the right button.
I’m not sure how Vista implements its taskbar and start menu, but you can use Spy++ to find out.
Having said all of this, it would be much better if you can find a way to achieve your goals without poking around in such implementation specific details.