?
Solved

Directx Alt-Tab Not Restoring Desktop in Native Resoultion

Posted on 2009-02-12
1
Medium Priority
?
523 Views
Last Modified: 2013-12-26
Greetings,

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;
Begin
     If AMsg = WM_DESTROY Then
        PostQuitMessage (0);
     If AMsg = WM_ACTIVATEAPP Then
          WindowActive := (AWParam <> 0);
     Result := DefWindowProc (AHWnd, AMsg, AWParam, ALParam);
End;
 
Function CreateMainWindow (HInst : HWnd) : HWnd;
Var
   WinHandle : HWnd;
   WinWidth, WinHeight : LongInt;
Begin
     WinClass.lpszClassName:= 'MainWindow';
     WinClass.lpfnWndProc := @WindowProc;
     WinClass.hInstance := HInst;
     WinClass.hbrBackground:= 8;
     WinClass.hIcon := LoadIcon (HInst, 'MAINICON');
     WinClass.hCursor := LoadCursor (0, IDC_ARROW);
     RegisterClass(WinClass);
     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;
End;
 
Begin
     MainWindowHandle := CreateMainWindow (hInstance);
     If MainWindowHandle = 0 Then
        Exit;
     If Not (WW_EngineSettings.DisplayWindowed) Then
        ShowCursor (False);
     PeekMessage (WinMsg, 0, 0, 0, PM_NOREMOVE);
     While WinMsg.Message <> WM_QUIT Do
     Begin
          If PeekMessage (WinMsg, 0, 0, 0, PM_REMOVE) Then
          Begin
               TranslateMessage (WinMsg);
               DispatchMessage (WinMsg);
          End;
          If WindowActive Then
             // App main called from here
          Else
              WaitMessage;
          CurrentTime := timeGetTime;
     End;
     If Not (WW_EngineSettings.DisplayWindowed) Then
        ShowCursor (True);
     DestroyWindow (MainWindowHandle);
End.

Open in new window

0
Comment
Question by:LordWolfy
1 Comment
 
LVL 2

Accepted Solution

by:
LordWolfy earned 0 total points
ID: 23629605
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

0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month14 days, 5 hours left to enroll

809 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