views:

121

answers:

3

How to well use the WinAPI to manage the fullscreen mode on windows's window ?

Here is my problem :

I have an application which has to be fullscreen. I use ChangeDisplaySettings() function (winuser.h) with the CDS_FULLSCREEN value to put my window to fullscreen mode when receiving a WM_ACTIVATE with (wParam == WA_ACTIVE || wParam == WA_CLICKACTIVE) :

DEVMODE dmScreenSettings;
memset (&dmScreenSettings, 0, sizeof (dmScreenSettings));
dmScreenSettings.dmSize = sizeof (dmScreenSettings);   
dmScreenSettings.dmPelsWidth = 1280;
dmScreenSettings.dmPelsHeight = 720;    
dmScreenSettings.dmBitsPerPel = 32;      
dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN);

I use the same function with the CDS_RESET value to put it back in "normal" mode when receiving a WM_ACTIVATE with (wParam == WA_INACTIVE) :

ChangeDisplaySettings(&dmScreenSettings, CDS_RESET);

When I first launch my application, it is in fullscreen. I use ALT+TAB to switch to another application on my computer. My application minimized itself. It works well. Then, I switch back to my application, and it comes up in fullscreen mode. Again, it works well. But if I want to switch back to another application one more time, my application statys in fullscreen mode, hiding all others applications on my computer.

NB : My window is created using CreateWindowEx() function with the following parameters :

DWORD dwExStyle = WS_EX_TOPMOST;
DWORD dwStyle = WS_VISIBLE | WS_POPUP;

1) Is there another way than using ChangeDisplaySettings() to change the fullscreen mode ?

2) Am I using it the good values ?

3) Is there anything to do that I forgot ?

Thanks in advance for all your answers. Best regards,

+1  A: 

These guys seem to cover all the options.

Win32: full-screen and hiding taskbar


New Edit: Based on a new comment, try this.

Trap the WM_ACTIVATE event in you app for that window. In that event call the GetWindowPlacement Function and hopefully you'll be on your way. Note the link to "SetWindowPlacement" at the bottom.

JustBoo
Thanks for the answer.It helps.I do not have the final solution but the link is useful.
Xavier V.
That is very helpful.I was already catching the WM_ACTIVATE but was not aware of GetWindowPlacement(). It is exactly what I need.Thanks a lot JustBoo, I think I will success to do what I want thanks to your help.It's really appreciated.
Xavier V.
A: 

Try it without WS_EX_TOPMOST.

Whenever you're activated, you'll become the foreground window automatically.

Adrian McCarthy
In my case, removing WS_EX_TOPMOST does not change anything. The second time I want to minimize it, the window still be on foreground fullscreen.
Xavier V.
A: 
  • If you are a Kiosk application, then the screen is already configured to the ideal / correct resolution.

  • If you are not a Kiosk application, then you have no business f***g with the users resolution. Instead: GetSystemMetrics to get the size of the default display, and create your borderless window exactly that large. The taskbar will automatically hide and your app will be "full screen".

Especially now that LCD panels are popular, the display resolution must match the panel resolution in order for sub pixel anti aliasing to work - ala ClearType. It is your applications responsibility to draw correctly at the display resolution, not the other way around.

Chris Becke
I am not in a Kiosk application and I already use GetSystemMetrics() to get the screen resolution in order to make my window fullscreen.And I have no problems with the taskbar. My problem is that the fullscreen window does not want to minimized when I switch of application for the second time.
Xavier V.