Solved

Taskbar icon and popup menu coordinates

Posted on 1998-07-15
13
321 Views
Last Modified: 2013-12-03
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.
0
Comment
Question by:trof
  • 4
  • 3
  • 2
  • +3
13 Comments
 
LVL 1

Author Comment

by:trof
ID: 1410159
Sorry for bothering you, I already know the answer - of cause GetCursorPos() .
Thanks anyway
0
 
LVL 11

Expert Comment

by:alexo
ID: 1410160
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
 
LVL 3

Expert Comment

by:Norbert
ID: 1410161
Alexo, What kind of bug? Looking to your code I see normal behaviour - nothing that looks like a workaround
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 23

Expert Comment

by:chensu
ID: 1410162
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
 
LVL 22

Expert Comment

by:nietod
ID: 1410163
They say this "behavior is by design".  From now on, that's what I'm going to tell my customers about my bugs.
0
 
LVL 11

Expert Comment

by:alexo
ID: 1410164
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
 
LVL 3

Expert Comment

by:Norbert
ID: 1410165
Thanks for the information
0
 
LVL 3

Accepted Solution

by:
BudVVeezer earned 300 total points
ID: 1410166
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
 
LVL 11

Expert Comment

by:alexo
ID: 1410167
Some people got absolutely no shame!
0
 
LVL 1

Author Comment

by:trof
ID: 1410168
Eyh, right.. :(
0
 
LVL 23

Expert Comment

by:chensu
ID: 1410169
8-(   ???
0
 
LVL 11

Expert Comment

by:alexo
ID: 1410170
>> Eyh, right.. :(
So why did you accept that answer?
0
 
LVL 1

Author Comment

by:trof
ID: 1410171
Because I found GetCursorPos by myself, but answer from BudVVeezer was here before I posted comment "Sorry for bothering "...
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now