x, y co-ords for trayIcon right click

For questions and postings not covered by the other forums
ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

x, y co-ords for trayIcon right click

Postby ConvertFromOldNGs » Fri Aug 07, 2009 12:27 pm

by ConcordDev >> Wed, 5 Nov 2003 23:10:49 GMT

Does anyone know how to go about positioning a popup menu for a tray icon?

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: x, y co-ords for trayIcon right click

Postby ConvertFromOldNGs » Fri Aug 07, 2009 12:27 pm

by allistar >> Thu, 6 Nov 2003 21:30:07 GMT

Here is a sample event handler (in C++) for a tray icon:

LRESULT CTrayIcon::OnTrayNotification(WPARAM wID, LPARAM lEvent)
{
if (wID!=m_nid.uID ||
(lEvent!=WM_RBUTTONUP && lEvent!=WM_LBUTTONDBLCLK))
return 0;

// If there's a resource menu with the same ID as the icon, use it as // the right-button popup menu. CTrayIcon will interprets the first // item in the menu as the default command for WM_LBUTTONDBLCLK
//
CMenu menu;
if (!menu.LoadMenu(m_nid.uID))
return 0;
CMenu* pSubMenu = menu.GetSubMenu(0);
if (!pSubMenu)
return 0;

if (lEvent==WM_RBUTTONUP) {

// Make first menu item the default (bold font)
::SetMenuDefaultItem(pSubMenu->m_hMenu, 0, TRUE);

// Display the menu at the current mouse location. There's a "bug" // (Microsoft calls it a feature) in Windows 95 that requires calling // SetForegroundWindow. To find out more, search for Q135788 in MSDN. //
CPoint mouse;
GetCursorPos(&mouse);
::SetForegroundWindow(m_nid.hWnd);
::TrackPopupMenu(pSubMenu->m_hMenu, 0, mouse.x, mouse.y, 0, m_nid.hWnd, NULL);

} else // double click: execute first menu item
::SendMessage(m_nid.hWnd, WM_COMMAND, pSubMenu->GetMenuItemID(0), 0);

return 1; // handled
}

(I hope that has formatted ok). You can see near the bottom that the menu gets popped up at mouse.x and mouse.y (after calling getCursorPos(&mouse)).

So you should be able to get the current cursor position by doing this:

CPoint point;
GetCursorPos(&point);

the x and y position of the mouse would be point.x and point.y respectively. You should be able to add external functions to do this directly in JADE, or you could roll your own external function in C++ with those lines of code in it.

I hope this helps,
Allistar.
--
------------------------------------------------------------------
Allistar Melville
Software Developer, Analyst allistar@silvermoon.co.nz
Auckland, NEW ZEALAND

Silvermoon Software
Specialising in JADE development and consulting
Visit us at: http://www.silvermoon.co.nz
*NEW* Simple web access to Jade at: www.silvermoon.co.nz/jhp.html ------------------------------------------------------------------


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 25 guests