WM_LBUTTONUP does not trigger, please help
-
I have a simple code where a user moves a window and when the user releases the window, a message box is displayed. here is my code for that.
void CFldWnd::OnLButtonDown(UINT nFlags, CPoint point) { SendMessage(WM_NCLBUTTONDOWN, HTCAPTION); CWnd::OnLButtonDown(nFlags, point); } void CFldWnd::OnLButtonUp(UINT nFlags, CPoint point) { MessageBox("Button up"); CWnd::OnLButtonUp(nFlags, point); }
the window moving part works fine but when i release the left mouse button, messagebox is not displayed. but when i double click on the window, message box is displayed. please help!!!! thanx in advance! -
I have a simple code where a user moves a window and when the user releases the window, a message box is displayed. here is my code for that.
void CFldWnd::OnLButtonDown(UINT nFlags, CPoint point) { SendMessage(WM_NCLBUTTONDOWN, HTCAPTION); CWnd::OnLButtonDown(nFlags, point); } void CFldWnd::OnLButtonUp(UINT nFlags, CPoint point) { MessageBox("Button up"); CWnd::OnLButtonUp(nFlags, point); }
the window moving part works fine but when i release the left mouse button, messagebox is not displayed. but when i double click on the window, message box is displayed. please help!!!! thanx in advance!Try listening for WM_NCLBUTTONUP, but this would trigger also when the user simply clicks somewhere in the non-client area of the window.
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > Sometimes you just have to hate coding to do it well. <
-
I have a simple code where a user moves a window and when the user releases the window, a message box is displayed. here is my code for that.
void CFldWnd::OnLButtonDown(UINT nFlags, CPoint point) { SendMessage(WM_NCLBUTTONDOWN, HTCAPTION); CWnd::OnLButtonDown(nFlags, point); } void CFldWnd::OnLButtonUp(UINT nFlags, CPoint point) { MessageBox("Button up"); CWnd::OnLButtonUp(nFlags, point); }
the window moving part works fine but when i release the left mouse button, messagebox is not displayed. but when i double click on the window, message box is displayed. please help!!!! thanx in advance!If the mouse is over the window, it will receive WM_LBUTTONUP, if the mouse is outside - it will not. To overcome this situation, you need to 'SetCapture' on WM_LBUTTONDOWN and 'ReleaseCapture' on WM_LBUTTONUP...
-
I have a simple code where a user moves a window and when the user releases the window, a message box is displayed. here is my code for that.
void CFldWnd::OnLButtonDown(UINT nFlags, CPoint point) { SendMessage(WM_NCLBUTTONDOWN, HTCAPTION); CWnd::OnLButtonDown(nFlags, point); } void CFldWnd::OnLButtonUp(UINT nFlags, CPoint point) { MessageBox("Button up"); CWnd::OnLButtonUp(nFlags, point); }
the window moving part works fine but when i release the left mouse button, messagebox is not displayed. but when i double click on the window, message box is displayed. please help!!!! thanx in advance!TThank u 4 ur quick responses.. i tried both of them but the problem still exists.. I commented SendMessage(WM_NCLBUTTONDOWN,HTCATION); and put some variable assigning code there and both LBUTTONDOWN and LBUTTONUP triggers.. when put back SendMessage(WM_NCLBUTTONDOWN,HTCATION);, LBUTTONUP does not trigger.. i dont know wat to do..
-
I have a simple code where a user moves a window and when the user releases the window, a message box is displayed. here is my code for that.
void CFldWnd::OnLButtonDown(UINT nFlags, CPoint point) { SendMessage(WM_NCLBUTTONDOWN, HTCAPTION); CWnd::OnLButtonDown(nFlags, point); } void CFldWnd::OnLButtonUp(UINT nFlags, CPoint point) { MessageBox("Button up"); CWnd::OnLButtonUp(nFlags, point); }
the window moving part works fine but when i release the left mouse button, messagebox is not displayed. but when i double click on the window, message box is displayed. please help!!!! thanx in advance!The mouse up message does happen - you can check this with Spy++. But the window moving stuff happens in response to the WM_NCLBUTTONDOWN message you've manually sent. That starts a message loop looking for mouse messages that is not the MFC message loops. It moves the window until you let go of the mouse, or press escape. If you want your window to be movable with the mouse, a far more elegant way of doing it is responding to the WM_NCHITTEST message.
class CMyMovableDialog : public CDialog
{
...
afx_msg LRESULT OnNcHitTest(CPoint point);
...
};
...
ON_WM_NCHITTEST()
...
LRESULT CMyMovableDialog::OnNcHitTest(CPoint point)
{
return HTCAPTION; // make it think everywhere is a caption!
}I hope that helps, Iain.
I have now moved to Sweden for love (awwww). If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), or need cotract work done, give me a job! http://cv.imcsoft.co.uk/[^]
-
The mouse up message does happen - you can check this with Spy++. But the window moving stuff happens in response to the WM_NCLBUTTONDOWN message you've manually sent. That starts a message loop looking for mouse messages that is not the MFC message loops. It moves the window until you let go of the mouse, or press escape. If you want your window to be movable with the mouse, a far more elegant way of doing it is responding to the WM_NCHITTEST message.
class CMyMovableDialog : public CDialog
{
...
afx_msg LRESULT OnNcHitTest(CPoint point);
...
};
...
ON_WM_NCHITTEST()
...
LRESULT CMyMovableDialog::OnNcHitTest(CPoint point)
{
return HTCAPTION; // make it think everywhere is a caption!
}I hope that helps, Iain.
I have now moved to Sweden for love (awwww). If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), or need cotract work done, give me a job! http://cv.imcsoft.co.uk/[^]
well, this still does not solve my problem, when i catch OnNcHitTest, i cannot even trigger the LBUTTONDOWN event.. anyway i learnt something out of your reply, thanx mate!
-
well, this still does not solve my problem, when i catch OnNcHitTest, i cannot even trigger the LBUTTONDOWN event.. anyway i learnt something out of your reply, thanx mate!
Isuru_Perera wrote:
well, this still does not solve my problem
Well, I'm not sure what the problem actually is. You had a mystery of a "missing" WM_LBUTTONUP, which is now explained. So, what's the actual problem that you're trying to solve? Iain,
I have now moved to Sweden for love (awwww). If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), or need cotract work done, give me a job! http://cv.imcsoft.co.uk/[^]
-
I have a simple code where a user moves a window and when the user releases the window, a message box is displayed. here is my code for that.
void CFldWnd::OnLButtonDown(UINT nFlags, CPoint point) { SendMessage(WM_NCLBUTTONDOWN, HTCAPTION); CWnd::OnLButtonDown(nFlags, point); } void CFldWnd::OnLButtonUp(UINT nFlags, CPoint point) { MessageBox("Button up"); CWnd::OnLButtonUp(nFlags, point); }
the window moving part works fine but when i release the left mouse button, messagebox is not displayed. but when i double click on the window, message box is displayed. please help!!!! thanx in advance!