[comp.windows.ms] Creating windows with a specified client size

andya@haddock.ima.isc.com (Andy Adler) (10/27/90)

Is there a way to create a window by specifying the window's
client area?  Is there a way to query windows about the
size of the decorations it will add to a window?  I want to 
be able to create a window and know what the client area will
be before showing it.

aa

press@venice.SEDD.TRW.COM (Barry Press) (10/27/90)

In article <18647@haddock.ima.isc.com> andya@haddock.ima.isc.com (Andy Adler) writes:
>Is there a way to create a window by specifying the window's
>client area?  Is there a way to query windows about the
>size of the decorations it will add to a window?  I want to 
>be able to create a window and know what the client area will
>be before showing it.

What you need to do is to look at the functions AdjustWindowRect and 
AdjustWindowRectEx.  They do what you're looking for -- you start with
a rectangle that is what the client area should be, and they change it to
reflect the entire window based on the styles you will use.

As a side note, I've had some issues of AdjustWindowRect not including the 
space needed for scroll bars, but kludged around it rather than crawling
through a bunch of code via the debugger.


-- 
Barry Press                                 Internet: press@venice.sedd.trw.com

gyugyi@portia.Stanford.EDU (Paul Gyugyi) (10/27/90)

In article <18647@haddock.ima.isc.com> andya@haddock.ima.isc.com (Andy Adler) writes:
>Is there a way to create a window by specifying the window's
>client area?  Is there a way to query windows about the
>size of the decorations it will add to a window?  I want to 
>be able to create a window and know what the client area will
>be before showing it.
>
>aa

If there is a better way to do this, I'd like to know about it.
The following worked for me in Actor:
1) Set the size of the window to what you want the client size to be.
2) Get the client size of the window
3) Subtract the difference, and set the size of the window to a bigger size.
4) show the window.

The above are simple Actor calls.  I imagine that they have simple SDK
versions.

Paul Gyugyi
gyugyi@rascals.stanford.edu

bcw@rti.rti.org (Bruce Wright) (11/09/90)

In article <18647@haddock.ima.isc.com>, andya@haddock.ima.isc.com (Andy Adler) writes:
> Is there a way to create a window by specifying the window's
> client area?  Is there a way to query windows about the
> size of the decorations it will add to a window?  I want to 
> be able to create a window and know what the client area will
> be before showing it.

It depends on what toolbox you are using.  It's quite possible to
create a window and specify a specific size and placement - those
are parameters to the CreateWindow function call in the Microsoft
SDK.  The problem is that these parameters are given in terms of
the total window size, including the title bar, menu bar, border,
scroll bars, etc.  What you have to do is to call the GetSystemMetrics
function to find the size(s) of the other object(s) created with
the window (depending on what type of window it is), and add their
sizes to the size of the client area that you want to create.

You can also use SetWindowPos to set the position and size of
a window that has already been created.

Note that the dimensions of both the sizes reported by the
GetSystemMetrics function and the sizes/coordinates required by
the CreateWindow function are in screen coordinates (pixels), which
are not necessarily the same dimensions that you will want to use
when drawing on the client area.  You may find that MM_LOENGLISH
(for example) is a better mapping mode for what you want to paint
in the client area;  then you would have to use the DPtoLP and
LPtoDP functions to convert between the different mapping modes
to get the "size of the created window"/"size of the window to be
created" (depending on exactly what you're trying to do).  

You do run into a minor problem when you are trying to create a 
window with a specific size in (say) inches rather than pixels:  
the LPtoDP function requires a Device Context (which you can't get
until you create the window).  In that case you either have to
make the computation manually from information returned by
GetSystemMetrics and GetDeviceCaps, or use SetWindowPos after the 
window has been created (presumably without being displayed) and 
you have called LPtoDP, or play games such as getting the desktop 
window with GetDesktopWindow and using it for a Device Context.  
You may find the MulDiv routine useful for some of this, since it 
eliminates the need for somewhat elaborate coercions to avoid 
overflow.  To my mind, all of these are ugly in varying degrees, 
but I may be missing a clever way to do this.

						Bruce C. Wright