zoukankan      html  css  js  c++  java
  • 仿win7窗体自动顶部最大化左侧右侧半屏效果(改写nativeEvent,使用AdjustWindowRectEx)

    #include "HMainWindow.h"
    
    #include <QApplication>
    #ifdef Q_OS_WIN
    #include <qt_windows.h>
    #include <dwmapi.h>
    
    #ifndef GET_X_LPARAM
    #define GET_X_LPARAM(lParam)    ((int)(short)LOWORD(lParam))
    #endif
    #ifndef GET_Y_LPARAM
    #define GET_Y_LPARAM(lParam)    ((int)(short)HIWORD(lParam))
    #endif
    
    #endif
    HMainWindow::HMainWindow(QWidget *parent) : QMainWindow(parent)
    {
        setObjectName("HFramer");
        setWindowTitle("HFramer");
        setWidgetBorderless(this);
    }
    
    
    void HMainWindow::setWidgetBorderless(const QWidget *widget)
    {
        setWindowFlags( Qt::WindowMinimizeButtonHint | Qt::FramelessWindowHint);
    #ifdef Q_OS_WIN
        HWND hwnd = reinterpret_cast<HWND>(widget->winId());
        DWORD style = GetWindowLong(hwnd, GWL_STYLE);
        SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_MAXIMIZEBOX | WS_THICKFRAME | WS_CAPTION);
    #endif
    }
    
    bool HMainWindow::nativeEvent(const QByteArray &eventType, void *message, long *result)
    {
    #ifdef Q_OS_WIN
        if (eventType != "windows_generic_MSG")
            return false;
    
        MSG* msg = static_cast<MSG*>(message);
        QWidget* widget = QWidget::find(reinterpret_cast<WId>(msg->hwnd));
        if (!widget)
            return false;
    
        switch (msg->message) {
    
        case WM_NCCALCSIZE: {
            *result = 0;
            return true;
        }
    
        case WM_NCHITTEST: {
            const LONG borderWidth = 9;
            RECT winrect;
            GetWindowRect(msg->hwnd, &winrect);
            long x = GET_X_LPARAM(msg->lParam);
            long y = GET_Y_LPARAM(msg->lParam);
    
            // bottom right
            if (x < winrect.right && x >= winrect.right - borderWidth &&
                    y < winrect.bottom && y >= winrect.bottom - borderWidth)
            {
                *result = HTBOTTOMRIGHT;
                return true;
            }
    
            return false;
        }
    
        case WM_GETMINMAXINFO: {
            if (::IsZoomed(msg->hwnd)) {
    
                RECT frame = { 0, 0, 0, 0 };
                AdjustWindowRectEx(&frame, WS_OVERLAPPEDWINDOW, FALSE, 0);
                frame.left = abs(frame.left);
                frame.top = abs(frame.bottom);
                widget->setContentsMargins(frame.left, frame.top, frame.right, frame.bottom);
            }
            else {
                widget->setContentsMargins(0, 0, 0, 0);
            }
    
            *result = ::DefWindowProc(msg->hwnd, msg->message, msg->wParam, msg->lParam);
            return true;
        }
            break;
    
        default:
            break;
        }
    
    #endif
    
        return QMainWindow::nativeEvent(eventType, message, result);
    }
    
    这样可以实现系统的虚框,重新写nativeEvent方法

    http://www.qtcn.org/bbs/read-htm-tid-62907.html

  • 相关阅读:
    五星评价
    IE9以上 CSS文件因Mime类型不匹配而被忽略 其他浏览器及IE8以下显示正常
    js时间显示设置
    jq手风琴---点击时列表的左边距逐渐减小
    break continue return
    validate插件:验证密码没有空格 用户名是5-10位 至少包含数字和大小写字母中的两种字符
    Commons IO
    Servlet & JSP
    设计模式
    Table of Contents
  • 原文地址:https://www.cnblogs.com/findumars/p/6759480.html
Copyright © 2011-2022 走看看