home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c480 / 18.ddi / SAMPLES / DIBVIEW / FRAME.C_ / FRAME.C
Encoding:
C/C++ Source or Header  |  1993-02-08  |  22.4 KB  |  800 lines

  1. /*************************************************************************
  2.  
  3.       File:  FRAME.C
  4.  
  5.    Purpose:  Routines needed to support the frame window, menus, etc.
  6.  
  7.  Functions:  FrameWndProc
  8.              DoCommands
  9.              OpenDIBWindow
  10.              OpenPaletteWindow
  11.              EnableWindowOptionsMenus
  12.  
  13.   Comments:
  14.  
  15.    History:   Date     Reason
  16.  
  17.             06/01/91   Created
  18.             01/28/92   IDM_PALDIB bug fix : delete palette
  19.                          returned by CurrentDIBPalette().
  20.  
  21. *************************************************************************/
  22.  
  23. #include "master.h"
  24.  
  25. typedef HWND FAR *LPHWND;
  26.  
  27.  
  28. // Local function prototypes
  29.  
  30. void OpenPaletteWindow (LPSTR szTitle, HWND hOwner, HPALETTE hPal);
  31. long DoCommands(HWND hWnd,
  32.                 WORD wParam,
  33.                 LONG lParam);
  34.  
  35.  
  36.  
  37. char  szDIBPalTitle[] = "DIB Palette";       // Title on DIB Palette Window
  38. char  szSysPalTitle[] = "System Palette";    // Title on System Palette Wnd
  39. HMENU hFrameMenu      = NULL;                // Menu handle to frame menu.
  40. HWND  hFrameWnd       = NULL;
  41.  
  42.  
  43.  
  44.  
  45. //---------------------------------------------------------------------
  46. //
  47. // Function:   FrameWndProc
  48. //
  49. // Purpose:    Window procedure for MDI frame window.
  50. //             Handles all messages destined for the frame.
  51. //
  52. // Parms:      hWnd    == Handle to the frame window.
  53. //             message == Message for window.
  54. //             wParam  == Depends on message.
  55. //             lParam  == Depends on message.
  56. //
  57. // History:   Date      Reason
  58. //             6/01/91  Created
  59. //
  60. //---------------------------------------------------------------------
  61.  
  62. long FAR PASCAL __export FrameWndProc(HWND hWnd,
  63.                  UINT message,
  64.                  WPARAM wParam,
  65.                  LPARAM lParam)
  66. {
  67.    static BOOL bPalDev;         // Display device can animate palettes?
  68.  
  69.    switch (message)
  70.    {
  71.       case WM_CREATE:
  72.          {
  73.          CLIENTCREATESTRUCT ccs;
  74.          HDC                hDC;
  75.  
  76.  
  77.             // Find window menu where children will be listed
  78.  
  79.          ccs.hWindowMenu  = GetSubMenu (GetMenu (hWnd), WINDOW_MENU);
  80.          ccs.idFirstChild = IDM_WINDOWCHILD;
  81.  
  82.  
  83.             // Create the MDI client filling the client area
  84.  
  85.          hWndMDIClient = CreateWindow (
  86.                            "mdiclient",
  87.                            NULL,
  88.                            WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL,
  89.                            0,
  90.                            0,
  91.                            0,
  92.                            0,
  93.                            hWnd,
  94.                            0xCAC,
  95.                            hInst,
  96.                            (LPSTR)&ccs);
  97.  
  98.          ShowWindow (hWndMDIClient, SW_SHOW);
  99.  
  100.          hDC        = GetDC (NULL);
  101.          bPalDev    = GetDeviceCaps (hDC, RASTERCAPS) & RC_PALETTE;
  102.          hFrameMenu = GetMenu (hWnd);
  103.          hFrameWnd  = hWnd;
  104.          ReleaseDC (NULL, hDC);
  105.          // gets the default system directory
  106.          getcwd(szDirName, DIRNAMESIZE);
  107.  
  108.          break;
  109.          }
  110.  
  111.  
  112.  
  113.          // Initialize pull down menus.  Gray the File/SaveAs+Print
  114.          //  if there is no current MDI child window.  Also, gray the
  115.          //  palette options when appropriate (i.e. gray when non-palette
  116.          //  device, gray animate if one is being animated or if there
  117.          //  are no MDI child windows, gray restore if none are being
  118.          //  animated).  The "Window" menu will also be grayed if there
  119.          //  are no MDI children.
  120.  
  121.       case WM_INITMENUPOPUP:
  122.          {
  123.          HWND  hCurWnd;
  124.  
  125.          hCurWnd = GetCurrentMDIWnd ();
  126.  
  127.          EnableMenuItem (hFrameMenu,
  128.                          IDM_SAVE,
  129.                          MF_BYCOMMAND | (hCurWnd ? MF_ENABLED : MF_GRAYED));
  130.          EnableMenuItem (hFrameMenu,
  131.                          IDM_PRINT,
  132.                          MF_BYCOMMAND | (hCurWnd ? MF_ENABLED : MF_GRAYED));
  133.          EnableMenuItem (hFrameMenu,
  134.                          IDM_OPTIONS,
  135.                          MF_BYCOMMAND | (hCurWnd ? MF_ENABLED : MF_GRAYED));
  136.          EnableMenuItem (hFrameMenu,
  137.                          IDM_PALDIB,
  138.                          MF_BYCOMMAND | (hCurWnd ? MF_ENABLED : MF_GRAYED));
  139.          EnableMenuItem (hFrameMenu,
  140.                          IDM_COPY,
  141.                          MF_BYCOMMAND | (hCurWnd ? MF_ENABLED : MF_GRAYED));
  142.          EnableMenuItem (hFrameMenu,
  143.                          IDM_PASTE,
  144.                          MF_BYCOMMAND |
  145.                           IsClipboardFormatAvailable (CF_DIB) ||
  146.                           IsClipboardFormatAvailable (CF_BITMAP) ?
  147.                              MF_ENABLED : MF_GRAYED);
  148.          EnableMenuItem (hFrameMenu,
  149.                          IDM_PALANIMATE,
  150.                          MF_BYCOMMAND |
  151.                           (bPalDev && !hWndAnimate && hCurWnd ? MF_ENABLED : MF_GRAYED));
  152.          EnableMenuItem (hFrameMenu,
  153.                          IDM_PALRESTORE,
  154.                          MF_BYCOMMAND |
  155.                           (bPalDev && hWndAnimate ? MF_ENABLED : MF_GRAYED));
  156.          break;
  157.          }
  158.  
  159.  
  160.  
  161.  
  162.          // Go handle all WM_COMMAND messages in DoCommands().
  163.  
  164.       case WM_COMMAND:
  165.          return DoCommands (hWnd, wParam, lParam);
  166.  
  167.  
  168.  
  169.          // Palette changed message -- someone changed the palette
  170.          //  somehow.  We must make sure that all the MDI child windows
  171.          //  realize their palettes here.
  172.  
  173.       case WM_PALETTECHANGED:
  174.          {
  175.          static BOOL bInPalChange = FALSE;
  176.  
  177.          if (bInPalChange)
  178.             break;
  179.  
  180.          bInPalChange = TRUE;
  181.          SendMessageToAllChildren (hWndMDIClient, message, wParam, lParam);
  182.          bInPalChange = FALSE;
  183.          break;
  184.          }
  185.  
  186.  
  187.  
  188.          // We get a QUERYNEWPALETTE message when our app gets the
  189.          //  focus.  We need to realize the currently active MDI
  190.          //  child's palette as the foreground palette for the app.
  191.          //  We do this by sending our MYWM_QUERYNEWPALETTE message
  192.          //  to the currently active child's window procedure.  See
  193.          //  the comments in CHILD.C (at the top of the file) for
  194.          //  more info on this.
  195.  
  196.       case WM_QUERYNEWPALETTE:
  197.          {
  198.          HWND hActive;
  199.  
  200.          hActive = GetCurrentMDIWnd ();
  201.  
  202.          if (hActive)
  203.             return SendMessage (hActive, MYWM_QUERYNEWPALETTE, hWnd, 0L);
  204.  
  205.          return FALSE;
  206.          }
  207.  
  208.  
  209.          // Terminate this app by posting a WM_QUIT message.
  210.  
  211.       case WM_DESTROY:
  212.            PostQuitMessage(0);
  213.          break;
  214.  
  215.  
  216.  
  217.          // We didn't handle, pass to DefFrameProc.
  218.  
  219.       default:
  220.          return DefFrameProc (hWnd,hWndMDIClient, message, wParam, lParam);
  221.     }
  222.  
  223.     return (NULL);
  224. }
  225.  
  226.  
  227.  
  228. //---------------------------------------------------------------------
  229. //
  230. // Function:   DoCommands
  231. //
  232. // Purpose:    WM_COMMAND handler for MDI frame window.
  233. //
  234. // Parms:      hWnd    == Handle to this MDI child window.
  235. //             wParam  == Depends on command.
  236. //             lParam  == Depends on command.
  237. //
  238. // History:   Date      Reason
  239. //             6/01/91  Created
  240. //            10/26/91  Removed "message" parm (unused)
  241. //                      Fixed bugs in IDM_PRINT:  was
  242. //                        assigning incorrect values to
  243. //                        wUnits for PRINT_BESTFIT and
  244. //                        PRINT_STRETCH.
  245. //            10/29/91  Added passing of bUse31APIs to
  246. //                        DIBPrint() in IDM_PRINT case.
  247. //            10/30/91  Added capture code.
  248. //            11/15/91  Added szFileName parm to OpenDIBFile
  249. //                        in IDM_OPEN.  Added use of IDS_CAPTURE
  250. //                        string table entry to IDM_CAPT*.
  251. //            01/28/92  IDM_PALDIB bug fix : delete palette
  252. //                        returned by CurrentDIBPalette().
  253. //
  254. //---------------------------------------------------------------------
  255.  
  256. long DoCommands(HWND hWnd,
  257.                 WORD wParam,
  258.                 LONG lParam)
  259. {
  260.    switch (wParam)
  261.    {
  262.  
  263.          // Put up the About box.
  264.  
  265.       case IDM_ABOUT:
  266.          {
  267.          FARPROC lpDlgProc;
  268.  
  269.  
  270.          lpDlgProc = MakeProcInstance(AboutDlg, hInst);
  271.  
  272.          DialogBox(hInst,             // current instance
  273.                    szAboutDLG,        // resource to use
  274.                    hWnd,              // parent handle
  275.                    lpDlgProc);        // About() instance address
  276.  
  277.          FreeProcInstance(lpDlgProc);
  278.          break;
  279.          }
  280.  
  281.  
  282.  
  283.          // Open up a DIB MDI child window.
  284.  
  285.       case IDM_OPEN:
  286.          {
  287.          HANDLE hDIB;
  288.          char   szFileName [MAX_FILENAME];
  289.  
  290.          hDIB = OpenDIBFile (szFileName);
  291.  
  292.          if (hDIB)
  293.             OpenDIBWindow (hDIB, szFileName);
  294.          break;
  295.          }
  296.  
  297.  
  298.  
  299.  
  300.       case IDM_PRINT:
  301.          {
  302.          HWND        hDIBWnd;
  303.          HANDLE      hDIB;
  304.          RECT        rect;
  305.          HANDLE      hDIBInfo;
  306.          LPDIBINFO   lpDIBInfo;
  307.          WORD        cxDIB, cyDIB, wUnits, cxScale, cyScale;
  308.          BOOL        bUseBanding, bUse31APIs;
  309.          char        lpszDocName [MAX_FILENAME];
  310.  
  311.          hDIBWnd = GetCurrentMDIWnd ();
  312.  
  313.          if (!hDIBWnd)
  314.             break;
  315.  
  316.          hDIBInfo = GetWindowWord (hDIBWnd, WW_DIB_HINFO);
  317.  
  318.          if (!hDIBInfo)
  319.             break;
  320.  
  321.          lpDIBInfo   = (LPDIBINFO) GlobalLock (hDIBInfo);
  322.          hDIB        = lpDIBInfo->hDIB;
  323.          cxDIB       = lpDIBInfo->wDIBWidth;
  324.          cyDIB       = lpDIBInfo->wDIBWidth;
  325.          wUnits      = lpDIBInfo->Options.wPrintOption;
  326.          cxScale     = lpDIBInfo->Options.wXScale;
  327.          cyScale     = lpDIBInfo->Options.wYScale;
  328.          bUseBanding = lpDIBInfo->Options.bPrinterBand;
  329.          bUse31APIs  = lpDIBInfo->Options.bUse31PrintAPIs;
  330.          lstrcpy (lpszDocName, lpDIBInfo->szFileName);
  331.          GlobalUnlock (hDIBInfo);
  332.  
  333.          switch (wUnits)
  334.             {
  335.             case PRINT_BESTFIT:
  336.                wUnits = UNITS_BESTFIT;
  337.                // rect is filled in by DIBPrint().
  338.                break;
  339.  
  340.             case PRINT_STRETCH:
  341.                wUnits = UNITS_STRETCHTOPAGE;
  342.                // rect is filled in by DIBPrint().
  343.                break;
  344.  
  345.             case PRINT_SCALE:
  346.                wUnits      = UNITS_SCALE;
  347.                rect.left   = cxScale;
  348.                rect.top    = cyScale;
  349.                // rect is modified to reflect actual width in DIBPrint.
  350.                break;
  351.  
  352.             default:
  353.                wUnits      = UNITS_PIXELS;
  354.                rect.left   = 0;
  355.                rect.top    = 0;
  356.                rect.right  = cxDIB;
  357.                rect.bottom = cyDIB;
  358.                break;
  359.             }
  360.  
  361.          if (hDIB)
  362.             {
  363.             DWORD dwError;
  364.  
  365.             if (dwError = DIBPrint (hDIB,
  366.                                     &rect,
  367.                                     wUnits,
  368.                                     SRCPAINT,
  369.                                     bUseBanding,
  370.                                     bUse31APIs,
  371.                                     lpszDocName))
  372.                ShowPrintError (hWnd, dwError);
  373.             }
  374.          break;
  375.          }
  376.  
  377.  
  378.          // Save the current DIB to disk.
  379.  
  380.       case IDM_SAVE:
  381.          SaveDIBFile ();
  382.          break;
  383.  
  384.  
  385.          // Handle the clipboard copy operation.
  386.  
  387.       case IDM_COPY:
  388.          HandleCopyClipboard ();
  389.          break;
  390.  
  391.  
  392.          // Handle the clipboard paste operation.
  393.  
  394.       case IDM_PASTE:
  395.          HandlePasteClipboard ();
  396.          break;
  397.  
  398.  
  399.          // Put up the DIB palette window if it isn't already.
  400.          //  Remember to copy the DIB's palette, since if the
  401.          //  DIB window is destroyed, the palette is destroyed
  402.          //  with it.  Also, remember to change the palette flags
  403.          //  so if the DIB is being animated, the palette window's
  404.          //  palette doesn't have the PC_RESERVED flag set.
  405.  
  406.       case IDM_PALDIB:
  407.          {
  408.          HPALETTE hPalDIB, hNewPal;
  409.  
  410.          hPalDIB = CurrentDIBPalette ();
  411.  
  412.          if (!hPalDIB)
  413.             break;
  414.  
  415.          hNewPal = CopyPaletteChangingFlags (hPalDIB, 0);
  416.          DeleteObject (hPalDIB);
  417.  
  418.          OpenPaletteWindow (szDIBPalTitle, hWnd, hNewPal);
  419.          break;
  420.          }
  421.  
  422.  
  423.  
  424.          // Put up the system palette window if it isn't already.
  425.  
  426.       case IDM_PALSYS:
  427.          OpenPaletteWindow (szSysPalTitle, hWnd, GetSystemPalette ());
  428.          break;
  429.  
  430.  
  431.  
  432.          // Animate the DIB's palette.
  433.  
  434.       case IDM_PALANIMATE:
  435.          {
  436.          HWND hMDIChild;
  437.  
  438.          hMDIChild = GetCurrentMDIWnd ();
  439.  
  440.          if (hMDIChild)
  441.             SendMessage (hMDIChild, MYWM_ANIMATE, 0, 0L);
  442.          break;
  443.          }
  444.  
  445.  
  446.          // Restore the DIB's palette (after animation) to its original
  447.          //  state.
  448.  
  449.       case IDM_PALRESTORE:
  450.          {
  451.          HWND hMDIChild;
  452.  
  453.          hMDIChild = GetCurrentMDIWnd ();
  454.  
  455.          if (hMDIChild)
  456.             SendMessage (hMDIChild, MYWM_RESTOREPALETTE, 0, 0L);
  457.          break;
  458.          }
  459.  
  460.  
  461.  
  462.          // Tile MDI windows
  463.  
  464.       case IDM_WINDOWTILE:
  465.          SendMessage (hWndMDIClient, WM_MDITILE, 0, 0L);
  466.          break;
  467.  
  468.  
  469.  
  470.          // Cascade MDI windows
  471.  
  472.       case IDM_WINDOWCASCADE:
  473.          SendMessage (hWndMDIClient, WM_MDICASCADE, 0, 0L);
  474.          break;
  475.  
  476.  
  477.  
  478.          // Auto - arrange MDI icons
  479.  
  480.       case IDM_WINDOWICONS:
  481.          SendMessage (hWndMDIClient, WM_MDIICONARRANGE, 0, 0L);
  482.          break;
  483.  
  484.  
  485.  
  486.          // Close all MDI child windows.
  487.  
  488.       case IDM_WINDOWCLOSEALL:
  489.          CloseAllDIBWindows ();
  490.          break;
  491.  
  492.  
  493.  
  494.          // User wants to see the stretch dialog box.
  495.  
  496.       case IDM_OPTIONS:
  497.          {
  498.          HWND        hDIBWnd;
  499.          HANDLE      hDIB;
  500.          HANDLE      hDIBInfo;
  501.          LPDIBINFO   lpDIBInfo;
  502.          OPTIONSINFO OptionsInfo;
  503.          BOOL        bOldStretch;
  504.  
  505.          hDIBWnd = GetCurrentMDIWnd ();
  506.  
  507.          if (!hDIBWnd)
  508.             break;
  509.  
  510.          hDIBInfo = GetWindowWord (hDIBWnd, WW_DIB_HINFO);
  511.  
  512.          if (!hDIBInfo)
  513.             break;
  514.  
  515.  
  516.             // Set up data for stretch dialog box.
  517.  
  518.          lpDIBInfo   = (LPDIBINFO) GlobalLock (hDIBInfo);
  519.          hDIB        = lpDIBInfo->hDIB;
  520.          OptionsInfo = lpDIBInfo->Options;
  521.          bOldStretch = OptionsInfo.bStretch;
  522.  
  523.          if (hDIB)
  524.             {
  525.             ShowOptions (hWnd, &OptionsInfo);
  526.             lpDIBInfo->Options = OptionsInfo;
  527.             }
  528.  
  529.  
  530.             // If the stretch option changed, need to repaint.
  531.  
  532.          if (lpDIBInfo->Options.bStretch != bOldStretch)
  533.             InvalidateRect (hDIBWnd, NULL, bOldStretch);
  534.  
  535.          GlobalUnlock (hDIBInfo);
  536.          break;
  537.          }
  538.  
  539.  
  540.          // User wants to perform a capture operation.  Call the
  541.          //  appropriate routine in CAPTURE.C for what the user
  542.          //  wants to do.  If we get a handle to a DIB back, open
  543.          //  up a new MDI child.
  544.  
  545.       case IDM_CAPTCLIENT:
  546.       case IDM_CAPTWINDOW:
  547.       case IDM_CAPTFULLSCREEN:
  548.          {
  549.          HANDLE      hDIB;
  550.          char        szWindowText[20], szCapture[20];
  551.          static WORD wWinNumber = 0;      // Capture Window number.
  552.  
  553.          if (wParam == IDM_CAPTFULLSCREEN)
  554.             hDIB = CaptureFullScreen (hWnd);
  555.          else
  556.             hDIB = CaptureWindow (hWnd, (wParam == IDM_CAPTCLIENT));
  557.  
  558.          if (hDIB)
  559.             {
  560.                // Open up a new MDI child with the specified window title
  561.  
  562.             wWinNumber   = (wWinNumber + 1) % 10;
  563.             szCapture[0] = '\0';
  564.             LoadString (hInst, IDS_CAPTURE, szCapture, 20);
  565.  
  566.             wsprintf (szWindowText, szCapture, wWinNumber);
  567.  
  568.             OpenDIBWindow (hDIB, szWindowText);
  569.             }
  570.  
  571.          break;
  572.          }
  573.  
  574.  
  575.  
  576.          // Toggle the "Hide on Capture" option.
  577.  
  578.       case IDM_CAPTUREHIDE:
  579.          {
  580.          BOOL  bHide;
  581.          HMENU hMenu;
  582.  
  583.          bHide = ToggleCaptureHide ();
  584.          hMenu = GetMenu (hWnd);
  585.          CheckMenuItem (hMenu, IDM_CAPTUREHIDE, MF_BYCOMMAND |
  586.                        (bHide ? MF_CHECKED : MF_UNCHECKED));
  587.          break;
  588.          }
  589.  
  590.  
  591.  
  592.          // User wants to exit DIBView.  Send ourselves a WM_CLOSE
  593.          //  message (WM_CLOSE does some necessary clean up operations).
  594.  
  595.       case IDM_EXIT:
  596.          SendMessage (hWnd, WM_CLOSE, 0, 0L);
  597.          break;
  598.  
  599.  
  600.  
  601.          // Must be some system command -- pass it on to the default
  602.          //  frame window procedure.
  603.  
  604.       default:
  605.          return DefFrameProc(hWnd, hWndMDIClient, WM_COMMAND, wParam, lParam);
  606.    }
  607.  
  608.    return NULL;
  609. }
  610.  
  611.  
  612.  
  613.  
  614.  
  615. //---------------------------------------------------------------------
  616. //
  617. // Function:   OpenDIBWindow
  618. //
  619. // Purpose:    This routine opens up an MDI child window.  The child
  620. //             window will be sized to the height/width of the DIB.
  621. //
  622. // Parms:      hDIB    == Handle to the DIB to put in the MDI child.
  623. //             szTitle == Title for title bar (must be a valid DOS
  624. //                        filename.
  625. //
  626. // History:   Date      Reason
  627. //             6/01/91  Created
  628. //            10/15/91  Got rid of use of handle for
  629. //                      DIBCREATEINFO, it's kosher to
  630. //                      pass a far pointer instead.
  631. //
  632. //---------------------------------------------------------------------
  633.  
  634. HWND OpenDIBWindow (HANDLE hDIB, LPSTR szTitle)
  635. {
  636.    LPSTR           lpDIB;
  637.    MDICREATESTRUCT mcs;
  638.    HWND            hChild;
  639.    DWORD           dwDIBHeight, dwDIBWidth;
  640.    DIBCREATEINFO   DIBCreateInfo;
  641.    RECT            rcWindow;
  642.  
  643.    SetCursor(LoadCursor(NULL, IDC_WAIT));
  644.  
  645.    if (hDIB)
  646.       {
  647.       lpDIB       = GlobalLock (hDIB);
  648.       dwDIBHeight = DIBHeight (lpDIB);
  649.       dwDIBWidth  = DIBWidth (lpDIB);
  650.       GlobalUnlock (hDIB);
  651.       }
  652.  
  653.    DIBCreateInfo.hDIB = hDIB;
  654.    lstrcpy (DIBCreateInfo.szFileName, szTitle);
  655.  
  656.  
  657.       // Determine the necessary window size to hold the DIB.
  658.  
  659.    rcWindow.left   = 0;
  660.    rcWindow.top    = 0;
  661.    rcWindow.right  = (int) dwDIBWidth;
  662.    rcWindow.bottom = (int) dwDIBHeight;
  663.  
  664.    AdjustWindowRect (&rcWindow, WS_CHILD|WS_SYSMENU|WS_CAPTION|
  665.                      WS_THICKFRAME|WS_MINIMIZEBOX|WS_MAXIMIZEBOX, FALSE);
  666.  
  667.  
  668.       // Setup to call WM_MDICREATE.
  669.  
  670.    mcs.szTitle = (LPSTR) szTitle;
  671.    mcs.szClass = szMDIChild;
  672.    mcs.hOwner  = hInst;
  673.    mcs.x       = CW_USEDEFAULT;
  674.    mcs.y       = CW_USEDEFAULT;
  675.    mcs.cx      = rcWindow.right - rcWindow.left;
  676.    mcs.cy      = rcWindow.bottom - rcWindow.top;
  677.    mcs.style   = WS_HSCROLL | WS_VSCROLL;
  678.    mcs.lParam  = (LONG) (LPDIBCREATEINFO) &DIBCreateInfo;
  679.  
  680.  
  681.       // If no other DIBs are being displayed, always force this
  682.       //  window to the upper left corner of the MDI client.
  683.  
  684.    if (nDIBsOpen == 0)
  685.       {
  686.       mcs.x = 0;
  687.       mcs.y = 0;
  688.       }
  689.  
  690.  
  691.       // Tell the MDI Client to create the child.
  692.  
  693.    hChild = (WORD) SendMessage (hWndMDIClient,
  694.                                 WM_MDICREATE,
  695.                                 0,
  696.                                 (LONG) (LPMDICREATESTRUCT) &mcs);
  697.  
  698.    if (!hChild)
  699.       {
  700.       SetCursor(LoadCursor(NULL, IDC_ARROW));
  701.       DIBError (ERR_CREATECHILD);
  702.       return NULL;
  703.       }
  704.  
  705.    SetCursor(LoadCursor(NULL, IDC_ARROW));
  706.    return hChild;
  707. }
  708.  
  709.  
  710.  
  711.  
  712.  
  713. //---------------------------------------------------------------------
  714. //
  715. // Function:   OpenPaletteWindo9w
  716. //
  717. // Purpose:    This routine opens up a popup window which displays
  718. //             a palette.
  719. //
  720. //             Note that all the popup window's routines are in
  721. //             PALETTE.C.
  722. //
  723. // Parms:      szTitle == Title for title bar.
  724. //             hOwner  == Handle to the Window which owns this popup
  725. //             hPal    == Palette to display.
  726. //
  727. // History:   Date      Reason
  728. //             6/01/91  Created
  729. //
  730. //---------------------------------------------------------------------
  731.  
  732.  
  733. void OpenPaletteWindow (LPSTR szTitle, HWND hOwner, HPALETTE hPal)
  734. {
  735.    HWND      hWnd;
  736.    HDC       hDC;
  737.    int       cxScr, cyScr;
  738.  
  739.    hDC        = GetDC (NULL);
  740.    cxScr      = GetDeviceCaps (hDC, HORZRES);
  741.    cyScr      = GetDeviceCaps (hDC, VERTRES);
  742.    ReleaseDC (NULL, hDC);
  743.  
  744.    hWnd = CreateWindow (szPalClass,                // Class name
  745.                         szTitle,                   // Title
  746.                         WS_POPUP |                 // Styles -- Popup Window
  747.                          WS_THICKFRAME |           //  Thick (resizable) frame
  748.                          WS_SYSMENU |              //  Has a system menu
  749.                          WS_CLIPSIBLINGS |         //  Clips other siblings
  750.                          WS_CLIPCHILDREN |         //  Clips its children
  751.                          WS_MAXIMIZEBOX |          //  Maximize button
  752.                          WS_MINIMIZEBOX |          //  Minimize button
  753.                          WS_VSCROLL |              //  Vertical scroll bar
  754.                          WS_CAPTION,               //  Caption
  755.                         0,                         // x
  756.                         0,                         // y
  757.                         cxScr / 4,                 // Width
  758.                         cyScr / 4,                 // Height
  759.                         hOwner,                    // Parent
  760.                         NULL,                      // Menu
  761.                         hInst,                     // Instance
  762.                         NULL);                     // Extra parms
  763.  
  764.    SetPaletteWindowsPal (hWnd, hPal);
  765.  
  766.    ShowWindow (hWnd, SW_SHOWNORMAL);
  767.    UpdateWindow (hWnd);
  768. }
  769.  
  770.  
  771.  
  772.  
  773. //---------------------------------------------------------------------
  774. //
  775. // Function:   EnableWindowOptionsMenus
  776. //
  777. // Purpose:    Enable or gray the "Window" and "Options" pull down
  778. //             menus.
  779. //
  780. // Parms:      bEnable == TRUE if "Window" should be enabled,
  781. //                        FALSE if it should be gray.
  782. //
  783. // History:   Date      Reason
  784. //             6/01/91  Created
  785. //
  786. //---------------------------------------------------------------------
  787.  
  788. void EnableWindowAndOptionsMenus (BOOL bEnable)
  789. {
  790.    EnableMenuItem (hFrameMenu,
  791.                    WINDOW_MENU,
  792.                    MF_BYPOSITION | (bEnable ? MF_ENABLED : MF_GRAYED));
  793.  
  794.    EnableMenuItem (hFrameMenu,
  795.                    IDM_OPTIONS,
  796.                    MF_BYCOMMAND | (bEnable ? MF_ENABLED : MF_GRAYED));
  797.  
  798.    DrawMenuBar (hFrameWnd);
  799. }
  800.