SAMPLE: Alternate MDI Tiling Scheme Code Sample Available

Last reviewed: February 15, 1996
Article ID: Q72135
The information in this article applies to:
  • Microsoft Windows Software Development Kit (SDK) for Windows versions 3.0 and 3.1

SUMMARY

The Microsoft Software Library contains the source code to a sample program, MDITILE, that demonstrates how to implement an alternate tiling scheme for the multiple document interface (MDI) of Windows version 3.0.

The alternate tiling scheme demonstrated in this sample attempts to tile MDI child windows so they are wider than they are tall. The default MDI tiling scheme sizes the child windows to be tall and narrow. This is unsuitable for MDI applications based on text such as a word processor.

Download MDITILE.EXE, a self-extracting file, from the Microsoft Software Library (MSL) on the following services:

  • Microsoft Download Service (MSDL)

          Dial (206) 936-6735 to connect to MSDL
          Download MDITILE.EXE (size: 29870 bytes) 
    
  • Internet (anonymous FTP)

          ftp ftp.microsoft.com
          Change to the \SOFTLIB\MSLFILES directory
          Get MDITILE.EXE (size: 29870 bytes) 
    

MORE INFORMATION

The horizontally based tiling scheme implemented in this sample uses the following eight-step procedure:

  1. Count the number of MDI child windows that are not iconic (represented by an icon). These are the only windows affected by tiling. This value is saved in "cKids."

  2. Find the next square (that is, a number "n," such that some integer "x" is the square root, x*x == n), that is greater than the number of windows to tile.

  3. Set a column value, "cCols," to "x-1," where "x" is the root of the square found in step 2.

  4. Set a row counter, "cRows," to "cKids / cCols."

  5. Set a remainder counter, "cMulRows," to "cKids % cCols." This accounts for the child windows that are not included in the base grid of cCols by cRows.

  6. Get the dimensions of the client rectangle in which tiling is to occur. Note that it may be desirable to reduce the size of this rectangle to leave space at the bottom of the MDI client window for a row of icons. Divide the vertical height of the rectangle by cRows to get the child window height, and divide the horizontal width of the rectangle by cCols to get the child window width.

  7. Loop through each row. In this row, the application will tile cCols child windows. The value "cRows-cMulRows" is the number of rows that can be created with cCols columns. If the rows that can have cCols columns have already been done, then increment cCols so that all remaining rows have an extra window. Since cMulRows are left to tile, adding one window to each row account for all remaining windows.

    This is also why cCols was initially "x-1." If "cCols==x," then the first rows (at the top of the window) would have more windows than rows on the bottom. If this tiling scheme is desired, set cCols to "x" as the assumed number of columns, then decrement cCols when cMulRows have been tiled.

  8. Once the number of columns has been calculated, loop through the columns, moving each window to the appropriate section of that row.

NOTE: It is preferable to move windows with BeginDeferWindowPos(), DeferWindowPos(), and EndDeferWindowPos(), instead of many calls to SetWindowPos(), because the visual effect of the window movement is much cleaner.


Additional reference words: 3.00 3.10 softlib MDITILE.EXE
KBCategory: kbprg kbfile
KBSubcategory: UsrMdi


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 15, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.