gpt4 book ai didi

qt - 如何在无边框窗口中保持阴影

转载 作者:IT王子 更新时间:2023-10-29 02:07:03 26 4
gpt4 key购买 nike

我正在尝试使用 Windows 中的 Qt 在无边框窗口上放置阴影。启动应用时,我成功地去掉了阴影,引用下面的文章。

但是我遇到了应用停用再重新激活阴影会消失的问题(换句话说,单击其他应用程序,然后再次单击我的应用程序。)

也许我的实现不够好。如果您对这个问题有一些想法,我很高兴。

我正在尝试用 Go bindings 改进 Qt这是代码片段:

package qframelesswindow

import (
"unsafe"

"github.com/therecipe/qt/core"
"github.com/therecipe/qt/widgets"

win "github.com/akiyosi/w32"
)

func (f *QFramelessWindow) SetNativeEvent(app *widgets.QApplication) {
filterObj := core.NewQAbstractNativeEventFilter()
filterObj.ConnectNativeEventFilter(func(eventType *core.QByteArray, message unsafe.Pointer, result int) bool {
msg := (*win.MSG)(message)
lparam := msg.LParam
hwnd := msg.Hwnd
var uflag uint
uflag = win.SWP_NOZORDER | win.SWP_NOOWNERZORDER | win.SWP_NOMOVE | win.SWP_NOSIZE | win.SWP_FRAMECHANGED
var nullptr win.HWND
shadow := &win.MARGINS{0, 0, 0, 1}

switch msg.Message {
case win.WM_CREATE:
style := win.WS_POPUP | win.WS_THICKFRAME | win.WS_MINIMIZEBOX | win.WS_MAXIMIZEBOX | win.WS_CAPTION
win.SetWindowLong(hwnd, win.GWL_STYLE, uint32(style))

win.DwmExtendFrameIntoClientArea(hwnd, shadow)
win.SetWindowPos(hwnd, nullptr, 0, 0, 0, 0, uflag)

return true

case win.WM_NCCALCSIZE:
if msg.WParam == 1 {
// this kills the window frame and title bar we added with WS_THICKFRAME and WS_CAPTION
result = 0
return true
}
return false

case win.WM_GETMINMAXINFO:
mm := (*win.MINMAXINFO)((unsafe.Pointer)(lparam))
mm.PtMinTrackSize.X = int32(f.minimumWidth)
mm.PtMinTrackSize.Y = int32(f.minimumHeight)
return true

default:
}
return false
})
app.InstallNativeEventFilter(filterObj)
}

所有源代码都在我的仓库中; akiyosi/goqtframelesswindow

最佳答案

WM_NCCALCSIZE :

If wParam is TRUE, the application should return zero or a combination of the following values.(In document)

还有:

When wParam is TRUE, simply returning 0 without processing the NCCALCSIZE_PARAMS rectangles will cause the client area to resize to the size of the window, including the window frame. This will remove the window frame and caption items from your window, leaving only the client area displayed.

从 Windows Vista 开始,简单地返回 0 不会影响扩展框架,只会删除标准框架。

编辑:

DWL_MSGRESULT 设置返回值而不是 result = 0

关于qt - 如何在无边框窗口中保持阴影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55688899/

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