Directx Alt-Tab Not Restoring Desktop in Native Resoultion

Posted on 2009-02-12
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

Question by:LordWolfy
    1 Comment
    LVL 2

    Accepted Solution

    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


    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    Artificial Intelligence comes in many forms, and for game developers, Path-Finding is an important ability for making an NPC (Non-Playable Character) maneuver through terrain.  A* is a particularly easy way to approach it.  I’ll start with the algor…
    Recently, in one of the tech-blogs I usually read, I saw a post about the best-selling video games through history. The first place in the list is for the classic, extremely addictive Tetris. Well, a long time ago, in a galaxy far far away, I was…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now