Screen Refresh with Windows and games
(DirectX 9, C++)
Hi !
I give the opportunity to the player to change the client size of the game (fixed predefined size, not the windows OS resize). Let's say, he has a screen of about 1440x900 pixel, he can play in a smaller "client" window of 800x600, 1024x768, etc. He choose the option in a menu.
It WORKS but the PROBLEM is that the old "bigger image" is not clear... or WINDOWS OS doesn't refresh the screen. If I RESIZE my game from 1024x768 to 800x600, I can play inside the 800x600 client window but I still see the "contour" of the old 1024x768 client.
Is there a way to say to WINDOWS to REFRESH all the screen ?
My code is like the following:
1- Change property of the client and the window
2- Destroy old scene, free memory
3- Resize
4- Create new scene
5- SetWindowPos
bool CGameEngine::ChangeWindowsSize( int NewWidth, int NewHeight )
{
// Windows
SetWindowLong( m_hWnd, GWL_style, m_dwWindowstyle );
// Resize window and put it on left-top corner. Player will then move
// the window where he wants.
m_WindowsWidth = NewWidth;
m_WindowsHeigth = NewHeight;
m_rcClient.left = 0;
m_rcClient.top = 0;
m_rcClient.right = m_rcClient.left + NewWidth;
m_rcClient.bottom = m_rcClient.top + NewHeight;
m_rcWindow.left = 0;
m_rcWindow.top = 0;
m_rcWindow.right = m_rcWindow.left + NewWidth;
m_rcWindow.bottom = m_rcWindow.top + NewHeight;
m_MiddleX = m_WindowsWidth / 2;
m_MiddleY = m_WindowsHeigth / 2;
// Destroy object in the old scene.
switch ( m_ActualScene )
{
case MAIN_MENU:
m_pSceneMainMenu->DestroyFinal();
SAFE_DELETE( m_pSceneMainMenu );
break;
// ... other scene
}
// Resize the screen like the user wants.
if( FAILED( m_pGraph3DEngine->Resize( m_WindowsWidth, m_WindowsHeigth )) )
{
return false;
}
else
{
switch ( m_ActualScene )
{
case MAIN_MENU:
m_pSceneMainMenu = new CSceneMainMenu( this );
m_pSceneMainMenu->SetRatioWindow( ( float)m_WindowsWidth/(float)m_WindowsHeigth );
m_pSceneMainMenu->Create();
break;
// ... other scene...
}
if( FAILED( SetWindowPos( m_hWnd, HWND_NOTOPMOST, 0, 0, NewWidth, NewHeight, SWP_SHOWWINDOW ) ) )
{
ErrorExit("SetWindowPos");
}
return true;
}
return false;
}
If the graphical bits left behind are definitley rubbish and you are allowing the system has enough CPU time for refreshing then InvalidateRect( GetDesktopWindow(), NULL ); may do the trick.
Been a while since I played with win32 and this is from memory so the function names may be slightly wrong given the win32 function nameing idiom.
Been a while since I played with win32 and this is from memory so the function names may be slightly wrong given the win32 function nameing idiom.
I think, in all fairness to Microsoft, that refreshing the screen is fairly fundamental to Windows and this might point to something that you're doing wrong.
Without knowing what your m_pGraph3DEngine->Resize function does it's hard to help out but resizing a window shouldn't leave any artefacts outside the window, unless you have another window 'underneath' the resized window that isn't getting repainted.
Maybe it's one for the DX experts if all else is correct.
Without knowing what your m_pGraph3DEngine->Resize function does it's hard to help out but resizing a window shouldn't leave any artefacts outside the window, unless you have another window 'underneath' the resized window that isn't getting repainted.
Maybe it's one for the DX experts if all else is correct.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement