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?
The easiest way to add an item to the Start menu for all users is to click the Start button then right-click on All Programs. Select the Open All Users action item, shown here. The location C:\ProgramData\Microsoft\Windows\Start Menu will open. You can create shortcuts here and they'll show up for all users.
Windows 7: Right-Click the All Programs Folder on the Start Menu. Back in Windows XP, all you had to do was right-click the Start button to get to the folder, but Windows 7 changed 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:
hStart = ::FindWindowEx(GetDesktopWindow(), NULL, "Button", NULL);
Although I think it would be better search for it by name to be sure that you get the right button.
hStart = ::FindWindowEx(GetDesktopWindow(), NULL, "Button", "Start");
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With