doue8385 2019-04-15 12:09
浏览 107

如何在无边界的窗口中保持阴影

I'm trying to drop a shadow on a borderless window using Qt in windows. I succeeded in dropping the shadow when launching the application, referring to the following article.

But I encountered the problem that the shadow will disappear if the application is deactivated and reactivated ( In other words, click the other applications, and click my application again.)

Perhaps my implementation is not good enough. I'm glad if you have some ideas for this issue.

I'm trying to imprement Qt with Go bindings Here is the code snippet:

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)
}

All source code is in my repository; akiyosi/goqtframelesswindow

  • 写回答

1条回答 默认 最新

  • dsvcqvp139098 2019-04-19 02:22
    关注

    WM_NCCALCSIZE:

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

    And also:

    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.

    Starting with Windows Vista, simply returning 0 does not affect extended frames, only the standard frame will be removed.

    EDIT:

    Set the return value with the DWL_MSGRESULT instead of result = 0.

    评论

报告相同问题?

悬赏问题

  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误