Taskbar icon and popup menu coordinates

My App added icon to the TaskBar by Shell_NotifyIcon and receiving notifycations about mouse events...Now I want to bring up popup menu after right button click. But how should I know proper coordinates for the menu ? How I can obtain coordinates of icon or coordinates of mouse pointer during this event ?
Thanks in advance.
LVL 1
trofAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
BudVVeezerConnect With a Mentor Commented:
When you create the Shell_NotifyIcon, tell the uCallback to be WM_USER+1, then, when the mouse is tracked in over your icon, it sends a message to your app, then, it there's a right click(message sent in the LParam), get the cursor's position, by using GetCusorPos, giving it the address of a POINT.  VERY easy to use code.  =o)

case WM_USER + 1:
      if(lParam == WM_RBUTTONDOWN){                  POINT pt;
                  GetCursorPos(&pt);
}
0
 
trofAuthor Commented:
Sorry for bothering you, I already know the answer - of cause GetCursorPos() .
Thanks anyway
0
 
alexoCommented:
Trof, this is not so trivial as you may think.  Due to a bug on certain builds of Win95, you have do something like the following:

LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch (msg)
    {
        // Tray icon notification message
        case MYWM_NOTIFYICON:
            // Button event is single click?
            if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN)
            {
                POINT   pos;

                // Show and process menu
                // SetForegroundWindow() and PostMessage() used to circumvent a Win95 bug
                GetCursorPos(&pos);
                SetForegroundWindow(hwnd);
                TrackPopupMenuEx(GetSubMenu(GetMenu(hwnd), 0), TPM_HORIZONTAL, pos.x, pos.y, hwnd, NULL);
                PostMessage(hwnd, WM_NULL, 0, 0);
            }

            break;

        // Other cases...

        default:
            return DefWindowProc(hwnd, msg, wParam, lParam);
    }

    return 0;
}

If you think this constitutes an answer, please say so.  Otherwise, ignore me.
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
NorbertCommented:
Alexo, What kind of bug? Looking to your code I see normal behaviour - nothing that looks like a workaround
0
 
chensuCommented:
What alexo refers to is the following KB article.

PRB: Menus for Notification Icons Don't Work Correctly
http://support.microsoft.com/support/kb/articles/q135/7/88.asp
0
 
nietodCommented:
They say this "behavior is by design".  From now on, that's what I'm going to tell my customers about my bugs.
0
 
alexoCommented:
I'm talking about the two lines surrounding the TrackPopupMenuEx() :
  ---> SetForegroundWindow(hwnd);
  ---> PostMessage(hwnd, WM_NULL, 0, 0);

See the KB article (at the URL chensu provided) for details.
0
 
NorbertCommented:
Thanks for the information
0
 
alexoCommented:
Some people got absolutely no shame!
0
 
trofAuthor Commented:
Eyh, right.. :(
0
 
chensuCommented:
8-(   ???
0
 
alexoCommented:
>> Eyh, right.. :(
So why did you accept that answer?
0
 
trofAuthor Commented:
Because I found GetCursorPos by myself, but answer from BudVVeezer was here before I posted comment "Sorry for bothering "...
0
All Courses

From novice to tech pro — start learning today.