Xref: utzoo comp.windows.ms:7040 comp.windows.ms.programmer:109 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!sdd.hp.com!elroy.jpl.nasa.gov!ncar!gatech!mcnc!rti!bcw From: bcw@rti.rti.org (Bruce Wright) Newsgroups: comp.windows.ms,comp.windows.ms.programmer Subject: Re: Creating windows with a specified client size Summary: Creating windows Message-ID: <1990Nov8.180215.10952@rti.rti.org> Date: 8 Nov 90 18:02:15 GMT References: <18647@haddock.ima.isc.com> Followup-To: comp.windows.ms.programmer Organization: Research Triangle Institute, RTP, NC Lines: 46 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