Skip to main content
GameDev.net gamedev.net
🔒 Locked

Window size

Started by startreky498 Apr 10, 2005 at 9:04 PM 3 replies 400+ views
Original Post
startreky498
startreky498
Say I create a window using the WS_OVERLAPPEDWINDOW | WS_VISIBLE flags. When I set the window size, it includes the titlebar and border. This is a problem, as the images I draw within that window are distorted. Is there a way to figure out how much I need to increase the window size to accomidate these things? Or is there some different flag that I can use to specify only the inside size? Keep in mind that this value is variable, since depending on operating system and user appearance settings the size of the title bar and borders can be different.
Aldenar
Aldenar
There is a way, the function you are looking for is AdjustWindowRect().
startreky498
startreky498
Thanks a lot, but how and when do I use this function?

I've tried, but it's produced no effect. Here's how I've tried:

[source code="cpp"]	WNDCLASSEX wcex;	wcex.cbSize        = sizeof(WNDCLASSEX);	wcex.style         = 0;	wcex.lpfnWndProc   = stWinProc;	wcex.cbClsExtra    = 0;	wcex.cbWndExtra    = 0;	wcex.hIcon         = LoadIcon(NULL, IDI_APPLICATION);	wcex.hCursor       = LoadCursor(NULL, IDC_ARROW);	wcex.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);	wcex.lpszMenuName  = NULL;	wcex.lpszClassName = m_ClassName;	wcex.hInstance     = *m_phInstance;	wcex.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);	RegisterClassEx(&wcex);	LPRECT rWindow = new RECT();	rWindow->left = mX;	rWindow->top = mY;	rWindow->right = mX + mWidth;	rWindow->bottom = mY + mHeight;	//AdjustWindowRect(RECT,dwStyle,bMenu)	AdjustWindowRect(rWindow, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);	m_hWnd = CreateWindowEx(WS_EX_CLIENTEDGE, m_ClassName, m_WindowTitle, WS_OVERLAPPEDWINDOW | WS_VISIBLE,		mX, mY, mWidth, mHeight, NULL, NULL, *m_phInstance, (void*)this);	if(!m_hWnd)		return false;	return true;


Anyone see what's wrong with this?
doynax
doynax
Quote:
Original post by startreky498
Thanks a lot, but how and when do I use this function?

I've tried, but it's produced no effect. Here's how I've tried:
You have to actually use the size returned in AdjustWindowRect's rectangle, not just pass the input width and height to CreateWindow.

RECT rWindow;rWindow.left = mX;rWindow.top = mY;rWindow.right = mWidth;rWindow.bottom = mHeight;AdjustWindowRect(&rWindow, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);mX = rWindow.left;mY = rWindow.top;mWidth = rWindow.right - rWindow.left;mHeight = rWindow.bottom - rWindow.top;m_hWnd = CreateWindowEx(..., mX, mY, mWidth, mHeight, ...);
startreky498
startreky498
ohhhhhhhhhh i get it! I was affecting only the rect and didn't pay attention to the variables! Thanks a lot!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.