Author Topic: window width/height vs dawing area width/height  (Read 9029 times)

0 Members and 1 Guest are viewing this topic.

Offline Tetra

  • DBF Aficionado
  • ******
  • Posts: 2532
  • Karma: 83
  • Pirate Monkey!
    • View Profile
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?
Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: window width/height vs dawing area width/height
« Reply #1 on: April 09, 2007 »
I'd never noticed that before, no idea.

Offline rdc

  • Pentium
  • *****
  • Posts: 1495
  • Karma: 140
  • Yes, it is me.
    • View Profile
    • Clark Productions
Re: window width/height vs dawing area width/height
« Reply #2 on: April 09, 2007 »
You should look at the AdjustWindowRect.

Offline Tetra

  • DBF Aficionado
  • ******
  • Posts: 2532
  • Karma: 83
  • Pirate Monkey!
    • View Profile
Re: window width/height vs dawing area width/height
« Reply #3 on: April 09, 2007 »
Thanx rdc

What I failed to realize before was the AdjustWindowRect.

originally this is how the window was created

Code: [Select]
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.

Code: [Select]
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?
Challenge Trophies Won:

Offline rdc

  • Pentium
  • *****
  • Posts: 1495
  • Karma: 140
  • Yes, it is me.
    • View Profile
    • Clark Productions
Re: window width/height vs dawing area width/height
« Reply #4 on: April 09, 2007 »
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?

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: window width/height vs dawing area width/height
« Reply #5 on: April 09, 2007 »
->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
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: window width/height vs dawing area width/height
« Reply #6 on: April 10, 2007 »
Quote
Code: [Select]
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

Code: [Select]
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
Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: window width/height vs dawing area width/height
« Reply #7 on: April 10, 2007 »
Ah cool, thanks Jim. Is it possible to make it go to fullscreen?

Offline Tetra

  • DBF Aficionado
  • ******
  • Posts: 2532
  • Karma: 83
  • Pirate Monkey!
    • View Profile
Re: window width/height vs dawing area width/height
« Reply #8 on: April 10, 2007 »
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 :-
Code: [Select]

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
« Last Edit: April 10, 2007 by Tetra »
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: window width/height vs dawing area width/height
« Reply #9 on: April 10, 2007 »
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
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: window width/height vs dawing area width/height
« Reply #10 on: April 10, 2007 »
->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.
« Last Edit: April 10, 2007 by Jim »
Challenge Trophies Won:

Offline Tetra

  • DBF Aficionado
  • ******
  • Posts: 2532
  • Karma: 83
  • Pirate Monkey!
    • View Profile
Re: window width/height vs dawing area width/height
« Reply #11 on: April 10, 2007 »
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.
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: window width/height vs dawing area width/height
« Reply #12 on: April 10, 2007 »
You're missing WS_CAPTION from the window style.

Jim
Challenge Trophies Won:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: window width/height vs dawing area width/height
« Reply #13 on: April 10, 2007 »
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).

Code: [Select]
//
// 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) ;
}

[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline Tetra

  • DBF Aficionado
  • ******
  • Posts: 2532
  • Karma: 83
  • Pirate Monkey!
    • View Profile
Re: window width/height vs dawing area width/height
« Reply #14 on: April 10, 2007 »
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.
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: window width/height vs dawing area width/height
« Reply #15 on: April 10, 2007 »
This stuff's all in my pumpkin code...however I realise the documentation in there is slim...:P

Jim
Challenge Trophies Won: