Win32 SDK中視窗全屏處理

來源:互聯網
上載者:User

      首先是考慮全屏處理的時機,是在建立視窗時還是顯示視窗時進行,若是前者,則可以:

BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   HWND hWnd;
   hInst = hInstance; // 將執行個體控制代碼儲存在全域變數中
    UINT width = GetSystemMetrics(SM_CXSCREEN);
    UINT height = GetSystemMetrics(SM_CYSCREEN);
   //建立視窗
   hWnd=CreateWindow(
       szWindowClass,
       szTitle,
       WS_POPUP,
       0,0,
       width,height,
       NULL,NULL,
       hInstance,
       NULL);
   if (!hWnd)
   {
      return FALSE;
   }
   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);
   return TRUE;
}

若是在顯示視窗時進行處理:

BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   HWND hWnd;
   hInst = hInstance; // 將執行個體控制代碼儲存在全域變數中
   hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
   if (!hWnd)
   {
      return FALSE;
   }
   HWND   hDesk;   
   RECT   rc;   
   hDesk   =   GetDesktopWindow();   
   GetWindowRect(   hDesk,   &rc   );   
   SetWindowLong(   hWnd,   GWL_STYLE,   WS_BORDER   );   
   SetWindowPos(   hWnd,   HWND_TOPMOST,   0,   0,   rc.right,   rc.bottom,   SWP_SHOWWINDOW);
   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);
   return TRUE;
}

也可以讓使用者控制全屏的時機,比如按下”ESC“鍵後進入全屏

BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   HWND hWnd;
   hInst = hInstance; // 將執行個體控制代碼儲存在全域變數中
   hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
   if (!hWnd)
   {
      return FALSE;
   }
   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);
   return TRUE;
}

在視窗處理函數中對ESC鍵進行處理:

switch (message)
{
case WM_KEYDOWN:
    switch(wParam)
    {
    case VK_ESCAPE:
        {
            HWND   hDesk;   
            RECT   rc;   
            hDesk   =   GetDesktopWindow();   
            GetWindowRect(   hDesk,   &rc   );   
            SetWindowLong(   hWnd,   GWL_STYLE,   WS_BORDER   );   
            SetWindowPos(   hWnd,   HWND_TOPMOST,   0,   0,   rc.right,   rc.bottom,   SWP_SHOWWINDOW);
        }
        break;
    }
return 0;
}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.