Ben
2005-01-11 01:05:30 UTC
Hi there,
I'm writing an MFC dialog-bassed app (with VS .NET 2003) in which I've
had to extend the CButton class to add some simple GUI-related
functionality. I'm using the _TrackMouseEvent function in the usual way
(inside a WM_MOUSEMOVE handler) to process the messages WM_MOUSELEAVE
and WM_MOUSEHOVER.
Here is my code for the WM_MOUSEMOVE, WM_MOUSEHOVER and WM_MOUSELEAVE
message handlers - it's pretty standard stuff:
void CButtonExtend::OnMouseMove(UINT nFlags, CPoint point)
{
if (!m_bTracking)
{
TRACKMOUSEEVENT tme;
tme.cbSize = sizeof(tme);
tme.hwndTrack = m_hWnd;
tme.dwFlags = TME_LEAVE|TME_HOVER;
tme.dwHoverTime = 1;
m_bTracking = _TrackMouseEvent(&tme);
m_point = point;
}
CButton::OnMouseMove(nFlags,point);
}
LRESULT CButtonExtend::OnMouseHover(WPARAM wparam, LPARAM lparam)
{
m_txtInfo->SetWindowText(m_strInformation);
return m_bTracking;
}
LRESULT CButtonExtend::OnMouseLeave(WPARAM wparam,LPARAM lparam)
{
m_txtInfo->SetWindowText("");
m_bTracking = FALSE;
return 0;
}
Now, this is all generally fine and works as expected - the
SetWindowText call just sets/clears a text box that displays
information about a button which when the mouse hovers over it.
My problem has arisen when I've tried to run my app under Windows XP
with the "Windows XP" desktop theme set. (Previously, I had been
developing the app in Win2000). When using this theme, a mouse cursor
hovering over a button (without a click) causes an orangey highlight to
appear around the button's edges, and it disappears when the mouse
leaves the button area. However, when using a button from my
ButtonExtend class, the orange highlight remains even after the cursor
moves away from the button.
The problem goes away if I disable my OnMouseLeave handler and don't
process the WM_MOUSELEAVE message - however, I need this handler to
clear the text in my information box after the mouse leaves a button's
area. I've been fiddling with common controls, manifests, a zillion
message handlers and scouring the MSDN without success. Does anyone
have any suggestions? They would be much appreciated.
Further - there is one message specific to XP (BCN_HOTITEMCHANGE) which
I suspect could be the culprit here. However, when I try to write a
handler for the message in the dialog class that owns the
CButtonExtends, the compiler insists that BCN_HOTITEMCHANGE is an
unresolved symbol, _even though_ when I hover over it in the code
editor, IntelliSense correctly identifies and defines it. I've included
the commctrl.h file in my code.
Any pointers definitely welcome! Thanks.
I'm writing an MFC dialog-bassed app (with VS .NET 2003) in which I've
had to extend the CButton class to add some simple GUI-related
functionality. I'm using the _TrackMouseEvent function in the usual way
(inside a WM_MOUSEMOVE handler) to process the messages WM_MOUSELEAVE
and WM_MOUSEHOVER.
Here is my code for the WM_MOUSEMOVE, WM_MOUSEHOVER and WM_MOUSELEAVE
message handlers - it's pretty standard stuff:
void CButtonExtend::OnMouseMove(UINT nFlags, CPoint point)
{
if (!m_bTracking)
{
TRACKMOUSEEVENT tme;
tme.cbSize = sizeof(tme);
tme.hwndTrack = m_hWnd;
tme.dwFlags = TME_LEAVE|TME_HOVER;
tme.dwHoverTime = 1;
m_bTracking = _TrackMouseEvent(&tme);
m_point = point;
}
CButton::OnMouseMove(nFlags,point);
}
LRESULT CButtonExtend::OnMouseHover(WPARAM wparam, LPARAM lparam)
{
m_txtInfo->SetWindowText(m_strInformation);
return m_bTracking;
}
LRESULT CButtonExtend::OnMouseLeave(WPARAM wparam,LPARAM lparam)
{
m_txtInfo->SetWindowText("");
m_bTracking = FALSE;
return 0;
}
Now, this is all generally fine and works as expected - the
SetWindowText call just sets/clears a text box that displays
information about a button which when the mouse hovers over it.
My problem has arisen when I've tried to run my app under Windows XP
with the "Windows XP" desktop theme set. (Previously, I had been
developing the app in Win2000). When using this theme, a mouse cursor
hovering over a button (without a click) causes an orangey highlight to
appear around the button's edges, and it disappears when the mouse
leaves the button area. However, when using a button from my
ButtonExtend class, the orange highlight remains even after the cursor
moves away from the button.
The problem goes away if I disable my OnMouseLeave handler and don't
process the WM_MOUSELEAVE message - however, I need this handler to
clear the text in my information box after the mouse leaves a button's
area. I've been fiddling with common controls, manifests, a zillion
message handlers and scouring the MSDN without success. Does anyone
have any suggestions? They would be much appreciated.
Further - there is one message specific to XP (BCN_HOTITEMCHANGE) which
I suspect could be the culprit here. However, when I try to write a
handler for the message in the dialog class that owns the
CButtonExtends, the compiler insists that BCN_HOTITEMCHANGE is an
unresolved symbol, _even though_ when I hover over it in the code
editor, IntelliSense correctly identifies and defines it. I've included
the commctrl.h file in my code.
Any pointers definitely welcome! Thanks.