分类: C/C++
2008-09-11 11:58:30
genie0610 () September 9, 2004 |
This article illustrates how to implement a tray mouse hover/leave message. Some programs want to get a mouse hover/leave message from the system tray when they want to show a popup window that is not a tool tip. However, the Windows shell doesn't support it. We can only get mouse move, up, down, and double-click messages from the system tray. It is very easy to implement a WM_MOUSEHOVER message because the first WM_MOUSEMOVE is that. But, WM_MOUSELEAVE is hard to implement, so I decided to write a compact class to notify the window of a mouse hover/leave message. The basic idea is very simple. It is that no WM_MOUSEMOVE message fires when the mouse is out of the tray icon. This class saves the mouse point whenever a WM_MOUSEMOVE message fires on the system tray, and then another thread compares it with the current mouse point. The thread fires a WM_MOUSELEAVE message when the two points are different. The following code is the WM_MOUSEMOVE handler. This is a thread function that checks the mouse point. If you want to use this class in your project, just follow these simple steps. Downloads
Tutorial: Part 1 - Get Ready to Develop Telecom Apps with the Avaya DMCC Java SDK
Sponsored by Avaya
Learn how to setup the development environment for using the Avaya DMCC Java SDK. This tutorial describes how to install and configure the Application Enablement Services (AE Services) Device, Media, and Call Control (DMCC) Java SDK. You'll also learn how to use Eclipse to test a sample application. »
Tutorial: Part 2 - Developing Telecommunication Applications with the Avaya DMCC Java SDK
Sponsored by Avaya
This tutorial gives a brief introduction to the basic steps required to develop telecommunication applications using the Avaya DMCC Java SDK. Learn more. »
Whitepaper: Avaya IQ - Building Upon the Strengths of CMS
Sponsored by Avaya
Learn how the new Avaya IQ analytics and reporting system provides a single reporting solution for contact center intelligence. Click here. »
Whitepaper: Are IP Telephony Contact Centers Ready for Prime Time?
Sponsored by Avaya
Learn how companies such as Avaya, Cisco, Siemens, Nortel, Mitel, Syntellect, Aspect Software, Genesys Telecommunications, NEC and others are promoting SIP-based IP contact centers. »
Introduction
The Problem
The Idea
VOID CTrayPos::OnMouseMove()
{
EnterCriticalSection(&m_cs);
GetCursorPos(&m_ptMouse);
if(m_bTrackMouse == FALSE)
{
OnMouseHover();
m_bTrackMouse = TRUE;
}
LeaveCriticalSection(&m_cs);
}
UINT CALLBACK CTrayPos::TrackMousePt(PVOID pvClass)
{
POINT ptMouse;
CTrayPos *pTrayPos = (CTrayPos *) pvClass;
while(WaitForSingleObject(pTrayPos->m_hExitEvent, 2000) ==
WAIT_TIMEOUT)
{
if(pTrayPos->m_bTrackMouse == TRUE)
{
GetCursorPos(&ptMouse);
if(ptMouse.x != pTrayPos->m_ptMouse.x || ptMouse.y !=
pTrayPos->m_ptMouse.y)
{
pTrayPos->m_bTrackMouse = FALSE;
pTrayPos->OnMouseLeave();
}
}
}
return 0;
}
Using the Code
Note that this class instance exists until the tray icon is deleted, so you must declare it a member variable or a global variable. CMsgTrayPos traypos;
The three parameters—hwnd, uID, and uMsgID—are the same value as the member of NOTIFYICONDATA. traypos.SetNotifyIconInfo(hwnd, uID, uMsgID);
CMsgTrayPos API
This function provides tray icon inforamtion to the class. The three parameters—hwnd, uID, and uCallbackMsg—and members of NOTIFYICONDATA are the same.
VOID CMsgTrayPos::OnMouseMove()
This function is very important. You must call this function when you get a WM_MOUSEMOVE message from the system tray.
This function checks the mouse hover status and updates the mouse point internally.
This function returns the mouse hover status. It returns TRUE if your mouse is on your tray icon. History