• Advertisement
Sign in to follow this  

C++ Win32- Resizing after resolution change(with D2D)

This topic is 2201 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am using a game window that sizes to current screen resolution. I am also rendering graphics with the Direct2D API, which is dependent on the windows message pump WM_PAINT messages. I am fiddling around with changing desktop resolution (as a user might) and trying to get not only the window to resize correctly, but also getting the RenderTarget to resize correctly. Without getting too far in the weeds, my RenderTarget is not resizing correctly immediately after res change (I am resizing it with LPARAM from the WinProc). It seems to be a timing issue, because I can minimize then reactivate and the RenderTarget sizes correctly. It seems like the LPARAM from the WinProc isn't passing the correct client size on the resizes that happen immediately after res change. Does that make any sense?


LRESULT CALLBACK WindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
//Get window width and height
UINT width = LOWORD(lParam);
UINT height = HIWORD(lParam);

//Route the message
switch(message)
{
case WM_CREATE:
{
}break;

case WM_DISPLAYCHANGE:
{
InvalidateRect(hwnd, NULL, false);
//Entry into log
CTools::GameLogAdd(false,"WM_DISPLAYCHANGE");
}break;

case WM_SIZE:
{
//Resizes window and render target
if(pApp->IsInitComplete())
{
//Resize the window
pApp->GetD2DPtr()->OnResize(hwnd,width,height);
}//end if

if(SIZE_MINIMIZED == wParam)
{
}//end if

if(SIZE_MAXIMIZED == wParam)
{
}//end if
}break;

case WM_NCLBUTTONDOWN:
{
//Prevents user from moving window via title bar
if (HTCAPTION == wParam) return 0;
}break;

case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}break;

case WM_PAINT:
{
//Call Direct2D rendering routines
if(pApp->IsInitComplete())
{
pView->OnPaint();
ValidateRect(hwnd, NULL);
}//end if
}break;
case WM_KEYDOWN:
{
switch(wParam)
{
case VK_SPACE:
{

}break;
}//end switch
}break;

}//end switch

//Handle any remaining messages
return DefWindowProc (hwnd, message, wParam, lParam);
}




UINT CDirect2D::OnResize(HWND _hwnd,UINT _width,UINT _height)
{
//Check if window is able to be resized
if(!IsResizable())
return FAIL;

//Get current screen size
int width = GetSystemMetrics(SM_CXSCREEN);
int height = GetSystemMetrics(SM_CYSCREEN);

//Reset window position
MoveWindow(_hwnd,0,0,width,height, true);

//Resize the Direct2D render target
GetRenderTarget()->Resize(D2D1::SizeU(_width, _height));

//Entry into log
CTools::GameLogAdd(false,"D2D OnResize: Called");

return SUCCESS;
}

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement