Thanks,
-Tom
int Classname::OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT
message)
{
if(message==WM_LBUTTONDOWN) // this will always work
{
AfxMessageBox("WM_LBUTTONDOWN");
}
if(message==WM_LBUTTONUP) // this doesn't
work
{
AfxMessageBox("WM_LBUTTONUP");
}
}
The documentation for WM_MOUSEACTIVATE says
"msg ... Specifies the identifier of the mouse message
generated when the user pressed a mouse button"
I think the key phrase there is "when the user pressed a
mouse button". It doesn't say anything about when the user
releases a mouse button, probably because releasing a
mouse button doesn't trigger an advance
WM_MOUSEACTIVATE message, because the window
is already 'activated'.
Why not just trap WM_LBUTTONDOWN & WM_LBUTTONUP
at the top level, i.e. at the same level as
WM_MOUSEACTIVATE?
--
John A. Grant * I speak only for myself * (remove 'z' to reply)
Radiation Geophysics, Geological Survey of Canada, Ottawa
If you followup, please do NOT e-mail me a copy: I will read it here
void CWinDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
AfxMessageBox("WM_LBUTTONUP");
CDialog::OnLButtonUp(nFlags, point);
}
"John A. Grant" <zjag...@znrcanz.gcz.ca> wrote in message
news:84rp8j$9b...@nrn2.NRCan.gc.ca...
>I tried trapping the WM_LBUTTONUP message in my dialog based app, but it is
>not triggered when you click on one of the push buttons. It will work when
>you click on the client area or on an image with the notify checkbox
>unchecked but not on the button.
>void CWinDlg::OnLButtonUp(UINT nFlags, CPoint point)
>{
> AfxMessageBox("WM_LBUTTONUP");
> CDialog::OnLButtonUp(nFlags, point);
>}
Now you're talking about something entirely different.
Repeat after me: "in Windows, 'everything' is a window".
The mouse button messages go to the current window.
If that's your main window or the surface of the dialog
box, then you'll receive them in the WndProc() or
DlgProc(), as you've noted. Buf if you click on a button,
which is just another window, then the WndProc() of that
window (window class="button"), will receive the mouse
message. If you want to intercept WM_ whatever for a
button, then you need to subclass the button and intercept
them there.
I forgot to mention that you need to be careful when you
subclass. You need to pass on messages like
WM_LBUTTONUP & WM_LBUTTONDOWN to the
original WndProc(). It relies on those messages to detect
the clicking of the button. At WM_LBUTTONDOWN, it
probably does SetCapture() so it will get WM_LBUTTONUP.
When it gets it, it checks to see if it is over the button. If
so, it sends WM_COMMAND/BN_CLICKED to the parent
(usually the dialog box). If not, there is no button click. You
can see that when you click on a button, hold it down, move
off the button and release it.
Tom Ripley schrieb:
> I tried trapping the WM_LBUTTONUP message in my dialog based app, but it is
> not triggered when you click on one of the push buttons. It will work when
> you click on the client area or on an image with the notify checkbox
> unchecked but not on the button.
> Thanks,
> -Tom
>
> void CWinDlg::OnLButtonUp(UINT nFlags, CPoint point)
> {
> AfxMessageBox("WM_LBUTTONUP");
> CDialog::OnLButtonUp(nFlags, point);
> }
>
> "John A. Grant" <zjag...@znrcanz.gcz.ca> wrote in message
> news:84rp8j$9b...@nrn2.NRCan.gc.ca...
> > Tom Ripley wrote in message ...
> > >Is there any way to catch the WM_LBUTTONUP message? I have tried to catch
> > it
> > >in the WM_MOUSEACTIVATE event it works fine for WM_LBUTTONDOWN but not
> > >WM_LBUTTONUP. I am using a dialog based mfc app in visual c++ 6.
> > [...code...]
> >
> > The documentation for WM_MOUSEACTIVATE says
> > "msg ... Specifies the identifier of the mouse message
> > generated when the user pressed a mouse button"
> >
> > I think the key phrase there is "when the user pressed a
> > mouse button". It doesn't say anything about when the user
> > releases a mouse button, probably because releasing a
> > mouse button doesn't trigger an advance
> > WM_MOUSEACTIVATE message, because the window
> > is already 'activated'.
> >
> > Why not just trap WM_LBUTTONDOWN & WM_LBUTTONUP
> > at the top level, i.e. at the same level as
> > WM_MOUSEACTIVATE?
> >