I have a DirectX9 application that sporadically runs into a hang in WM_WINDOWPOSCHANGED. The hang occurs only rarely when alt+tabbing into and out of fullscreen exclusive mode.

The application is hung because the main window message processing thread is stuck at WaitForSingleObject() in the DefWindowProc handler. Other threads we have created are operating normally.

Call Stack on Stuck Main Thread:

 ntdll.dll!_NtWaitForSingleObject@12()  + 0x15 bytes    
 ntdll.dll!_NtWaitForSingleObject@12()  + 0x15 bytes    
 kernel32.dll!_WaitForSingleObjectExImplementation@12()  + 0x43 bytes   
 kernel32.dll!_WaitForSingleObject@8()  + 0x12 bytes    
 d3d9.dll!WindowProc()  + 0x27e95 bytes 
 user32.dll!_InternalCallWinProc@20()  + 0x23 bytes 
 user32.dll!_UserCallWinProcCheckWow@32()  + 0xb7 bytes 
 user32.dll!_DispatchClientMessage@24()  + 0x51 bytes   
 user32.dll!___fnDWORD@4()  + 0x2b bytes    
 ntdll.dll!_KiUserCallbackDispatcher@12()  + 0x2e bytes 
 user32.dll!_NtUserMessageCall@28()  + 0x15 bytes   
 user32.dll!_RealDefWindowProcWorker@24()  + 0x26afe bytes  
 user32.dll!_RealDefWindowProcW@16()  + 0x2a bytes  
 uxtheme.dll!_ThemeDefWindowProc()  + 0x152 bytes   
 uxtheme.dll!_ThemeDefWindowProcW@16()  + 0x18 bytes    
 user32.dll!_DefWindowProcW@16()  + 0x805 bytes 
> Player.exe!cnWindowProc(HWND__ * hWnd=0x006507f4, unsigned int message=0x00000047, unsigned int wParam=0x00000000, long lParam=0x0034eea8)  Line 502 + 0x18 bytes C++

I am wondering what Windows is waiting for here. DirectX is created and owned by a separate thread, but that thread is not stuck. We seem to be handling things correctly for lost devices (freeing up video memory resources and calling Reset()).

If anyone has ideas on why windows is hanging here, I would appreciate it.

asked on Stack Overflow Jan 17, 2013 by JustinB • edited Jan 18, 2013 by JustinB

1 Answer


Usually when I see this problem it is because SetWindowPos() needs to be called after setting the window style with a SetWindowLong() function. Changes will not be updated until SetWindowPos() is called, as detailed here:

It does not always seem to crash without calling SetWindowPos(), but will sometimes. I am not sure why the result is usually so sporadic. Either way the results will not update without that call.

answered on Stack Overflow Jan 17, 2013 by JayDoe

User contributions licensed under CC BY-SA 3.0