We help IT Professionals succeed at work.

Directx Alt-Tab Not Restoring Desktop in Native Resoultion

LordWolfy asked
Medium Priority
Last Modified: 2013-12-26

I have a directx game app which runs perfectly in any resolution, full screen or windowed and has no problems with alt-tab except when using full screen with the same resolution as the desktop.

In this case, the desktop or app being switched to is not displayed.  The screen dosent get updated at all except for the mouse pointer which appears normal for whatever's supposed to be there (ie. will react to window controls such as text, links etc).  All input appears to work correctly and the app can even be alt-tabbed back into again and continue.

If the resolution is different from that of the desktop then everthing works perfectly.
I'm using a standard message loop.  Here is an extract of the relevant code  (it's in Delphi but I'm sure the structure will be plain enough to see).  Some code and variables have been stripped out to make it more readable:
Function WindowProc (AHWnd, AMsg, AWParam, ALParam : Integer) : Integer; StdCall;
     If AMsg = WM_DESTROY Then
        PostQuitMessage (0);
     If AMsg = WM_ACTIVATEAPP Then
          WindowActive := (AWParam <> 0);
     Result := DefWindowProc (AHWnd, AMsg, AWParam, ALParam);
Function CreateMainWindow (HInst : HWnd) : HWnd;
   WinHandle : HWnd;
   WinWidth, WinHeight : LongInt;
     WinClass.lpszClassName:= 'MainWindow';
     WinClass.lpfnWndProc := @WindowProc;
     WinClass.hInstance := HInst;
     WinClass.hbrBackground:= 8;
     WinClass.hIcon := LoadIcon (HInst, 'MAINICON');
     WinClass.hCursor := LoadCursor (0, IDC_ARROW);
     WinWidth := WW_EngineSettings.DisplayWidth + 6;
     WinHeight := WW_EngineSettings.DisplayHeight + 25;
     WinHandle := CreateWindow (WinClass.lpszClassName,'Main Window',
                                       (WS_OVERLAPPED Or WS_CAPTION Or WS_SYSMENU Or WS_VISIBLE),
                                       0, 0, WinWidth, WinHeight, 0, 0, HInst, NIL);
     Result := WinHandle;
     MainWindowHandle := CreateMainWindow (hInstance);
     If MainWindowHandle = 0 Then
     If Not (WW_EngineSettings.DisplayWindowed) Then
        ShowCursor (False);
     PeekMessage (WinMsg, 0, 0, 0, PM_NOREMOVE);
     While WinMsg.Message <> WM_QUIT Do
          If PeekMessage (WinMsg, 0, 0, 0, PM_REMOVE) Then
               TranslateMessage (WinMsg);
               DispatchMessage (WinMsg);
          If WindowActive Then
             // App main called from here
          CurrentTime := timeGetTime;
     If Not (WW_EngineSettings.DisplayWindowed) Then
        ShowCursor (True);
     DestroyWindow (MainWindowHandle);

Open in new window

Watch Question

Found a solution : basically just to make sure windows resets the display settings when the app is deactivated.

Also - losing the WaitMessage call smoothes things out a bit with respect to that.
ChangeDisplaySettings (PDeviceMode (NIL)^, CDS_RESET);

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.