How to create specific window size? (CreateWindow)

Blitz3D Forums/Blitz3D Userlibs/How to create specific window size? (CreateWindow)

RustyKristi(Posted 2016) [#1]
Using window commands like in blitzplus aka WinBlitz3D, when setting up createwindow with a specific size say 640x480, it is somehow cutoff and adding the window as part of the resolution/window size.

How do you calculate the window size inside to reflect 640x480?

Related issue pointing to AdjustWindowRect:
http://stackoverflow.com/questions/4843806/winapi-create-a-window-with-a-specified-client-area-size


jfk EO-11110(Posted 2016) [#2]
There are certain Systemmetrics that reveal the thickness of the border and titlebar, but I prefer a cheap trick: by moving the window to 0,0 on the desktop, then call GetWindowRect to retrieve the desktop position of the inner window, which is not 0,0.
This way I find the users individual border and titlebar size in Blitz3D. Of course, doing this with the hidden window during app init.

Ince you know this, add it to your 640*480 to get an inner window of the desired size. That is w + border*2, h+ border+ titlebar.


BlitzSupport(Posted 2016) [#3]
No need to fiddle with OS calls, in BlitzPlus, anyway -- see CreateWindow 'flags' docs:


...

32 - The window shape is in 'client coordinates'



This actually refers to what Windows calls the 'client area', or inner area, of the window. Pass flag 32 in addition to the standard flags (15), or your own combination, and the overall size of the window will be calculated for you, based on the client area being 640 x 480 (or whatever):


flags = 15 + 32 ; 15 is default combination

window = CreateWindow ("Testing...", 400, 400, 640, 480, 0, flags)

Repeat

Until WaitEvent () = $803



You can then use ClientWidth/Height (window) to create canvases, etc.


BlitzSupport(Posted 2016) [#4]
Ah, you're trying to do this via the Windows API?

This looks to be how BlitzPlus sets the window size, indeed using AdjustWindowRect:

void Win32Window::setShape( int x,int y,int w,int h ){
	if( style()&32 ){
		if( _status ){
			RECT sb_rect;
			::GetWindowRect( _status,&sb_rect );
			h+=sb_rect.bottom-sb_rect.top;
		}
		RECT rect={x,y,x+w,y+h};
		int wstyle=GetWindowLong( _window.hwnd(),GWL_STYLE );
		bool menu=GetMenu( _window.hwnd() ) ? true : false;
		AdjustWindowRect( &rect,wstyle,menu );
		x=rect.left;
		y=rect.top;
		w=rect.right-rect.left;
		h=rect.bottom-rect.top;
	}
	_window.setShape(x,y,w,h);
	BBWindow::setShape(x,y,w,h); 
}


I remember asking for this specific feature early on, sending screenshots, etc! :D


RustyKristi(Posted 2016) [#5]
Thanks James and jfk! I kinda stopped what I'm working on here but will keep a note on these solutions.