home *** CD-ROM | disk | FTP | other *** search
/ Windoware / WINDOWARE_1_6.iso / source / wzun11sr / sizewndw.c < prev    next >
C/C++ Source or Header  |  1992-01-23  |  5KB  |  154 lines

  1. #include <windows.h>    /* required for all Windows applications */
  2. #include <assert.h>    /* required for all Windows applications */
  3. #include "wizunzip.h"                /* specific to this program              */
  4.  
  5. /* sizewndw.c module of WizUnzip.
  6.  * Author: Robert A. Heath
  7.  * I, Robert Heath, place this source code module in the public domain.
  8.  */
  9.  
  10. #define MIN_LISTBOX_LINES 2
  11.  
  12. /* Call this when the window size changes or needs to change.
  13.  */
  14. void SizeWindow(HWND hWnd, BOOL bOKtoMovehWnd)
  15. {
  16. WORD wListAreaWidth;            /* width list box and modifiers */
  17. WORD  wMinClientWidth;        /* minimum client width        */
  18. WORD  wButtonWidth;
  19. int        nListBoxHeight;            /* height of listbox in pix            */
  20. WORD    wVariableHeight;        /* no. variable pixels on client    */
  21. WORD    wVariableLines;            /* no. variable lines on client window */
  22. WORD    wMessageBoxHeight;        /* message box height in pixels        */
  23. int    nCxBorder = GetSystemMetrics(SM_CXBORDER);
  24. int    nCyBorder = GetSystemMetrics(SM_CYBORDER);
  25. int    nCxVscroll = GetSystemMetrics(SM_CXVSCROLL); /* vertical scroll width */
  26. int    nCyHscroll = GetSystemMetrics(SM_CYHSCROLL); /* vertical scroll width */
  27. int nCyCaption = GetSystemMetrics(SM_CYCAPTION); /* caption height        */
  28. int    nButtonsYpos;
  29. short xClient, yClient;         /* size of client area    */
  30. RECT WindowRect;                /* full window rectangle structure            */
  31. RECT ClientRect;                /* full window rectangle structure            */
  32.  
  33.         GetWindowRect(hWnd, &WindowRect);
  34.         GetClientRect(hWnd, &ClientRect);
  35.         xClient = ClientRect.right-ClientRect.left+1; /* x size of client area */
  36.         yClient = ClientRect.bottom-ClientRect.top+1; /* y size of client area */
  37.         if (bStatusMaxed)
  38.         {
  39.                     /* position the status window to fill entire client window     */
  40.             MoveWindow(hWndStatus, 
  41.                 0, 
  42.                 0,
  43.                 xClient,
  44.                 yClient, TRUE);
  45.                 MessageWinLines = yClient / ychar ;
  46.  
  47.         }
  48.         else    /* else status window is its normal size            */
  49.         {
  50.         /* List Box gets roughly 1/2 of lines left over on client
  51.          * window after subtracting fixed overhead for borders,
  52.          * horizontal scroll bar,
  53.          * button margin spacing, header, and trailer lines.
  54.          */
  55.         wVariableHeight =  yClient - (4 * nCyBorder) - (7 * ychar) - 
  56.                             nCyHscroll - nCyCaption;
  57.         wVariableLines = wVariableHeight / ychar;
  58.         ListBoxLines =  wVariableLines / 2 ; 
  59.  
  60.         if (ListBoxLines < MIN_LISTBOX_LINES)
  61.             ListBoxLines = MIN_LISTBOX_LINES;
  62.  
  63.         MessageWinLines = wVariableLines - ListBoxLines; /* vis. msg. wnd lines */
  64.  
  65.         wListAreaWidth = 
  66.            (!wFormat ? MIN_SHORT_FORMAT_CHARS : MIN_LONG_FORMAT_CHARS) * xchar +
  67.                           nCxVscroll + 2 * nCxBorder;
  68.         wMinClientWidth = wListAreaWidth;
  69.         /* if we moved the hWnd from WM_SIZE, we'd probably get into
  70.          * a nasty, tight loop since this generates a WM_SIZE.
  71.          */
  72.         if (bOKtoMovehWnd && xClient < wMinClientWidth)
  73.         {
  74.             xClient = wMinClientWidth;
  75.             MoveWindow(hWnd, WindowRect.left, WindowRect.top, xClient + 2*GetSystemMetrics(SM_CXFRAME), yClient, TRUE);
  76.         }
  77.         /* divide buttons up into 4 equal zones each button separated by
  78.          * a 1-character buffer.
  79.          */
  80.         wButtonWidth = (xClient - 5 * xchar)/4 ; /* width of button itself */
  81.  
  82.         MoveWindow(hWndHeaderLine1, 
  83.                 nCxBorder, 0,
  84.                 xClient,
  85.                 ychar, TRUE);
  86.  
  87.         MoveWindow(hWndHeaderLine2, 
  88.                 nCxBorder, ychar,
  89.                 xClient,
  90.                 ychar, TRUE);
  91.  
  92.         nListBoxHeight = ListBoxLines * ychar + 2 * nCyBorder;
  93.         MoveWindow(hWndList,         
  94.                 0, 2*ychar ,
  95.                 xClient,
  96.                 nListBoxHeight,
  97.                 TRUE);
  98.  
  99.  
  100.         MoveWindow(hWndTotalLine1, 
  101.                 nCxBorder, 
  102.                 ((ListBoxLines+2) * ychar + (2 * nCyBorder)),
  103.                 xClient,
  104.                 ychar, TRUE);
  105.  
  106.         MoveWindow(hWndTotalLine2, 
  107.                 nCxBorder, ((ListBoxLines+3) * ychar + (2 * nCyBorder)),
  108.                 xClient,
  109.                 ychar, TRUE);
  110.  
  111.         nButtonsYpos = ListBoxLines * ychar + 
  112.                         9 * ychar / 2 + (2 * nCyBorder);
  113.  
  114.         /* position the 4 buttons                                */
  115.         MoveWindow(hExtract, 
  116.                 xchar,      
  117.                 nButtonsYpos,
  118.                 wButtonWidth ,   2 * ychar,
  119.                 TRUE);
  120.  
  121.         MoveWindow(hDisplay,
  122.                 wButtonWidth+ (2 * xchar),      
  123.                     nButtonsYpos,
  124.                     wButtonWidth ,   2 * ychar,
  125.                 TRUE);
  126.  
  127.         MoveWindow(hTest,
  128.                 2*(wButtonWidth+xchar)+xchar,      
  129.                     nButtonsYpos,
  130.                     wButtonWidth ,   2 * ychar,
  131.                 TRUE);
  132.  
  133.         MoveWindow(hShowComment,
  134.                 3*(wButtonWidth+xchar)+xchar,      
  135.                     nButtonsYpos,
  136.                     wButtonWidth ,   2 * ychar,
  137.                 TRUE);
  138.  
  139.  
  140.         /* Position the status (Message) window.
  141.          * The Message windows is positioned relative to the bottom
  142.          * of the client area rather than relative to the top of the client.
  143.          */
  144.         wMessageBoxHeight = wVariableHeight - nListBoxHeight + 
  145.                             2 * nCyBorder + 
  146.                             nCyHscroll + nCyCaption ;
  147.  
  148.         MoveWindow(hWndStatus, 
  149.                 0, yClient - wMessageBoxHeight,
  150.                 xClient,
  151.                 wMessageBoxHeight, TRUE);
  152.         } /* bottom of status window is normal size            */
  153. }
  154.