Getting coordinates of tray icon click

This is a discussion on Getting coordinates of tray icon click within the Windows Programming forums, part of the Platform Specific Boards category; When a tray icon is clicked, the specified callback message is sent to the specified window. But, how can I ...

  1. #1
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401

    Getting coordinates of tray icon click

    When a tray icon is clicked, the specified callback message is sent to the specified window. But, how can I find out where to display a shortcut menu? Ie, how can I correctly position a context menu next to the system tray?
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  2. #2
    Registered User
    Join Date
    Jun 2003
    Location
    Austria
    Posts
    55
    I'm using this:

    POINT p;
    GetCursorPos(&p);

  3. #3
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Cool thanks.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  4. #4
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Another problem: When I display the menu, but I click somewhere else on the screen, the menu stays there, and I can't do anything, effectively the computer is useless, until I either go back to the program or click the menu. How can I remove this behavior?
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  5. #5
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    After the call to GetCursorPos() call SetForegroundWindow() with your main window handle, then call TrackPopupMenuEx().
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  6. #6
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Works like a charm, thanks.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  7. #7
    Registered User
    Join Date
    Jun 2003
    Location
    Austria
    Posts
    55
    you schould bring your program's window to front, when showing the menu (even if it's not shown):

    SetForegroundWindow(hWnd);


    edit: too slow ^^

  8. #8
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    And one more: How can I make the bottom right corner of the menu where the cursor is? Every other context menu is like that, but mine has the cursor at the top left.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  9. #9
    Registered User
    Join Date
    Jun 2003
    Location
    Austria
    Posts
    55

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GTK+ Gnome desktop system tray app problem
    By BobS0327 in forum Linux Programming
    Replies: 2
    Last Post: 04-01-2006, 08:54 PM
  2. Creating system tray icon popups
    By Archie77 in forum Windows Programming
    Replies: 1
    Last Post: 05-24-2004, 10:20 PM
  3. right click on an icon in systray
    By fizisyen in forum Windows Programming
    Replies: 4
    Last Post: 03-21-2004, 11:49 PM
  4. Replies: 2
    Last Post: 08-09-2003, 04:44 AM
  5. Hiding Another Progs System Tray Icon
    By (TNT) in forum Windows Programming
    Replies: 2
    Last Post: 04-29-2002, 01:20 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21