gpt4 book ai didi

c++ - 如何使用 WM_NCHITTEST 从子窗口 move 无边框的父窗口

转载 作者:可可西里 更新时间:2023-11-01 09:21:21 33 4
gpt4 key购买 nike

所以我创建了这个带有自定义 move 和调整大小的弹出窗口,按住 ctrl 键并单击客户端中的任意位置以 move 和 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);

最佳答案

子窗口过程应该返回 HTTRANSPARENT 以响应 WM_NCHITTEST,并且(引用 MSDN)“消息将被发送到相同的底层窗口线程直到其中一个返回不是 HTTRANSPARENT 的代码”

关于c++ - 如何使用 WM_NCHITTEST 从子窗口 move 无边框的父窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8969852/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com