Full screen dialogs

本文介绍了一种简单的方法来创建全屏对话框,通过移除窗口标题栏和边框,并使用SetWindowPos调整窗口位置及大小以覆盖整个屏幕。这种方法适用于需要全屏显示对话框的应用场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Full screen dialogs

Sometimes you might feel the need to make a full screen dialog - means a dialog that fills up the entire monitor. Well it's rather easy to achieve this. You need to remove the caption and the border which we do by removing the WS_CAPTION and the WS_BORDER styles. Then we call SetWindowPos with HWND_TOPMOST and resize the dialog to fill up the entire screen. Just put the following code into your OnInitDialog function.

BOOL CFullScrDlgDlg::OnInitDialog()
{
    CDialog::OnInitDialog();

    //...

    int cx, cy; 
    HDC dc = ::GetDC(NULL); 
    cx = GetDeviceCaps(dc,HORZRES) + 
        GetSystemMetrics(SM_CXBORDER); 
    cy = GetDeviceCaps(dc,VERTRES) +
        GetSystemMetrics(SM_CYBORDER); 
    ::ReleaseDC(0,dc); 

    // Remove caption and border
    SetWindowLong(m_hWnd, GWL_STYLE, 
        GetWindowLong(m_hWnd, GWL_STYLE) & 
    (~(WS_CAPTION | WS_BORDER))); 

    // Put window on top and expand it to fill screen
    ::SetWindowPos(m_hWnd, HWND_TOPMOST, 
        -(GetSystemMetrics(SM_CXBORDER)+1), 
        -(GetSystemMetrics(SM_CYBORDER)+1), 
        cx+1,cy+1, SWP_NOZORDER); 

    //...

    return TRUE; 
} 
import QtQuick import QtQuick.Layouts import QtQuick.Controls ApplicationWindow{ id:appWindow visible: true width: 600 height: 400 menuBar: MenuBar{ id:appMenuBar Menu{ title: qsTr("&File") //RECOMMENDED Way: to encapsulate actions using MenuItem MenuItem{action: actions.openAction} MenuItem{action: actions.folderAction} MenuItem{action: actions.exitAction} } Menu{ title: qsTr("&View") //using Action object as menu item directly Action{ text:qsTr("&Full Screen") icon.name:"view-fullscreen" onTriggered: { content.fullScreen(); } } //sub menu Menu{ title: qsTr("ViewMode") MenuItem{action: actions.imageModePreserveAspectCropAction} MenuItem{action: actions.imageModePreserveAspectFitAction} MenuItem{action: actions.imageModeStretchAction} } } Menu { title: qsTr("&Help") //using Action object id as menu item contentData:[ actions.contentsAction, actions.aboutAction ] } } header: ToolBar { id:appToolBar RowLayout{ ToolButton{ action: actions.openAction } ToolButton{ action: actions.folderAction } } } //setting the logic of all actions Actions{ id:actions openAction.onTriggered: content.dialogs.openFileDialog() folderAction.onTriggered: content.dialogs.openFolderDialog() imageModePreserveAspectCropAction.onTriggered: content.setImageFillMode(Image.PreserveAspectCrop) imageModePreserveAspectFitAction.onTriggered: content.setImageFillMode(Image.PreserveAspectFit) imageModeStretchAction.onTriggered: content.setImageFillMode(Image.Stretch) aboutAction.onTriggered: content.dialogs.openAboutDialog() } //setting the logic of content Content{ id:content anchors.fill: parent onFullScreen: { menuBar.visible = false; header.visible = false; appWindow.showFullScreen(); isFullScreen = true; singleView(); } onWindow: { menuBar.visible = true header.visible = true appWindow.showNormal() isFullScreen=false; } } }
06-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值