4

I need to activate Windows start menu on mouse location.

I know I can send CTRL + ESC or Win keys to the specific window, and move the window afterwards, but it still shows menu on original location for a short period of time (unless I install hook, and that is overkill for the task).

I recall there is some way to do this, using some dll call or sending some message to the shell or something.

Ty

majkinetor
  • 8,730
  • 9
  • 54
  • 72
  • 2
    I notice that, in two and a half years, no-one has noticed that you aren't asking how to show the Start menu (although no-one has actually given [the official, documented, answer](http://stackoverflow.com/questions/2755202/) to that) but are asking how to open the Start menu _at whereever the mouse pointer is_ rather than in its default location. – JdeBP Jun 23 '11 at 13:36

2 Answers2

1

Do you get the same behaviour if you "press" the button more programmatically?

  // Find the Start button
  HANDLE hScreenDC = GetDC(0);
  DWORD height = GetDeviceCaps(hScreenDC, VERTRES);
  ReleaseDC(0, hScreenDC);
  hTaskBarWnd = FindWindow("Shell_TrayWnd", 0);
  hStartButtonWnd = GetWindow(hTaskBarWnd, GW_CHILD);

  // Now simulate a press on the Start button
  SendMessage(hButtonWnd, WM_LBUTTONDOWN,
        MK_LBUTTON, LOWORD(5) + HIWORD(height - 20));

Otherwise you might explore the "Shell_TrayWnd" window using WinSpy++ or by using a similar utility, perhaps the Start menu is a child window of the tray window.

Gabriella
  • 41
  • 3
  • Your code works only when i pass 0 (or some small value, probably must be in client region of button) as Lparam of WM_LBUTTODOWN. It seems its not a child window but recreated each time.... – majkinetor Sep 02 '09 at 21:29
  • It certainly can be done, there are apps around doing it (for instance DesktopX by Stardock) – majkinetor Sep 02 '09 at 21:30
  • Ok, then you might use Dependency Walker to examine the imports used by the DesktopX utility, it might reveal the API function you are looking for. – Gabriella Sep 02 '09 at 21:35
  • Ok, I was wrong. Window is not recreated but simply hidden. To show it on any position simply get its Hwnd and show it. The problem that may be experienced is that shadow may stay after the window is gone, and that window looses its transparency. Shadow must be killed (SysShadow) and transparency can be set, however. – majkinetor Sep 03 '09 at 11:30
1
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindow (string lpClassName, string lpWindowName);

[DllImport("user32.dll")]
public static extern bool ShowWindow (IntPtr hWnd, ShowWindowCommand nCmdShow);

int ShowCmd = 5;
int HideCmd = 0;
ShowWindow(FindWindow("DV2ControlHost", "Start menu"), ShowCmd);

Should do the trick in windows 7 at least. Use "HideCmd" instead of "ShowCmd" to hide again.

Iain Ballard
  • 4,433
  • 34
  • 39