zoukankan      html  css  js  c++  java
  • Windows全屏代码--摘自Chrome

    变量定义:

        typedef struct SCREEN_INFO
        {
            DWORD dwStyle;
            DWORD dwExStyle;
            CRect rect;
            bool bMaximized;
        }SreenInfo;
    
        SreenInfo m_screenInfo;
        bool m_bFullScreen = false;

    实现代码:

        if (!m_bFullScreen) 
        {
             // Save current window information.  We force the window into restored mode
             // before going fullscreen because Windows doesn't seem to hide the
             // taskbar if the window is in the maximized state.
             m_screenInfo.bMaximized = !!::IsZoomed(this->m_hWnd);
    //          if (m_screenInfo.bMaximized)
    //               ::SendMessage(this->m_hWnd, WM_SYSCOMMAND, SC_RESTORE, 0);
             m_screenInfo.dwStyle = GetWindowLongPtr(this->m_hWnd, GWL_STYLE);
             m_screenInfo.dwExStyle = GetWindowLongPtr(this->m_hWnd, GWL_EXSTYLE);
             GetWindowRect(m_screenInfo.rect);
        }
       
        m_bFullScreen = !m_bFullScreen;
    
        if (m_bFullScreen) 
        {
          // Set new window style and size.
            SetWindowLongPtr(this->m_hWnd, GWL_STYLE,
              m_screenInfo.dwStyle & ~(WS_CAPTION | WS_THICKFRAME));
            SetWindowLongPtr(this->m_hWnd, GWL_EXSTYLE,
              m_screenInfo.dwExStyle & ~(WS_EX_DLGMODALFRAME |
                                WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE));
               // On expand, if we're given a window_rect, grow to it, otherwise do
               // not resize.
          bool for_metro = false;
          if (!for_metro)
          {
              MONITORINFO monitor_info; 
              monitor_info.cbSize = sizeof(monitor_info);
              GetMonitorInfo(MonitorFromWindow(this->m_hWnd, MONITOR_DEFAULTTONEAREST), & monitor_info);
              CRect window_rect(monitor_info.rcMonitor);
              SetWindowPos(NULL, window_rect.left, window_rect.top,
                                 window_rect.Width(), window_rect.Height(),
                                 SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED);
          }
        }
        else 
        {
             // Reset original window style and size.  The multiple window size/moves
             // here are ugly, but if SetWindowPos() doesn't redraw, the taskbar won't be
             // repainted.  Better-looking methods welcome.
             SetWindowLongPtr(this->m_hWnd, GWL_STYLE, m_screenInfo.dwStyle);
             SetWindowLongPtr(this->m_hWnd, GWL_EXSTYLE, m_screenInfo.dwExStyle);
    
             // On restore, resize to the previous saved rect size.
             CRect new_rect(m_screenInfo.rect);
             SetWindowPos(NULL, new_rect.left, new_rect.top,
                          new_rect.Width(), new_rect.Height(),
                          SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED);
        }

    参考:

    1. https://stackoverflow.com/questions/2382464/win32-full-screen-and-hiding-taskbar,第一个高赞回答。

    2.https://github.com/chromium/chromium/blob/master/ui/views/win/fullscreen_handler.cc, chromium 浏览器源代码。

  • 相关阅读:
    git线上操作
    IDEA快捷方式
    Java 四种线程池
    java 获取当前天之后或之前7天日期
    如何理解AWS 网络,如何创建一个多层安全网络架构
    申请 Let's Encrypt 通配符 HTTPS 证书
    GCE 部署 ELK 7.1可视化分析 nginx
    使用 bash 脚本把 AWS EC2 数据备份到 S3
    使用 bash 脚本把 GCE 的数据备份到 GCS
    nginx 配置 https 并强制跳转(lnmp一键安装包)
  • 原文地址:https://www.cnblogs.com/2018shawn/p/12054413.html
Copyright © 2011-2022 走看看