Sign in to follow this  
Turold

Frustrating Win32 Problem

Recommended Posts

Turold    134
My game optionally runs in a windowed mode. If user changes desktop res while the game is running I capture WM_DISPLAYCHANGE and do D3D reset to decrease game res if needed, in order to fit window on screen. It works fine if my window is NOT MINIMIZED while I start trying to do reset. If the window is minimized, when I restore it, it covers whole screen. Example 1 : I start the game at 1024x768. I DON'T minimize window. I change desktop res to 800x600. This causes the game to do reset D3D and switch to 640x480, to fit on desktop. Window behaves correctly. Example 2 : I start the game at 1024x768. I MINIMIZE window, so it's iconic and does not have focus. I change desktop res to 800x600. This causes the game to do reset and switch to 640x480, to fit on desktop. When I click on taskbar to restore window, it comes covering whole screen, and client area look like it's 800x600. I want it to get restored with client size of 640x480. Why is window size incorrect? If in this situation I immediately switch to fullscreen and back to desktop, everything works like expected and the window has correct size. The culprit seems to be the fact that I initiate reset while iconic and out of focus. Is there a way to do it without restoring window before launching reset?

Share this post


Link to post
Share on other sites
MJP    19786
Quote:
Original post by Turold
The culprit seems to be the fact that I initiate reset while iconic and out of focus. Is there a way to do it without restoring window before launching reset?


Not that I know of. I think your best bet is simply to defer the reset and window sizing until the user restores the window.

Share this post


Link to post
Share on other sites
SiCrane    11839
Well, obviously, the problem is that you're using the function ResizeThisWindowOnlyIfItIsntMinimized() to resize your window. Solution: don't use the function ResizeThisWindowOnlyIfItIsntMinimized() to resize your window.

If that isn't your actual problem then you might want to post code for what you are doing.

Share this post


Link to post
Share on other sites
Turold    134
To resize window after reset I use this:

Window style:


static DWORD m_pmfWindowStyle=WS_SYSMENU|WS_CAPTION|WS_MAXIMIZEBOX|WS_MINIMIZEBOX|WS_VISIBLE;

if (m_pmfVideoSettings.windowMode==PMF_WINDOWMODE_FULLSCREEN)
SetWindowLong(g_pmfMainWindow, GWL_STYLE, WS_POPUP|WS_SYSMENU|WS_VISIBLE);
else
SetWindowLong(g_pmfMainWindow, GWL_STYLE, m_pmfWindowStyle);




Sizing:


m_pmfClientRect.left=0;
m_pmfClientRect.top=0;
m_pmfClientRect.right=(LONG)PMF_XRES;
m_pmfClientRect.bottom=(LONG)PMF_YRES;
if
( AdjustWindowRectEx
( &m_pmfClientRect,
GetWindowLong(g_pmfMainWindow, GWL_STYLE),
false,
GetWindowLong(g_pmfMainWindow, GWL_EXSTYLE)
)==0
)
{ PMF_Report(PMF_LOGTAG_ERROR, "Setting window size failed!\n");
PMF_REPORT_WIN32_ERROR
}




There are no error reports. I have a suspicion that maybe DX is doing something with the window.

Share this post


Link to post
Share on other sites
SiCrane    11839
AdjustWindowRectEx() doesn't actually change the size of a window. It only calculates what the size should be.

Share this post


Link to post
Share on other sites
Turold    134
AHHHHH YEEEESSS!!!!! I wrote that code a while ago. I forgot what it does in reality, so now I just saw identifiers, not real operations. I completely overlooked my SetWindowPos, since I forgot that it does much more that just setting the pos ^_^. The culprit here was SWP_SHOWWINDOW flag.

Quote from MSDN:

"Remarks

If the SWP_SHOWWINDOW or SWP_HIDEWINDOW flag is set, the window cannot be moved or sized."

THIS caused the problem. I switched to SWP_NOZORDER and now upon restore I call my SetupWindow and it works like a charm.

I love YOU guys! :D


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this