Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem calling OnMouseMove for CButton in CDialog

380 views
Skip to first unread message

Martin

unread,
Jan 14, 2008, 4:48:20 AM1/14/08
to
I have a CDialog with a custom control JS in it that inherits from
CButton. (It's a groupbox button with some other child controls in
it). I'd like to catch the WM_MOUSEMOVE event for this control.
However, nothing happens when the mouse moves over the control.

In JS.h, I have
//{{AFX_MSG(JS)
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
//}}AFX_MSG

and in JS.cpp, I have
BEGIN_MESSAGE_MAP(JS, CButton)
//{{AFX_MSG_MAP(JS)
ON_WM_MOUSEMOVE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

The callback function is defined as this:
void JS::OnMouseMove(UINT nFlags, CPoint point)
{
SetWindowText("move");
return;
}

The JS element gets created from the CDialog object like this:
js->Create("Joystick", WS_CHILD|WS_VISIBLE|BS_NOTIFY, CRect(px,py, 0,
0), this, 0);

Am I missing something here?

Jeff Partch

unread,
Jan 14, 2008, 5:28:58 AM1/14/08
to
"Martin" <love...@frustratedhousewives.zzn.com> wrote in message
news:448686ab-835e-4cf3...@q39g2000hsf.googlegroups.com...

>I have a CDialog with a custom control JS in it that inherits from
> CButton. (It's a groupbox button with some other child controls in
> it). I'd like to catch the WM_MOUSEMOVE event for this control.
> However, nothing happens when the mouse moves over the control.
>
> Am I missing something here?

I believe the BS_GROUPBOX returns HTTRANSPARENT in response to WM_NCHITTEST.
--
Jeff Partch


David Webber

unread,
Jan 14, 2008, 5:33:28 AM1/14/08
to
"Martin" <love...@frustratedhousewives.zzn.com> wrote in message
news:448686ab-835e-4cf3...@q39g2000hsf.googlegroups.com...

>I have a CDialog with a custom control JS in it that inherits from


> CButton. (It's a groupbox button with some other child controls in
> it). I'd like to catch the WM_MOUSEMOVE event for this control.
> However, nothing happens when the mouse moves over the control.

Two possibilities:

1. The controls within your group box are probably higher in the z-order
(after it in the tab order). If the mouse moves over them, then they will
be getting the WM_MOUSEMOVE

2. It may be worth calling InvalidateRect( NULL ) after the
SetWindowText() - I can never remember if this is necessary, but it probably
doesn't do any harm.

(If this *is* the problem and it causes flicker, then you can always
GetWindowText and only change it if it is necessary.)

Dave
--
David Webber
Author of 'Mozart the Music Processor'
http://www.mozart.co.uk
For discussion/support see
http://www.mozart.co.uk/mozartists/mailinglist.htm

Martin

unread,
Jan 14, 2008, 5:38:03 AM1/14/08
to
On 14 Jan, 10:48, Martin <lovesl...@frustratedhousewives.zzn.com>
wrote:

I have also tried catching the message with a PreTranslateMessage
function:
BOOL JS::PreTranslateMessage(MSG* pMsg)
{
switch(pMsg->message) {
case WM_MOUSEMOVE:
this->OnMouseMove(pMsg->wParam, pMsg->pt);
break;
}
return CButton::PreTranslateMessage(pMsg);
}

Then, OnMouseMove gets called when the mouse is over one of the sub-
buttons of the control, but not when it is elsewhere within the JS
groupbox. Why?

Martin

unread,
Jan 14, 2008, 6:21:34 AM1/14/08
to
On 14 Jan, 11:33, "David Webber" <d...@musical-dot-demon-dot-co.uk>
wrote:
> "Martin" <lovesl...@frustratedhousewives.zzn.com> wrote in message

>
> news:448686ab-835e-4cf3...@q39g2000hsf.googlegroups.com...
>
> >I have a CDialog with a custom control JS in it that inherits from
> > CButton. (It's a groupbox button with some other child controls in
> > it). I'd like to catch the WM_MOUSEMOVE event for this control.
> > However, nothing happens when the mouse moves over the control.
>
> Two possibilities:
>
> 1. The controls within your group box are probably higher in the z-order
> (after it in the tab order). If the mouse moves over them, then they will
> be getting the WM_MOUSEMOVE

I tried calling this->BringWindowToTop() in the object's Create
method, which I guess should bring it to the topmost z-order. That
didn't change anything.

> 2. It may be worth calling InvalidateRect( NULL ) after the
> SetWindowText() - I can never remember if this is necessary, but it probably
> doesn't do any harm.

That didn't do anything either.

Thanks for your suggestions.

Martin

unread,
Jan 14, 2008, 6:23:41 AM1/14/08
to
On 14 Jan, 11:28, "Jeff Partch" <je...@mvps.org> wrote:
> "Martin" <lovesl...@frustratedhousewives.zzn.com> wrote in message

Does that mean that it's simply impossible to catch mouse movements in
a CButton-derived class with the BS_GROUPBOX style?

Martin

unread,
Jan 14, 2008, 6:51:40 AM1/14/08
to
On 14 Jan, 12:23, Martin <lovesl...@frustratedhousewives.zzn.com>
wrote:

OK, I think I've got it now. I added an OnNcHitTest method using
ClassWizard, and there I return HTCLIENT. Now I can catch mouse
movements within the whole control.

Thank you very much.

0 new messages