如何使用 WM_NCHITTEST 从子窗口移动无边框的父窗口
所以我创建了这个带有自定义移动和大小调整的弹出窗口,按下 ctrl 并单击客户端中的任意位置以移动并在边框处进行 alt 调整大小。问题是,现在我正在该窗口内部创建子窗口,但这里出现“错误”。我找不到如何将消息发送到父窗口。 这是我尝试过的。
我在父窗口的 wndproc 中处理这些消息
case WM_NCHITTEST:
//determines if the window should be moving, sizing or don't do a thing
return DoHitTest(pWnd, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) );
case WM_NCLBUTTONDOWN:
//just set the cursor for visual notice
if (GetAsyncKeyState(VK_CONTROL) & 0x8000)
SetCursor(LoadCursor(NULL, IDC_SIZEALL));
break;
,这是 doHitTest 方法
int WindowGnaq::DoHitTest(WindowBase* pWnd, int x, int y)
{
if( GetAsyncKeyState( VK_CONTROL ) & 0x8000 )
return HTCAPTION;
if( m_bAdjustable && GetAsyncKeyState( VK_MENU ) & 0x8000 )
{
short spare = 5;
RECT r;
pWnd->GetRect(r);
r.right -= 1;
r.bottom -= 1;
if (x < (r.left + spare) && y < (r.top + spare))
return HTTOPLEFT;
else if (x < (r.left + spare) && y > (r.bottom - spare))
return HTBOTTOMLEFT;
else if (x < (r.left + spare))
return HTLEFT;
else if (x > (r.right - spare) && y < (r.top + spare))
return HTTOPRIGHT;
else if (x > (r.right - spare) && y > (r.bottom - spare))
return HTBOTTOMRIGHT;
else if (x > (r.right - spare))
return HTRIGHT;
else if (y < (r.top + spare))
return HTTOP;
else if (y > (r.bottom - spare))
return HTBOTTOM;
}
return HTCLIENT;
}
,这就是我在子窗口过程中尝试的方法
case WM_NCHITTEST:
//this just moves the mouse to the border i don't have but doesn't make me able to move
return SendMessage( m_pParent->GetHandle(), WM_SYSCOMMAND, SC_MOVE, -1);
//this doesn't to anything
return PostMessage( m_pParent->GetHandle(), msg, wParam, lParam);
//this makes the childwindow move instead of the parent
return SendMessage( m_pParent->GetHandle(), msg, wParam, lParam);
so I have created this popup window with a custom move and sizing, pressing ctrl and click anywhere in the client to move and alt at the borders to size. The problem is, now i'm creating child windows for inside this window and here it goes "wrong". I can't find how to send the message to the parent window.
This is what I've tried.
I handle these messages in the wndproc of the parent window
case WM_NCHITTEST:
//determines if the window should be moving, sizing or don't do a thing
return DoHitTest(pWnd, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) );
case WM_NCLBUTTONDOWN:
//just set the cursor for visual notice
if (GetAsyncKeyState(VK_CONTROL) & 0x8000)
SetCursor(LoadCursor(NULL, IDC_SIZEALL));
break;
and this is the doHitTest method
int WindowGnaq::DoHitTest(WindowBase* pWnd, int x, int y)
{
if( GetAsyncKeyState( VK_CONTROL ) & 0x8000 )
return HTCAPTION;
if( m_bAdjustable && GetAsyncKeyState( VK_MENU ) & 0x8000 )
{
short spare = 5;
RECT r;
pWnd->GetRect(r);
r.right -= 1;
r.bottom -= 1;
if (x < (r.left + spare) && y < (r.top + spare))
return HTTOPLEFT;
else if (x < (r.left + spare) && y > (r.bottom - spare))
return HTBOTTOMLEFT;
else if (x < (r.left + spare))
return HTLEFT;
else if (x > (r.right - spare) && y < (r.top + spare))
return HTTOPRIGHT;
else if (x > (r.right - spare) && y > (r.bottom - spare))
return HTBOTTOMRIGHT;
else if (x > (r.right - spare))
return HTRIGHT;
else if (y < (r.top + spare))
return HTTOP;
else if (y > (r.bottom - spare))
return HTBOTTOM;
}
return HTCLIENT;
}
and this is what I'm trying in the childs window procedure
case WM_NCHITTEST:
//this just moves the mouse to the border i don't have but doesn't make me able to move
return SendMessage( m_pParent->GetHandle(), WM_SYSCOMMAND, SC_MOVE, -1);
//this doesn't to anything
return PostMessage( m_pParent->GetHandle(), msg, wParam, lParam);
//this makes the childwindow move instead of the parent
return SendMessage( m_pParent->GetHandle(), msg, wParam, lParam);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
子窗口过程应该返回
HTTRANSPARENT
来响应WM_NCHITTEST
,并且(引用 MSDN)"消息将被发送到同一线程中的底层窗口,直到其中一个窗口返回以下代码:不是 HTTRANSPARENT”
。The childrens' window procedures should return
HTTRANSPARENT
in response toWM_NCHITTEST
, and (citing MSDN)"the message will be sent to underlying windows in the same thread until one of them returns a code that is not HTTRANSPARENT"
.