微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

wxWidgets和WM_NCHITTEST

我在Visual C ++ 2010中使用wxWidgets。

我的目标之一是能够移动我创build的窗口的任何部分(客户端或其他)。 为了这个目的,我过去用WM_NCHITTEST来欺骗Windows,认为我的窗口的每个部分都是标题栏。

wxWidgets应该怎么做?

经过广泛的研究,由于答复部门的不活动,我发现了一个可以接受的(虽然不是便携式的)解决方案:

WXLRESULT [your-wxWindow-inheriting-objectname-here]::MSWWindowProc(WXUINT message,WXWParaM wParam,WXLParaM lParam) { if(message==WM_NCHITTEST) { return HTCAPTION; } return wxFrame::MSWWindowProc(message,wParam,lParam); }

这可以用于任何WINAPI消息。

另一种便携式解决方案可能是这样

//assume your frame named wxUITestFrame //headers class wxUITestFrame : public wxFrame { DECLARE_EVENT_TABLE() protected: void OnMouseMove(wxMouseEvent& event); void OnLeftMouseDown(wxMouseEvent& event); void OnLeftMouseUp(wxMouseEvent& event); void OnMouseLeave(wxMouseEvent& event); private: bool m_isTitleClicked; wxPoint m_mousePosition; //mouse position when title clicked }; //cpp BEGIN_EVENT_TABLE(wxUITestFrame,wxFrame) EVT_MOTION(wxUITestFrame::OnMouseMove) EVT_LEFT_DOWN(wxUITestFrame::OnLeftMouseDown) EVT_LEFT_UP(wxUITestFrame::OnLeftMouseUp) EVT_LEAVE_WINDOW(wxUITestFrame::OnMouseLeave) END_EVENT_TABLE() void wxUITestFrame::OnMouseMove( wxMouseEvent& event ) { if (event.Dragging()) { if (m_isTitleClicked) { int x,y; GetPosition(&x,&y); //old window position int mx,my; event.GetPosition(&mx,&my); //new mouse position int dx,dy; //changed mouse position dx = mx - m_mousePosition.x; dy = my - m_mousePosition.y; x += dx; y += dy; Move(x,y); //move window to new position } } } void wxUITestFrame::OnLeftMouseDown( wxMouseEvent& event ) { if (event.GetY() <= 40) //40 is the height you want to set for title bar { m_isTitleClicked = true; m_mousePosition.x = event.GetX(); m_mousePosition.y = event.GetY(); } } void wxUITestFrame::OnLeftMouseUp( wxMouseEvent& event ) { if (m_isTitleClicked) { m_isTitleClicked = false; } } void wxUITestFrame::OnMouseLeave( wxMouseEvent& event ) { //if mouse dragging too fase,we will not get mouse move event //instead of mouse leave event here. if (m_isTitleClicked) { int x,&y); int mx,&my); int dx,dy; dx = mx - m_mousePosition.x; dy = my - m_mousePosition.y; x += dx; y += dy; Move(x,y); } }

实际上,John Locke在1楼提到的解决方案在wxmsW中more提示,而在linux系统中,我们可以在标题被点击时模拟ALT BUTTON DOWN消息。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐