home *** CD-ROM | disk | FTP | other *** search
/ Boston 2 / boston-2.iso / DOS / PROGRAM / C / MDIDEMO / MDIDEMO.C next >
C/C++ Source or Header  |  1993-12-01  |  22KB  |  672 lines

  1. /*--------------------------------------------------------
  2.    MDIDEMO.C -- Multiple Document Interface Demonstration
  3.                 (c) Charles Petzold, 1990
  4.  
  5.    Windows SDK V. 3.0
  6.    Microsoft C V. 6.0
  7.    Windows     V. 3.0
  8.  
  9.   --------------------------------------------------------*/
  10.  
  11. #if defined(_MEWEL_)
  12.     #include <stdlib.h>
  13.     #include <string.h>
  14.     #include "window.h"
  15.  
  16.     #undef   _CreateWindow
  17.     #define LOCALHANDLE                         VOID *
  18.     #define GLOBALHANDLE                        VOID *
  19.     #define GetWindowLOCALHANDLE                GetWindowPtr
  20.     #define SetWindowLOCALHANDLE                SetWindowPtr
  21.     #define GetWindowGLOBALHANDLE               GetWindowPtr
  22.     #define SetWindowGLOBALHANDLE               SetWindowPtr
  23.  
  24.     int PASCAL WinMain (HANDLE, HANDLE, LPSTR, int);
  25.  
  26.     // main
  27.     //
  28.     void main(int argc, char *argv[])
  29.     {
  30.         extern      USHORT _amblksiz;
  31.         register    int i;
  32.         char        achCmdLine[128];
  33.  
  34.         _amblksiz = 16;
  35.  
  36.         strcpy (achCmdLine, "");
  37.  
  38.         for (i=1 ; i<argc ; i++)
  39.         {
  40.             strcat (achCmdLine, argv[i]);
  41.         }
  42.  
  43.         WinInit();
  44.         WinUseSysColors(NULLHWND, TRUE);
  45.         MDIInitialize();
  46.  
  47.         exit (WinMain (0, 0, achCmdLine, SW_SHOW));
  48.     }
  49.  
  50.     // _CreateWindow
  51.     //
  52.     HWND  FAR PASCAL _CreateWindow(
  53.         LPSTR   lpClassName,
  54.         LPSTR   lpWindowName,
  55.         DWORD   dwStyle,
  56.         int     X,
  57.         int     Y,
  58.         int     nWidth,
  59.         int     nHeight,
  60.         HWND    hwndParent,
  61.         HMENU   hMenu,
  62.         HANDLE  hInstance,
  63.         LPSTR   lpParam
  64.         )
  65.     {
  66.         HMENU   hmenu;
  67.         USHORT  usChildID;
  68.         HWND    hwnd;
  69.  
  70.         if (dwStyle & WS_CHILD)
  71.         {
  72.             usChildID = (USHORT) hMenu;
  73.             hmenu = (HMENU) NULL;
  74.         }
  75.         else
  76.         {
  77.             usChildID = 0;
  78.             hmenu = hMenu;
  79.         }
  80.  
  81.         hwnd = CreateWindow(
  82.             lpClassName,                        // Window class name
  83.             lpWindowName,                       // Window caption
  84.             dwStyle,                            // Window style
  85.             X,                                  // Initial x position
  86.             Y,                                  // Initial y position
  87.             nWidth,                             // Initial x size
  88.             nHeight,                            // Initial y size
  89.             SYSTEM_COLOR,                       // Screen colors
  90.             (USHORT) usChildID,                 // Child ID
  91.             (HWND) hwndParent,                  // Parent window handle
  92.             (HMENU) hmenu,                      // Window menu handle
  93.             (HANDLE) hInstance,                 // Program instance handle
  94.             (LPSTR)lpParam                      // Create parameters
  95.             );
  96.  
  97.         return (hwnd);
  98.     }
  99. #else
  100.     #include <windows.h>
  101.     #define _CreateWindow                       CreateWindow
  102.     #define _DialogBox                          DialogBox
  103.     #define _TranslateAccelerator               TranslateAccelerator
  104.     #define GetWindowLOCALHANDLE                GetWindowWord
  105.     #define SetWindowLOCALHANDLE                SetWindowWord
  106.     #define GetWindowGLOBALHANDLE               GetWindowWord
  107.     #define SetWindowGLOBALHANDLE               SetWindowWord
  108. #endif
  109. #include <memory.h>
  110. #include <stdlib.h>
  111. #include "mdidemo.h"
  112.  
  113. long FAR PASCAL FrameWndProc  (HWND, WORD, WORD, LONG) ;
  114. BOOL FAR PASCAL CloseEnumProc (HWND, LONG) ;
  115. long FAR PASCAL HelloWndProc  (HWND, WORD, WORD, LONG) ;
  116. long FAR PASCAL RectWndProc   (HWND, WORD, WORD, LONG) ;
  117.  
  118. // structure for storing data unique to each Hello child window
  119.  
  120. typedef struct
  121. {
  122.     short    nColor ;
  123. #if defined(_MEWEL_)
  124.     WORD     clrText ;     /* colors are words */
  125. #else
  126.     COLORREF clrText ;
  127. #endif
  128. }
  129. HELLODATA ;
  130.  
  131. typedef HELLODATA *NPHELLODATA ;
  132.  
  133. // structure for storing data unique to each Rect child window
  134.  
  135. typedef struct
  136. {
  137.     short cxClient ;
  138.     short cyClient ;
  139. }
  140. RECTDATA ;
  141.  
  142. typedef RECTDATA *NPRECTDATA ;
  143.  
  144. // global variables
  145.  
  146. char   szFrameClass [] = "MdiFrame" ;
  147. char   szHelloClass [] = "MdiHelloChild" ;
  148. char   szRectClass  [] = "MdiRectChild" ;
  149. HANDLE hInst ;
  150. HMENU  hMenuInit, hMenuHello, hMenuRect ;
  151. HMENU  hMenuInitWindow, hMenuHelloWindow, hMenuRectWindow ;
  152. HWND   hwndFrame, hwndClient ;
  153.  
  154. int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance,
  155.                     LPSTR lpszCmdLine, int nCmdShow)
  156. {
  157.     HANDLE   hAccel ;
  158.     MSG      msg ;
  159.     WNDCLASS wndclass ;
  160.  
  161.     hInst = hInstance ;
  162.  
  163.     if (!hPrevInstance)
  164.     {
  165.         // Register the frame window class
  166.  
  167.         memset (&wndclass, 0, sizeof (wndclass));
  168.         wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
  169.         wndclass.lpfnWndProc   = FrameWndProc ;
  170.         wndclass.cbClsExtra    = 0 ;
  171.         wndclass.cbWndExtra    = 0 ;
  172.         wndclass.hInstance     = hInstance ;
  173.         wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
  174.         wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
  175.         wndclass.hbrBackground = COLOR_APPWORKSPACE + 1 ;
  176.         wndclass.lpszMenuName  = "MdiMenuInit" ;
  177.         wndclass.lpszClassName = szFrameClass ;
  178.  
  179.         RegisterClass (&wndclass) ;
  180.  
  181.         // Register the Hello child window class
  182.  
  183.         memset (&wndclass, 0, sizeof (wndclass));
  184.         wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
  185.         wndclass.lpfnWndProc   = HelloWndProc ;
  186.         wndclass.cbClsExtra    = 0 ;
  187.         wndclass.cbWndExtra    = sizeof (LOCALHANDLE) ;
  188.         wndclass.hInstance     = hInstance ;
  189.         wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
  190.         wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
  191.         wndclass.hbrBackground = GetStockObject (WHITE_BRUSH) ;
  192.         wndclass.lpszMenuName  = NULL ;
  193.         wndclass.lpszClassName = szHelloClass ;
  194.  
  195.         RegisterClass (&wndclass) ;
  196.  
  197.         // Register the Rect child window class
  198.  
  199.         memset (&wndclass, 0, sizeof (wndclass));
  200.         wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
  201.         wndclass.lpfnWndProc   = RectWndProc ;
  202.         wndclass.cbClsExtra    = 0 ;
  203.         wndclass.cbWndExtra    = sizeof (LOCALHANDLE) ;
  204.         wndclass.hInstance     = hInstance ;
  205.         wndclass.hIcon         = NULL ;
  206.         wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
  207.         wndclass.hbrBackground = GetStockObject (WHITE_BRUSH) ;
  208.         wndclass.lpszMenuName  = NULL ;
  209.         wndclass.lpszClassName = szRectClass ;
  210.  
  211.         RegisterClass (&wndclass) ;
  212.     }
  213.  
  214.     // Create the frame window
  215.  
  216.     hwndFrame = _CreateWindow (
  217.         szFrameClass,
  218.         "MDI Demonstration",
  219.         WS_OVERLAPPEDWINDOW
  220.             | WS_CLIPCHILDREN,
  221.         CW_USEDEFAULT,
  222.         CW_USEDEFAULT,
  223.         CW_USEDEFAULT,
  224.         CW_USEDEFAULT,
  225.         NULL,
  226.         NULL,
  227.         hInstance,
  228.         NULL
  229.         );
  230.  
  231.     hwndClient = GetWindow (hwndFrame, GW_CHILD) ;
  232.  
  233.     ShowWindow (hwndFrame, (BOOL) nCmdShow) ;
  234.     UpdateWindow (hwndFrame) ;
  235.     SetFocus(hwndFrame);
  236.  
  237. #if defined(_MEWEL_)
  238.     MessageBox(hwndFrame,
  239. "Just so you know...\n\
  240. MEWEL does not do complex cliiping in the Rectangle() function, so the\n\
  241. rectangles drawn in a child window will paint over any overlapping\n\
  242. windows. But, since this is domain of a graphical-oriented window system\n\
  243. and not MEWEL, it shouldn't affect any normal MEWEL apps.",
  244.                "Warning", MB_OK);
  245. #endif
  246.  
  247.     // Enter the modified message loop
  248.  
  249.     while (GetMessage (&msg, NULL, 0, 0))
  250.     {
  251.         if (!TranslateMDISysAccel (hwndClient, &msg) &&
  252.             !_TranslateAccelerator (hwndFrame, hAccel, &msg))
  253.         {
  254.             TranslateMessage (&msg) ;
  255.             DispatchMessage (&msg) ;
  256.         }
  257.     }
  258.     return msg.wParam ;
  259. }
  260.  
  261. long FAR PASCAL FrameWndProc (HWND hwnd, WORD message,
  262.                               WORD wParam, LONG lParam)
  263. {
  264.     CLIENTCREATESTRUCT clientcreate ;
  265.     FARPROC            lpfnEnum ;
  266.     HWND               hwndChild, hwndNext ;
  267.     MDICREATESTRUCT    mdicreate ;
  268.  
  269.     switch (message)
  270.     {
  271.         case WM_CREATE:          // Create the client window
  272.  
  273.             // Obtain handles to three possible menus & submenus
  274.             hwndFrame  = hwnd;
  275.             hMenuInit  = LoadMenu (hInst, "MdiMenuInit") ;
  276.             hMenuHello = LoadMenu (hInst, "MdiMenuHello") ;
  277.             hMenuRect  = LoadMenu (hInst, "MdiMenuRect") ;
  278.  
  279.             hMenuInitWindow  = GetSubMenu (hMenuInit,   INIT_MENU_POS) ;
  280.             hMenuHelloWindow = GetSubMenu (hMenuHello, HELLO_MENU_POS) ;
  281.             hMenuRectWindow  = GetSubMenu (hMenuRect,   RECT_MENU_POS) ;
  282.  
  283.             clientcreate.hWindowMenu  = hMenuInitWindow ;
  284.             clientcreate.idFirstChild = IDM_FIRSTCHILD ;
  285.  
  286.             hwndClient = _CreateWindow (
  287.                 "MDICLIENT",
  288.                 NULL,
  289.                 WS_CHILD
  290.                     | WS_CLIPCHILDREN
  291.                     | WS_VISIBLE,
  292.                 0,
  293.                 0,
  294.                 0,
  295.                 0,
  296.                 hwnd,
  297.                 1,
  298.                 hInst,
  299.                 (LPSTR) &clientcreate
  300.                 ) ;
  301.             return 0 ;
  302.  
  303.         case WM_COMMAND:
  304.             switch (wParam)
  305.             {
  306.                 case IDM_NEWHELLO:       // Create a Hello child window
  307.  
  308.                     mdicreate.szClass = szHelloClass ;
  309.                     mdicreate.szTitle = "Hello" ;
  310.                     mdicreate.hOwner  = hInst ;
  311.                     mdicreate.x       = CW_USEDEFAULT ;
  312.                     mdicreate.y       = CW_USEDEFAULT ;
  313.                     mdicreate.cx      = CW_USEDEFAULT ;
  314.                     mdicreate.cy      = CW_USEDEFAULT ;
  315.                     mdicreate.style   = 0 ;
  316.                     mdicreate.lParam  = NULL ;
  317.  
  318.                     hwndChild = (HWND) SendMessage(hwndClient, WM_MDICREATE, 0,
  319.                         (LONG) (LPMDICREATESTRUCT) &mdicreate) ;
  320.                     return 0 ;
  321.  
  322.                 case IDM_NEWRECT:        // Create a Rect child window
  323.  
  324.                     mdicreate.szClass = szRectClass ;
  325.                     mdicreate.szTitle = "Rectangles" ;
  326.                     mdicreate.hOwner  = hInst ;
  327.                     mdicreate.x       = CW_USEDEFAULT ;
  328.                     mdicreate.y       = CW_USEDEFAULT ;
  329.                     mdicreate.cx      = CW_USEDEFAULT ;
  330.                     mdicreate.cy      = CW_USEDEFAULT ;
  331.                     mdicreate.style   = 0 ;
  332.                     mdicreate.lParam  = NULL ;
  333.  
  334.                     hwndChild = (HWND) SendMessage(hwndClient, WM_MDICREATE, 0,
  335.                         (LONG) (LPMDICREATESTRUCT) &mdicreate) ;
  336.                     return 0 ;
  337.  
  338.                 case IDM_CLOSE:          // Close the active window
  339.  
  340.                     hwndChild = LOWORD (SendMessage (hwndClient,
  341.                         WM_MDIGETACTIVE, 0, 0L)) ;
  342.  
  343.                     if (SendMessage (hwndChild, WM_QUERYENDSESSION, 0, 0L))
  344.                         SendMessage (hwndClient, WM_MDIDESTROY,
  345.                         hwndChild, 0L) ;
  346.                     return 0 ;
  347.  
  348.                 case IDM_EXIT:           // Exit the program
  349.  
  350.                     SendMessage (hwnd, WM_CLOSE, 0, 0L) ;
  351.                     return 0 ;
  352.  
  353.                     // Messages for arranging windows
  354.                 case IDM_TILE:
  355.                     SendMessage (hwndClient, WM_MDITILE, 0, 0L) ;
  356.                     return 0 ;
  357.  
  358.                 case IDM_CASCADE:
  359.                     SendMessage (hwndClient, WM_MDICASCADE, 0, 0L) ;
  360.                     return 0 ;
  361.  
  362.                 case IDM_ARRANGE:
  363.                     SendMessage (hwndClient, WM_MDIICONARRANGE, 0, 0L) ;
  364.                     return 0 ;
  365.  
  366.                 case IDM_CLOSEALL:       // Attempt to close all children
  367.  
  368.                     lpfnEnum = MakeProcInstance (CloseEnumProc, hInst) ;
  369.                     EnumChildWindows (hwndClient, lpfnEnum, 0L) ;
  370.                     FreeProcInstance (lpfnEnum) ;
  371.                     return 0 ;
  372.  
  373.                 default:            // Pass to active child
  374.  
  375.                     hwndChild = LOWORD (SendMessage (hwndClient,
  376.                         WM_MDIGETACTIVE, 0, 0L)) ;
  377.  
  378.                     if (IsWindow (hwndChild))
  379.                         SendMessage (hwndChild, WM_COMMAND,
  380.                         wParam, lParam) ;
  381.  
  382.                     break ;        // and then to DefFrameProc
  383.             }
  384.             break ;
  385.  
  386.         case WM_QUERYENDSESSION:
  387.         case WM_CLOSE:       // Attempt to close all children
  388.             SendMessage (hwnd, WM_COMMAND, IDM_CLOSEALL, 0L) ;
  389.  
  390.             if (NULL != GetWindow (hwndClient, GW_CHILD))
  391.                 return 0 ;
  392.             break ;   // ie, call DefFrameProc ;
  393.  
  394.         case WM_DESTROY :
  395.             PostQuitMessage (0) ;
  396.             return 0 ;
  397.     }
  398.     // Pass unprocessed msgs to DefFrameProc (not DefWindowProc)
  399.  
  400.     return DefFrameProc (hwnd, hwndClient, message, wParam, lParam) ;
  401. }
  402.  
  403. BOOL FAR PASCAL CloseEnumProc (HWND hwnd, LONG lParam)
  404. {
  405.     if (GetWindow (hwnd, GW_OWNER))         // check for icon title
  406.         return 1 ;
  407.  
  408.     SendMessage (GetParent (hwnd), WM_MDIRESTORE, hwnd, 0L) ;
  409.  
  410.     if (!SendMessage (hwnd, WM_QUERYENDSESSION, 0, 0L))
  411.         return 1 ;
  412.  
  413.     SendMessage (GetParent (hwnd), WM_MDIDESTROY, hwnd, 0L) ;
  414.     return 1 ;
  415. }
  416.  
  417. long FAR PASCAL HelloWndProc (HWND hwnd, WORD message,
  418.                             WORD wParam, LONG lParam)
  419. {
  420. #if defined(_MEWEL_)
  421.    static WORD clrTextArray [] =    /* colors are words */
  422.       { BLACK,
  423.         RED,
  424.         GREEN,
  425.         BLUE,
  426.         WHITE } ;
  427. #else
  428.    static COLORREF clrTextArray [] =
  429.       { RGB (  0,   0,   0),
  430.         RGB (255,   0,   0),
  431.         RGB (  0, 255,   0),
  432.         RGB (  0,   0, 255),
  433.         RGB (255, 255, 255) } ;
  434. #endif
  435.  
  436.     HDC             hdc ;
  437.     HMENU           hMenu ;
  438.     LOCALHANDLE     hHelloData ;
  439.     NPHELLODATA     npHelloData ;
  440.     PAINTSTRUCT     ps ;
  441.     RECT            rect ;
  442.  
  443.     switch (message)
  444.     {
  445.           case WM_CREATE:
  446.               // Allocate memory for window private data
  447.   
  448.               hHelloData = LocalAlloc (LMEM_MOVEABLE | LMEM_ZEROINIT,
  449.                   sizeof (HELLODATA)) ;
  450.   
  451.               npHelloData = (NPHELLODATA) LocalLock (hHelloData) ;
  452.               npHelloData->nColor  = IDM_BLACK ;
  453.               npHelloData->clrText = RGB (0, 0, 0) ;
  454.               LocalUnlock (hHelloData) ;
  455.               SetWindowLOCALHANDLE (hwnd, 0, hHelloData) ;
  456.   
  457.               // Save some window handles
  458.   
  459.               hwndClient = GetParent (hwnd) ;
  460.               hwndFrame  = GetParent (hwndClient) ;
  461.               return 0 ;
  462.  
  463.           case WM_COMMAND:
  464.               switch (wParam)
  465.               {
  466.                   case IDM_BLACK:
  467.                   case IDM_RED:
  468.                   case IDM_GREEN:
  469.                   case IDM_BLUE:
  470.                   case IDM_WHITE:
  471.                       // Change the text color
  472.   
  473.                       hHelloData  = GetWindowLOCALHANDLE (hwnd, 0) ;
  474.                       npHelloData = (NPHELLODATA) LocalLock (hHelloData) ;
  475.   
  476.                       hMenu = GetMenu (hwndFrame) ;
  477.   
  478.                       CheckMenuItem (hMenu, npHelloData->nColor,
  479.                           MF_UNCHECKED) ;
  480.                       npHelloData->nColor = wParam ;
  481.                       CheckMenuItem (hMenu, npHelloData->nColor,
  482.                           MF_CHECKED) ;
  483.   
  484.                       npHelloData->clrText =
  485.                           clrTextArray [wParam - IDM_BLACK] ;
  486.   
  487.                       LocalUnlock (hHelloData) ;
  488.                       InvalidateRect (hwnd, NULL, FALSE) ;
  489.                       break;
  490.               }
  491.               return 0 ;
  492.  
  493.           case WM_PAINT:
  494.               // Paint the window
  495.   
  496.               hdc = BeginPaint (hwnd, &ps) ;
  497.   
  498.               hHelloData  = GetWindowLOCALHANDLE (hwnd, 0) ;
  499.               npHelloData = (NPHELLODATA) LocalLock (hHelloData) ;
  500.               SetTextColor (hdc, npHelloData->clrText) ;
  501.               LocalUnlock (hHelloData) ;
  502.   
  503.               GetClientRect (hwnd, &rect) ;
  504.   
  505. #if defined(_MEWEL_)
  506.               WinClear(hwnd);
  507.               TextOut(hdc, 0, 0, "Hello, World!", strlen("Hello, World!"));
  508. #else
  509.               DrawText (hdc, "Hello, World!", -1, &rect,
  510.                   DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;
  511. #endif
  512.   
  513.               EndPaint (hwnd, &ps) ;
  514.               return 0 ;
  515.  
  516.         case WM_MDIACTIVATE:
  517.  
  518.             // Set the Hello menu if gaining focus
  519.  
  520.             if (wParam == TRUE)
  521.                 SendMessage (hwndClient, WM_MDISETMENU, 0,
  522.                 MAKELONG (hMenuHello, hMenuHelloWindow)) ;
  523.  
  524.               // check or uncheck menu item
  525.   
  526.               hHelloData  = GetWindowLOCALHANDLE (hwnd, 0) ;
  527.               npHelloData = (NPHELLODATA) LocalLock (hHelloData) ;
  528.               CheckMenuItem (hMenuHello, npHelloData->nColor,
  529.                   wParam ? MF_CHECKED : MF_UNCHECKED) ;
  530.               LocalUnlock (hHelloData) ;
  531.  
  532.             // Set the Init menu if losing focus
  533.  
  534.             if (wParam == FALSE)
  535.                 SendMessage (hwndClient, WM_MDISETMENU, 0,
  536.                 MAKELONG (hMenuInit, hMenuInitWindow)) ;
  537.  
  538.             DrawMenuBar (hwndFrame) ;
  539.             return 0 ;
  540.  
  541.         case WM_QUERYENDSESSION:
  542.         case WM_CLOSE:
  543.             if (IDOK != MessageBox (hwnd,"OK to close window?","Hello",
  544.                 MB_ICONQUESTION | MB_OKCANCEL))
  545.                 return 0 ;
  546.             break ;   // ie, call DefMDIChildProc
  547.  
  548.           case WM_DESTROY:
  549.               hHelloData = GetWindowLOCALHANDLE (hwnd, 0) ;
  550.               LocalFree (hHelloData) ;
  551.               return 0 ;
  552.     }
  553.     // Pass unprocessed message to DefMDIChildProc
  554.  
  555.     return DefMDIChildProc (hwnd, message, wParam, lParam) ;
  556. }
  557.  
  558. long FAR PASCAL RectWndProc (HWND hwnd, WORD message,
  559.                            WORD wParam, LONG lParam)
  560. {
  561.     HPEN        hBrush ;
  562.     HDC         hdc ;
  563.     LOCALHANDLE hRectData ;
  564.     NPRECTDATA  npRectData ;
  565.     PAINTSTRUCT ps ;
  566.     short       xLeft, xRight, yTop, yBottom, nRed, nGreen, nBlue ;
  567. #if defined(_MEWEL_)
  568.     RECT        rWindow;
  569. #endif
  570.  
  571.     switch (message)
  572.     {
  573.           case WM_CREATE:
  574.               // Allocate memory for window private data
  575.   
  576.               hRectData = LocalAlloc (LMEM_MOVEABLE | LMEM_ZEROINIT,
  577.                   sizeof (RECTDATA)) ;
  578.   
  579.               SetWindowLOCALHANDLE (hwnd, 0, hRectData) ;
  580.   
  581.               // Start the timer going
  582.   
  583.               SetTimer (hwnd, 1, 250, NULL) ;
  584.   
  585.               // Save some window handles
  586.   
  587.               hwndClient = GetParent (hwnd) ;
  588.               hwndFrame  = GetParent (hwndClient) ;
  589. #if defined(_MEWEL_)
  590.               GetClientRect(hwnd, &rWindow);
  591.               lParam = MAKELONG(RECT_WIDTH(rWindow), RECT_HEIGHT(rWindow));
  592.               /* fall through ... */
  593. #else
  594.               return 0 ;
  595. #endif
  596.  
  597.           case WM_SIZE:            // Save the window size
  598.   
  599.               hRectData  = GetWindowLOCALHANDLE (hwnd, 0) ;
  600.               npRectData = (NPRECTDATA) LocalLock (hRectData) ;
  601.   
  602.               npRectData->cxClient = LOWORD (lParam) ;
  603.               npRectData->cyClient = HIWORD (lParam) ;
  604.   
  605.               LocalUnlock (hRectData) ;
  606.   
  607.               break ; //WM_SIZE must be processed by DefMDIChildProc
  608.  
  609.           case WM_TIMER:           // Display a random rectangle
  610.   
  611.               hRectData  = GetWindowLOCALHANDLE (hwnd, 0) ;
  612.               npRectData = (NPRECTDATA) LocalLock (hRectData) ;
  613.   
  614.               xLeft   = rand () % npRectData->cxClient ;
  615.               xRight  = rand () % npRectData->cxClient ;
  616.               yTop    = rand () % npRectData->cyClient ;
  617.               yBottom = rand () % npRectData->cyClient ;
  618. #if defined(_MEWEL_)
  619.               nRed    = rand () % 16;
  620. #else
  621.               nRed    = rand () & 255 ;
  622.               nGreen  = rand () & 255 ;
  623.               nBlue   = rand () & 255 ;
  624. #endif
  625.   
  626.               hdc = GetDC (hwnd) ;
  627. #if defined(_MEWEL_)
  628.               hBrush = CreateSolidBrush (nRed) ;
  629.               SetBkColor(hdc, hBrush);
  630. #else
  631.               hBrush = CreateSolidBrush (RGB (nRed, nGreen, nBlue)) ;
  632. #endif
  633.               SelectObject (hdc, hBrush) ;
  634.   
  635.               Rectangle (hdc, min (xLeft, xRight), min (yTop, yBottom),
  636.                   max (xLeft, xRight), max (yTop, yBottom)) ;
  637.   
  638.               ReleaseDC (hwnd, hdc) ;
  639.               DeleteObject (hBrush) ;
  640.               LocalUnlock (hRectData) ;
  641.               return 0 ;
  642.  
  643.           case WM_PAINT:           // Clear the window
  644.   
  645.               InvalidateRect (hwnd, NULL, TRUE) ;
  646.               hdc = BeginPaint (hwnd, &ps) ;
  647.               EndPaint (hwnd, &ps) ;
  648.               return 0 ;
  649.  
  650.         case WM_MDIACTIVATE:     // Set the appropriate menu
  651.             if (wParam == TRUE)
  652.                 SendMessage (hwndClient, WM_MDISETMENU, 0,
  653.                 MAKELONG (hMenuRect, hMenuRectWindow)) ;
  654.             else
  655.                 SendMessage (hwndClient, WM_MDISETMENU, 0,
  656.                 MAKELONG (hMenuInit, hMenuInitWindow)) ;
  657.  
  658.             DrawMenuBar (hwndFrame) ;
  659.             return 0 ;
  660.  
  661.           case WM_DESTROY:
  662.               hRectData = GetWindowLOCALHANDLE (hwnd, 0) ;
  663.               LocalFree (hRectData) ;
  664.               KillTimer (hwnd, 1) ;
  665.               return 0 ;
  666.     }
  667.     // Pass unprocessed message to DefMDIChildProc
  668.  
  669.     return DefMDIChildProc (hwnd, message, wParam, lParam) ;
  670. }
  671.  
  672.