views:

262

answers:

4

How can I make a true full screen mode in VC++?

Code:

#include <windows.h>
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PSTR szCmdLine, int iCmdShow)
{
     static TCHAR szAppName[] = TEXT ("screen") ;
     HWND         hwnd ;
     MSG          msg ;
     WNDCLASS     wndclass ;

     wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
     wndclass.lpfnWndProc   = WndProc ;
     wndclass.cbClsExtra    = 0 ;
     wndclass.cbWndExtra    = 0 ;
     wndclass.hInstance     = hInstance ;
     wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION);
     wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
     wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
     wndclass.lpszMenuName  = NULL ;
     wndclass.lpszClassName = szAppName ;

     if (!RegisterClass (&wndclass))
     {
          MessageBox (NULL, TEXT ("Program requires Windows NT!"), 
                      szAppName, MB_ICONERROR) ;
          return 0 ;
     }

     hwnd = CreateWindow (szAppName, TEXT ("Digital Clock"),
                          WS_POPUP|WS_DLGFRAME|WS_VISIBLE, // _OVERLAPPEDWINDOW| WS_MAXIMIZE,
                          CW_USEDEFAULT, CW_USEDEFAULT,
                          CW_USEDEFAULT, CW_USEDEFAULT,
                          NULL, NULL, hInstance, NULL) ;

     ShowWindow (hwnd, SW_MAXIMIZE);// iCmdShow) ;
     UpdateWindow (hwnd) ;

     while (GetMessage (&msg, NULL, 0, 0))
          {
          TranslateMessage (&msg) ;
          DispatchMessage (&msg) ;
          }
     return msg.wParam ;
     }
+1  A: 

Games usually use DirectX which has a mode that takes exclusive use of the video output - this means no other window (or task bar) can draw to the screen and the whole screen is available to the application at whatever resolution and colour depth you want (well almost, whatever the video card supports).

Skizz

Skizz
+1  A: 

Does

SetWindowPos( hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );

not put it on top of the taskbar?

Goz
But it doesn't stop other windows from doing the same thing and appearing on top of your window.
Skizz
Its true ... but seeing as DirectX isn't designed for windowing there are LOTS of drivers that will fail miserably if you try and draw windows over the full-screen mode. Its worth a go though ... ill give ya that.
Goz
DirectX can be happily used in a window. Also, if you get exclusive access to the primary surface then no other window/application can draw to the screen.
Skizz
+1  A: 

Check out this function and look at the definition of WS_EX_TOPMOST...

Malkocoglu
The problem with this is what happens if there's more than one window with the WS_EX_TOPMOST style, then which one is really the top most?
Skizz
You mean 2 or more full-screen video-players or games. I do not know about that but this is not an ordinary window style and is not very common. For example, when you change the screen resolution and press apply, Windows creates this type of window and paints it black, changes the screen resolution and then closes it so we do not see any screen garbage during this operation. Other programs that use this are the video-players and they set this flag when you want them in full-screen. I also have used this style for a video-player that I wrote. You may safely ignore your assumption in real world.
Malkocoglu
I'm sure those notification balloons that pop up are always on top, as are the MS messenger prompts - but I've not tested that. Also, are you sure about the black window when changing video modes? Do you have a reference for that? My monitor goes black whenever the screen mode changes - even during boot up when changing from text mode bios to low res loading screen to high res welcome screen, on non-window OSes and even when the mode is changed without using the display properties dialog.
Skizz
The youtube video player, when played in full screen mode, jumps out of full screen mode whenever I try to access another window - even just clicking on the other window drops the player out of full screen mode (two monitors, full screen video on one, apps on the other).
Skizz
I accidentally have observed it (black window during resolution change) while I was debugging my video player. Flash plugin also uses CreateWindowExA function but it does not relate itself to a window station. Maybe that's why, whenever other program gets focus, it quits the full-screen mode.WS_EX_TOPMOST flag puts the window top most whenever it has the focus. My application was catching the focus programmatically every 5 seconds by this...#ifdef _DEBUG ShowCursor(TRUE);#else ShowCursor(FALSE); SetActiveWindow(pi_win); BringWindowToTop(pi_win); SetForegroundWindow(pi_win);#endif
Malkocoglu
+1  A: 

See http://stackoverflow.com/questions/812686/can-a-window-be-always-on-top-of-just-one-other-window

In case of multiple window set to AlwaysOnTop; than only that window will remain on top that has been manually brought on top. For instance there are two windows Window1 and Window2; then when you would run window1.exe, it would be the window on top; and when you would run window2.exe then that window would be on top, thats the default behavior.

Otherwise if you must not allow any other window to get on top, you will have to look for other apps being invoked after yours, and then probably hook those windows somehow and, well probably call its Minimize event to send it to the task bar.

KMan