Stylus tap position

I have made an application and the only GUI is an icon in tray. Im trying to popup a menu when the user click up to the icon but i can take the position of stylus tap. i dont want to make a tap and hold
Im trying the API GetCursorPos but its return an error that it tell that is unsupported for win mobile
According  the MSDN the LOWORD and HIWORD of event WM_LBUTTONDBLCLK  return the stylus position but the position tha return are wrong. Also im trying to use ClientToScreen API but still are wrong

Pleaze help!
Who is Participating?
hjgodeConnect With a Mentor Commented:

as far as we can assume, you are using a shell notification icon in the taskbar. The Shell_NotifyIcon API enables you to provide a callback, which is invoked, when the user clicks the notification icon in the taskbar:


   notdata.cbSize = 152;
   notdata.hIcon =  hIcon;
   notdata.hWnd = hwnd;
   notdata.uCallbackMessage = WM_NOTIFY_TRAY;
   notdata.uFlags = NIF_MESSAGE | NIF_ICON;
   notdata.uID = uID;

   Shell_NotifyIcon(dwMessage, ref notdata);

This notification message is generated by the OS and the message does NOT contain any click position data. The message sent to notify your main loop is WM_NOTIFY_TRAY and lParam has some additional information:

    case WM_NOTIFY_TRAY:
        case WM_LBUTTONDBLCLK:
            ShowWindow(hWnd, SW_RESTORE);
        case WM_RBUTTONDOWN:
        case WM_CONTEXTMENU:

If you need a click position, you have to hook and get the position within the taskbar area. Here is an article on this advanced topic:

That's the x and y from the click message:
x = LOWORD(lParam);
y = HIWORD(lParam);

It does work.

If you write an application for the system tray, you need Shell_NotifyIcon and you don't convert these coordinates.
CodeProject. Adding Icons to the System Tray
CodeProject. FindFirstChangeNotification & Shell_NotifyIcon together... again
CodeProject.Basic use of Shell_NotifyIcon in Win32
Frog153Author Commented:
here is my code that i use

the function OnTrayIcon from Message uCallbackMessage from NOTIFYICONDATA

LRESULT OnTrayIcon(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
            // Is this the ID we want?
            if (wParam != m_nid.uID)
                  return 0;
            T* pT = static_cast<T*>(this);
            // Was the right-button clicked?
            if (LOWORD(lParam) == WM_LBUTTONUP)
                  // Load the menu
                  CMenu oMenu;
                  if (!oMenu.LoadMenu(m_nid.uID))
                        return 0;
                  // Get the sub-menu
                  CMenuHandle oPopup(oMenu.GetSubMenu(0));
                  // Prepare
                  // Get the menu position
                  CPoint pos;
                  DWORD messagepos = ::GetMessagePos(); /*Here is my problem i cant take the stylus tap postition.I have already use LOWORD(lParam) and HIWORD(lParam) */
                  pos.x = GET_X_LPARAM(messagepos);
                  pos.y = GET_Y_LPARAM(messagepos);

                  // Make app the foreground
                  // Set the default menu item
                  /*if (m_nDefault == 0)
                        oPopup.SetMenuDefaultItem(0, TRUE);
                  // Track
                  oPopup.TrackPopupMenu(TPM_LEFTALIGN, pos.x, pos.y, pT->m_hWnd);
                  // BUGFIX: See "PRB: Menus for Notification Icons Don't Work Correctly"
                  // Done
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 DWORD messagepos = ::GetMessagePos();
  WORD x = LOWORD(messagepos);
  WORD y = HIWORD(messagepos);

or, maybe:

pos = (CPoint(GetMessagePos()));

Use a trace/log utility to check the coordinates. They are correct and the problem can be somewhere in the menu. Check something simple like that:
::TrackPopupMenu(hMenu, 0, pos.x, pos.y, 0, hWnd, NULL);
::PostMessage(hWnd, WM_NULL, 0, 0);

Let's say that the problem is really in the coordinates. But this popup menu should jump in a more or less predefined position. At least for a test, use coordinates valid for your screen. If you will see the menu, so the reason was the coordinates as you suspected.

there is a great article at CodeProject about Notification Icons 

Why do you need the tapped position, it is always within the Icon size. This notification icon is almost only 26x26 pixels. I dont see a need to track the clicked position for within the icon.


This question has been classified as abandoned and is being closed as part of the Cleanup Program.  See my comment at the end of the question for more details.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.