我试图在QT中创建一个看起来像旧版Firefox和Opera的东西(非客户区左上角的按钮与标题重叠)。
我完成了所有工作,但我遇到了2个问题。
在调整大小时,我的窗口会随机变成部分黑色和随机的黑色形状。我不确定为什么会这样做。但确实如此。见#1
我的主容器似乎没有延伸到完整的可用区域,右侧和底部缺少50个左右的像素。见#2
#1
#2
我的代码是(它从QT的nativeEvents运行)。
bool MainWindow::winEvent(MSG *msg, long *result)
{
bool fCallDWP = true;
BOOL fDwmEnabled = FALSE;
LRESULT lRet = 0;
HRESULT hr = S_OK;
HWND hWnd = msg->hwnd;
UINT message = msg->message;
WPARAM wParam = msg->wParam;
LPARAM lParam = msg->lParam;
// Winproc worker for custom frame issues.
hr = DwmIsCompositionEnabled(&fDwmEnabled);
if (!SUCCEEDED(hr) || !fDwmEnabled)
{
return false;
}
if (message == WM_NCHITTEST)
{
return hitTestNCA(msg, result);
}
fCallDWP = !DwmDefWindowProc(hWnd, message, wParam, lParam, &lRet);
// Handle window activation.
if (message == WM_ACTIVATE)
{
// Extend the frame into the client area.
MARGINS margins;
margins.cxLeftWidth = -1;
margins.cxRightWidth = -1;
margins.cyBottomHeight = -1;
margins.cyTopHeight = -1;
hr = DwmExtendFrameIntoClientArea(hWnd, &margins);
if (!SUCCEEDED(hr))
{
// Handle error.
}
fCallDWP = true;
lRet = 0;
}
// Handle the non-client size message.
if ((message == WM_NCCALCSIZE) && (wParam == TRUE))
{
// Calculate new NCCALCSIZE_PARAMS based on custom NCA inset.
NCCALCSIZE_PARAMS *pncsp = reinterpret_cast<NCCALCSIZE_PARAMS*>(lParam);
pncsp->rgrc[0].left = pncsp->rgrc[0].left + 0;
pncsp->rgrc[0].top = pncsp->rgrc[0].top + 0;
pncsp->rgrc[0].right = pncsp->rgrc[0].right - 0;
pncsp->rgrc[0].bottom = pncsp->rgrc[0].bottom - 0;
lRet = 0;
// No need to pass the message on to the DefWindowProc.
fCallDWP = false;
}
if (message == WM_GETMINMAXINFO) {
MINMAXINFO *mmi = (MINMAXINFO*)lParam;
QRect rect = QApplication::desktop()->availableGeometry();
mmi->ptMaxSize.x = rect.width();
mmi->ptMaxSize.y = rect.height()-1;
mmi->ptMaxPosition.x = 0;
mmi->ptMaxPosition.y = 0;
lRet = 0;
fCallDWP = false;
}
if (!fCallDWP)
*result = lRet;
return !fCallDWP;
}
WM_NCCALCSIZE
中某处出现问题导致这些问题。如果我将其删除(并返回原始窗口,一切正常)。
编辑:我已经确定它与透明度有关。虽然我不确定是哪一部分,但如果我删除小部件半透明标志,它就不再这样做了。