WM_SYSCOMMAND SC_MOVE eats up mouse events and mouse up is not fired

二次信任 提交于 2019-12-12 00:30:24

问题


My program is a chromeless window and I want to move the window when user drag any part of my dialog. Once WM_SYSCOMMAND is used, all subsequent mouse events are lost.

First I wrote a program to capture the mouse events and all working fine with WTL.

BEGIN_MSG_MAP(CMainDlg)
    MSG_WM_LBUTTONUP(OnMouseUp)
    MSG_WM_LBUTTONDOWN(OnMouseDown)
....
LRESULT OnMouseDown ( UINT uKeys, CPoint pt ) {
    print ("on mouse down");
    return 0;
}
LRESULT OnMouseUp ( UINT uKeys, CPoint pt ) {
    print ("on mouse up");
    return 0;
}

Then I change onMouseDown above to,

LRESULT OnMouseDown ( UINT uKeys, CPoint pt ) {
    print ("on mouse down");
    this->SendMessageW(WM_SYSCOMMAND, SC_MOVE|0x0002);
    return 0;
}

The drag is working and the windows move along with the mouse. However, OnMouseUp event is no longer fired.

Tried many different approach using WM_NCHITTEST, or ProcessMessage setHandled to true/false without success.

Much appreciate if anyone has any suggestions :)


回答1:


Thanks for describing why you're doing this, because there's a much better approach: Return HTCAPTION in response to WM_NCHITTEST.




回答2:


The DefWindowProc handler for WM_SYSCOMMAND will be eating the mouse button up message which is why you don't see it. However, your SendMessage call won't actually return until the drag has finished so you can take that as being notification of mouse button up.



来源:https://stackoverflow.com/questions/11979278/wm-syscommand-sc-move-eats-up-mouse-events-and-mouse-up-is-not-fired

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!