CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Threaded View

  1. #2
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,244

    Re: How to make a full screen window

    If you want full-screen functionality as implemented in most applications, that's it: in full screen-view you have to remove caption as well as the menu bar.
    Here is a brief example how to toggle between normal and full-screen view:
    Code:
    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
       int wmId, wmEvent;
       // ...
       switch (message)
       {
       case WM_COMMAND:
          wmId = LOWORD(wParam);
          wmEvent = HIWORD(wParam);
          // Parse the menu selections:
          switch (wmId)
          {
          case ID_VIEW_FULLSCREEN: // toggle full screen
             if(g_bFullScreen)
                _ViewNormal(hWnd); 
             else
                _ViewFullScreen(hWnd);
             break;
             //...
          //...
       //...
    Code:
    void _ViewFullScreen(HWND hWnd)
    {
       // keep in mind normal window rectangle
       ::GetWindowRect(hWnd, &g_rcNormal);
    
       // remove caption and border styles
       DWORD dwOldStyle = ::GetWindowLong(hWnd, GWL_STYLE);
       DWORD dwNewStyle = dwOldStyle & ~(WS_CAPTION | WS_THICKFRAME);
       ::SetWindowLong(hWnd, GWL_STYLE, dwNewStyle);
    
       // remove the menu bar
       ::SetMenu(hWnd, NULL);
    
       // resize to full screen view
       // NOTE: use SWP_FRAMECHANGED to force redraw non-client
       const int x = 0;
       const int y = 0;
       const int cx = ::GetSystemMetrics(SM_CXSCREEN);
       const int cy = ::GetSystemMetrics(SM_CYSCREEN); 
       ::SetWindowPos(hWnd, HWND_TOPMOST, x, y, cx, cy, SWP_FRAMECHANGED);
    
       // set full screen indicator
       g_bFullScreen = TRUE;
    }
    Code:
    void _ViewNormal(HWND hWnd)
    {
       // put caption and border styles back
       DWORD dwOldStyle = ::GetWindowLong(hWnd, GWL_STYLE);
       DWORD dwNewStyle = dwOldStyle | WS_CAPTION | WS_THICKFRAME;
       ::SetWindowLong(hWnd, GWL_STYLE, dwNewStyle);
    
       // put back the menu bar
       ::SetMenu(hWnd, g_hMenu);
    
       // resize to normal view
       // NOTE: use SWP_FRAMECHANGED to force redraw non-client
       const int x = g_rcNormal.left;
       const int y = g_rcNormal.top;
       const int cx = g_rcNormal.right - g_rcNormal.left;
       const int cy = g_rcNormal.bottom - g_rcNormal.top; 
       ::SetWindowPos(hWnd, HWND_NOTOPMOST, x, y, cx, cy, SWP_FRAMECHANGED);
    
       // reset full screen indicator
       g_bFullScreen = FALSE;
    }
    Further, to keep some functionality provided by the menu or the title bar buttons when in full-screen view mode, you can use accelerators and/or context menus.

    I have attached here a simple demo application.
    Attached Files Attached Files
    Last edited by ovidiucucu; October 13th, 2012 at 04:08 AM.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured