Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get a handle to the Start button in Windows 7?

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?

like image 492
Fish Avatar asked Mar 05 '12 15:03

Fish


People also ask

How do I add a shortcut to the Start menu in Windows 7?

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.

How do I show the Start menu in Windows 7?

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.


1 Answers

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.

like image 135
David Heffernan Avatar answered Oct 13 '22 11:10

David Heffernan