1

I've read about how to make a notification popup menu go away when clicking outside it, but when I use the suggested code, a right click causes the taskbar popup menu to appear as well as my own. How do I make only my menu appear? Here is my code:

SetForegroundWindow(Form1.Handle);
PopupMenu1.Popup(x, y);
PostMessage(Form1.Handle, WM_NULL, 0, 0);

Edit: Okay, it seems like I did need to do something related to what I commented below.

  trayhandle := FindWindow('Shell_TrayWnd', '');
  trayhandle := FindWindowEx(trayhandle, 0, 'TrayNotifyWnd', nil);
  trayhandle := FindWindowEx(trayhandle, 0, 'SysPager', nil);
  trayhandle := FindWindowEx(trayhandle, 0, 'ToolbarWindow32', nil);
  PostMessage(trayHandle, WM_LBUTTONDOWN, MK_LBUTTON, 0);
  PostMessage(trayHandle, WM_LBUTTONUP, MK_LBUTTON, 0);
  SetForegroundWindow(Handle);
  PopupMenu1.Popup(x, y);
  PostMessage(Handle, WM_NULL, 0, 0);

I've done other work and kept bouncing back to this app and the menu (and only my menu) displays properly and disappears properly as well. Seems to be working fine now (besides triggering the left mouse button)?

Community
  • 1
  • 1
Glenn1234
  • 2,542
  • 1
  • 16
  • 21
  • It is working perfectly with delphi xe2 on a windows 7 machine – Vibeeshan Mahadeva Nov 11 '11 at 13:41
  • FWIW, it's happening on Windows XP, I can duplicate it 100% of the time now. It happens when the task bar doesn't have focus. Now given it isn't happening with my other tray apps, it has to be code related. Do I need to find the window handle of the task bar and set that to foreground first before the code above? – Glenn1234 Nov 13 '11 at 09:41

0 Answers0