Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Helpful routine: Center form on screen
#11
Quote:Also, have you any idea how to determine the size of non-client areas of a window? For example: a window set to 600 pixels tall in XP with styles is going to have a different client area size than the same window in Windows 98...that's a major issue right now.

Very weird. No kidding, but I was just trying to figure out that very same thing. I have an idea of how to do it, but it might be a little messy at first. (This is from being spoiled by Delphi which lets you do:
Code:
myform.clientwidth = 600
which requires some calc, set, check, and repeat kind of routine to accomplish in freeBASIC. (unless I'm really missing something simple in the API).
ature has its way of warning a person away from danger: The distinct black and white coloration on a skunk, the chilling buzz of a rattlesanke, a redneck handing you his beer and saying "Watch this!"
Reply
#12
use AdjustWindowRect
Reply
#13
Quote:use AdjustWindowRect

So I was missing something simple...
ature has its way of warning a person away from danger: The distinct black and white coloration on a skunk, the chilling buzz of a rattlesanke, a redneck handing you his beer and saying "Watch this!"
Reply
#14
Quote:I'm not the one who was asked but I can't keep myself shut... :wink:
Code:
BOOL GetClientRect(
    HWND hWnd,    // handle of window
    LPRECT lpRect     // address of structure for client coordinates
   );

hWnd:
Identifies the window whose client coordinates are to be retrieved.

lpRect:
Points to a RECT structure that receives the client coordinates. The left and top members are zero. The right and bottom members contain the width and height of the window.

Unfortunately, that only gets the client area (which we presumably already know since we set that, right? Wink )

What adosorken was asking, was the *none*-client area, ie: the borders and titlebar at the top. The "classic" windows non-client area adds 6 pixels width, 3 on each side (3+3=6 total) and 27 height, 24 at the top and 3 on the bottom (24+3=27 total).

But, Windows XP and non-classic skins (or using skinning programs like WindowsBlinds) are not those values always. XP adds a *lot* more to the width and height and a lot of skins for WindowsBlinds makes it a lot smaller.
Life is like a box of chocolates', hrm, WTF, no it isn't, more like, 'life is like a steaming pile of horse crap.'
Reply
#15
Well, based on the past few posts in this thread, I've found that it's AdjustWindowRectEx that I need to be using. AdjustWindowRect is meant to be used with CreateWindow, but since I use CreateWindowEx exclusively, I gotta use the Ex version of AdjustWindowRect. Thanks for the information, guys. Big Grin
I'd knock on wood, but my desk is particle board.
Reply
#16
Quote:What adosorken was asking, was the *none*-client area, ie: the borders and titlebar at the top. The "classic" windows non-client area adds 6 pixels width, 3 on each side (3+3=6 total) and 27 height, 24 at the top and 3 on the bottom (24+3=27 total).

Also the TOOLWINDOW class has a different height regarding the TITLEBAR.
Reply
#17
Hrm...AdjustWindowRectEx seems to fail as well. Oh well, I think I'll write a hackup using GetClientRect and SetWindowPos. Whatever works, right? Big Grin
I'd knock on wood, but my desk is particle board.
Reply
#18
Quote:Hrm...AdjustWindowRectEx seems to fail as well. Oh well, I think I'll write a hackup using GetClientRect and SetWindowPos. Whatever works, right? Big Grin

AdjustWindowRect should work with CreateWindowEx too because it does nothing with the window.
It's just a function to gather all the information needed (caption and border size) to get the window size.

It should work as follows (not tested):
Code:
dim rec as RECT ' needed client size - but only at the beginning.
                ' After using AdjustWindowRect it has the new RECT values for the main window
dim main_window_width as long
dim main_window_height as long

rec.left=0
rec.top=0
rec.right = 600
rec.bottom = 400

AdjustWindowRect(rec, Put_In_Your_Used_Window_Style ,0)  ' 0 = no Menu / 1 = Menu

main_window_width = rec.right
main_window_height = rec.bottom
now resize the window with the main_window_width and main_window_height values
(AdjustWindowRect writes the new values back into the RECT structure...)

If you have rec.left and rec.top to NON ZERO, than you have to subtract:
Code:
main_window_width = rec.right - rec.left
main_window_height = rec.bottom - rec.top
Reply
#19
Quote:Hrm...AdjustWindowRectEx seems to fail as well. Oh well, I think I'll write a hackup using GetClientRect and SetWindowPos. Whatever works, right? :D

I haven't had time to try it but I was working on something along the following lines:

GetClientRect to get the current client area.
GetWindowRect to get the current "total" window area.
Figure out how much X and Y need to be increased to get the client to the right size.
SetWindowPos to increase the "total" window size by the needed increase from the client calc.
ature has its way of warning a person away from danger: The distinct black and white coloration on a skunk, the chilling buzz of a rattlesanke, a redneck handing you his beer and saying "Watch this!"
Reply
#20
The following appears to work correctly in resizeing a form based on a requested client width and height:

Code:
'  needed defines that are not found in current .BI files
#define HWND_TOP  0
#define SWP_SHOWWINDOW &H40

sub ResizeClient( clientwidth as long, clientheight as long)
  dim clientrect as rect
  dim formrect as rect
  dim widthadjust as long
  dim heightadjust as long
  GetClientRect( hWnd, clientrect )
  GetWindowRect( hWnd, formrect )
  widthadjust = clientwidth - clientrect.nright
  heightadjust = clientheight - clientrect.nbottom
  SetWindowPos( hWnd, HWND_TOP, 0, 0, _
    formrect.nright + widthadjust, _
    formrect.nbottom + heightadjust, SWP_SHOWWINDOW )
end sub
ature has its way of warning a person away from danger: The distinct black and white coloration on a skunk, the chilling buzz of a rattlesanke, a redneck handing you his beer and saying "Watch this!"
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)