Dark Bit Factory & Gravity
PROGRAMMING => C / C++ /C# => Topic started by: Tetra on April 09, 2007
-
I noticed that creating a window with CreateWindowEx, the width and height you specify is infact the actual window width and height. That means that the actual drawing area is the width and height minus the title bar height and border of the application.
So i tired to measure the border and title bar and add it to the width and height, but it didnt work :(
Is there any way to make it so that the width and height you specify is the actual drawing area?
-
I'd never noticed that before, no idea.
-
You should look at the AdjustWindowRect (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowfunctions/adjustwindowrect.asp).
-
Thanx rdc
What I failed to realize before was the AdjustWindowRect.
originally this is how the window was created
RECT rect={0,0,width,height};
int style = WS_SYSMENU|WS_MINIMIZEBOX|WS_VISIBLE;
AdjustWindowRectEx(&rect, style, FALSE, WS_EX_TOPMOST);
window = CreateWindowEx(0, graphics_class, title, style, CW_USEDEFAULT, CW_USEDEFAULT, width, height, NULL, NULL, hInstance, 0);
which meant both client and window was thhe same size.
So to adjust it I had to add some numbers to the width and height in CreateWindowRectEx width and height variables. But this isnt ideal because everyone will no dought have different layouts for windows, i.e. windows classic vs windows xp.
RECT rect={0,0,width,height};
int style = WS_SYSMENU|WS_MINIMIZEBOX|WS_VISIBLE;
AdjustWindowRectEx(&rect, style, FALSE, WS_EX_TOPMOST);
window = CreateWindowEx(0, graphics_class, title, style, CW_USEDEFAULT, CW_USEDEFAULT, width + 6, height + 25, NULL, NULL, hInstance, 0);
Is there a way to set the width and height automatically based on the client rect specified by AdjustWindowRectEx?
-
I am not sure what you are asking here. AdjustWindowRect returns a window rect based on the desired client area. The returned rect is adjusted to accommodate the title bar, etc, but has the desired client area. You then pass the rect to CreateWindow.
Is this what you want or something else?
-
->Tetra, you don't want to be using hard coded constants like that. Every version of Windows is different with respect to caption size, border width, etc, and the user can change them in the desktop settings - eg, Large Fonts setting will ruin your program.
If you must do it this way, use the Windows API function GetSystemMetrics() to retrieve the offsets.
But much better to use AdjustWindowRect(), since that does exactly what you want.
Jim
-
RECT rect={0,0,width,height};
int style = WS_SYSMENU|WS_MINIMIZEBOX|WS_VISIBLE;
AdjustWindowRectEx(&rect, style, FALSE, WS_EX_TOPMOST);
window = CreateWindowEx(0, graphics_class, title, style, CW_USEDEFAULT, CW_USEDEFAULT, width + 6, height + 25, NULL, NULL, hInstance, 0);
should be
RECT rect={0,0,width,height};
int style = WS_SYSMENU|WS_MINIMIZEBOX|WS_VISIBLE;
int new_width, new_height;
AdjustWindowRectEx(&rect, style, FALSE, WS_EX_TOPMOST);
new_width = rect.right - rect.left;
new_height = rect.bottom - rect.top;
window = CreateWindowEx(0, graphics_class, title, style, CW_USEDEFAULT, CW_USEDEFAULT, new_width, new_height, NULL, NULL, hInstance, 0);
Jim
-
Ah cool, thanks Jim. Is it possible to make it go to fullscreen?
-
Sorry I pasted the wrong bit of code, thats what I was doing as its your framework pretty much i'm using.
it should have been :-
RECT rect={0,0,width,height};
int style = WS_SYSMENU|WS_MINIMIZEBOX|WS_VISIBLE;
AdjustWindowRectEx(&rect, style, FALSE, WS_EX_TOPMOST);
window = CreateWindowEx(0, graphics_class, title, style, CW_USEDEFAULT, CW_USEDEFAULT, rect.right-rect.left, rect.bottom-rect.top, NULL, NULL, hInstance, 0);
But that doesnt work :( the actual window is still only 640x480 including the title bar etc. The drawing area is infact 640x480, but its getting cut off, you can see it if you make the window resizable. I dont understand why it doesnt work :(
Heres a pic of an app running with that exact code, code downloadable too
-
Fullscreen mode is either - make a window as big as the desktop. WS_POPUP style, CM_XSCREEN, CM_YSCREEN for GetSystemMetrics,
or use the code to change the video mode to the size you want and use the same technique.
Jim
-
->Tetra - what does it say in the debugger in 'rect' after you called AdjustWindowRect?
Jim
<edit>
I think you're missing WS_CAPTION from the style.
-
rect {top=0 bottom=480 left=0 right=640} tagRECT
is that what your after? I dont quite understand. This is the value of rect after calling AdjustWindowRect.
I also checked to see if AdjustWindowRect was failing but it wasnt.
-
You're missing WS_CAPTION from the window style.
Jim
-
Here is some very old code ( dated in the year 2000 ) by me. Maybe it is useful. It
just creates a borderless window. Press Escape to quit (exe included).
//
// old code by benny!weltenkonstrukteur.de
//
// ** Includes (System) **************************************************************
#include <windows.h>
// ** Definitionen (System) **********************************************************
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
// ** Globals **************************************************************
static int cxClient, cyClient ; // Speichert die X-,Y-Größe von Windows
// ** WinMain (System) ***************************************************************
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("test") ;
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;
cxClient = GetSystemMetrics (SM_CXSCREEN) ; // get x resolution
cyClient = GetSystemMetrics (SM_CYSCREEN) ; // get y resolution
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))
{ // UNICODE
MessageBox (NULL, TEXT ("Error in Class Registration - Sorry !"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindow (szAppName, // name of windowclass
TEXT ("coming art production 2ooo"), // window title
WS_POPUPWINDOW , // window style
0, // x pos
0, // y pos
cxClient, // width
cyClient, // height
NULL, // parent window
NULL, // menu
hInstance, // program id
NULL) ; // additional param
ShowWindow (hwnd, SW_SHOWMAXIMIZED) ;
UpdateWindow (hwnd) ;
// Weird solution for Run-Time failure #3
memset( &msg, 0, sizeof(msg) );
while (msg.message != WM_QUIT)
{
if(PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
{
if(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
return 0;
}
// ** WndProc (System) ***************************************************************
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
return 0 ;
case WM_DESTROY:
case WM_CLOSE:
case WM_QUIT:
PostQuitMessage(0) ;
return 0 ;
break;
case WM_KEYDOWN:
PostMessage(hwnd, WM_DESTROY, 0, 0) ;
break;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
-
Thanks Jim :) that sorted it :updance: I wish I understood all thats going on better, I'm learning bit by bit :)
Thanks Benny :) thats will be usefull for making fullscreen stuff i'm sure.
-
This stuff's all in my pumpkin code...however I realise the documentation in there is slim...:P
Jim