home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / MULTIPAD.PAK / MULTIPAD.C < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  20.8 KB  |  795 lines

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright (C) 1993-1995  Microsoft Corporation.  All Rights Reserved.
  7. //
  8. //  MODULE:   multipad.c
  9. //
  10. //  PURPOSE:  Implement the window procedure for the main application
  11. //            window.
  12. //
  13. //  FUNCTIONS:
  14. //    WndProc            - Processes messages for the main window.
  15. //    MsgCommand         - Handle the WM_COMMAND messages for the main window.
  16. //    MsgCreate          - Handle the WM_CREATE message for the main window
  17. //    MsgInitMenu        - Handle the WM_INITMENU message for the main window
  18. //    MsgSize            - Handle the WM_SIZE message for the main window
  19. //    MsgClose           - Handle the WM_CLOSE message for the main window
  20. //    MsgQueryEndSession - Handle the WM_QUERYENDSESSION message 
  21. //    MsgDestroy         - Handles the WM_DESTROY message by calling
  22. //                         PostQuitMessage().
  23. //    CmdFileNew         - Handler to create a new MDI child window
  24. //    CmdFileClose       - Handler to close the active MDI child window
  25. //    CmdClip            - Handler for cut, copy, paste
  26. //    CmdWindowTile      - Handler to tile the MDI children
  27. //    CmdWindowCascade   - Handler to cascade the MDI children
  28. //    CmdWindowIcons     - Handler to arrange the iconic MDI children
  29. //    CmdWindowCloseAll  - Handler to close all the MDI children
  30. //    CmdExit            - Handles the file exit command by calling destory
  31. //                         window on the main window.
  32. //    GetFName           - Get the current file name.
  33. //
  34. //  COMMENTS:
  35. //    Message dispatch table -
  36. //      For every message to be handled by the main window procedure
  37. //      place the message number and handler function pointer in
  38. //      rgmsd (the message dispatch table).  Place the prototype
  39. //      for the function in globals.h and the definition of the
  40. //      function in the appropriate module.
  41. //    Command dispatch table -
  42. //      For every command to be handled by the main window procedure
  43. //      place the command number and handler function pointer in
  44. //      rgcmd (the command dispatch table).  Place the prototype
  45. //      for the function in globals.h and the definition of the
  46. //      function in the appropriate module.
  47. //    Globals.h Contains the definitions of the structures and dispatch.c
  48. //      contains the functions that use these structures.
  49. //
  50.  
  51. #include <windows.h>            // required for all Windows applications
  52. #include <windowsx.h>
  53. #include <commctrl.h>
  54. #include "globals.h"            // prototypes specific to this application
  55. #include "mdichild.h"
  56. #include "toolbar.h"
  57. #include "statbar.h"
  58. #include "resource.h"
  59.  
  60. // Main window message table definition.
  61. MSD rgmsd[] =
  62. {
  63.     {0,                  MsgFindReplace},
  64.     {WM_INITMENU,        MsgInitMenu},
  65.     {WM_COMMAND,         MsgCommand},
  66.     {WM_CREATE,          MsgCreate},
  67.     {WM_DESTROY,         MsgDestroy},
  68.     {WM_MENUSELECT,      MsgMenuSelect},
  69.     {WM_NOTIFY,          MsgNotify},
  70.     {WM_TIMER,           MsgTimer},
  71.     {WM_SIZE,            MsgSize},
  72.     {WM_CLOSE,           MsgClose},
  73.     {WM_QUERYENDSESSION, MsgQueryEndSession},
  74. };
  75.  
  76. MSDI msdiMain =
  77. {
  78.     sizeof(rgmsd) / sizeof(MSD),
  79.     rgmsd,
  80.     edwpMDIFrame
  81. };
  82.  
  83.  
  84. // Main window command table definition.
  85. CMD rgcmd[] =
  86. {
  87.     {IDM_FILENEW,       CmdFileNew},
  88.     {IDM_FILEOPEN,      CmdFileOpen},
  89.     {IDM_FILESAVE,      CmdFileSave},
  90.     {IDM_FILESAVEAS,    CmdFileSaveAs},
  91.     {IDM_FILECLOSE,     CmdFileClose},
  92.     {IDM_FILEPRINT,     CmdFilePrint},
  93.     {IDM_FILEPRINTSU,   CmdFilePrintSU},
  94.     {IDM_EDITCUT,       CmdClip},
  95.     {IDM_EDITCOPY,      CmdClip},
  96.     {IDM_EDITCLEAR,     CmdClip},
  97.     {IDM_EDITPASTE,     CmdClip},
  98.     {IDM_EDITUNDO,      CmdClip},
  99.     {IDM_EXIT,          CmdExit},
  100.     {IDM_ABOUT,         CmdAbout},
  101.     {IDM_FIND,          CmdSearchFindReplace},
  102.     {IDM_REPLACE,       CmdSearchFindReplace},
  103.     {IDM_FINDNEXT,      CmdSearchFindNext},
  104.     {IDM_FINDPREV,      CmdSearchFindNext},
  105.     {IDM_WINDOWTILE,    CmdWindowTile},
  106.     {IDM_WINDOWCASCADE, CmdWindowCascade},
  107.     {IDM_WINDOWICONS,   CmdWindowIcons},
  108.     {IDM_WINDOWCLOSEALL,CmdWindowCloseAll}
  109. };
  110.  
  111. CMDI cmdiMain =
  112. {
  113.     sizeof(rgcmd) / sizeof(CMD),
  114.     rgcmd,
  115.     edwpMDIFrame
  116. };
  117.  
  118.  
  119. //Module specific globals
  120.  
  121. HWND hwndMDIClient = NULL;      // The MDI client window handle.
  122. UINT cUntitled = 1;
  123. UINT cOpen;
  124. HCURSOR hcursHourGlass;
  125. extern char szChildName[];
  126.  
  127. //
  128. //  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
  129. //
  130. //  PURPOSE:  Processes messages for the main window.
  131. //
  132. //  PARAMETERS:
  133. //    hwnd     - window handle
  134. //    uMessage - message number
  135. //    wparam   - additional information (dependant on message number)
  136. //    lparam   - additional information (dependant on message number)
  137. //
  138. //  RETURN VALUE:
  139. //    The return value depends on the message number.  If the message
  140. //    is implemented in the message dispatch table, the return value is
  141. //    the value returned by the message handling function.  Otherwise,
  142. //    the return value is the value returned by the default window procedure.
  143. //
  144. //  COMMENTS:
  145. //    Call the DispMessage() function with the main window's message dispatch
  146. //    information (msdiMain) and the message specific information.
  147. //
  148.  
  149. LRESULT CALLBACK WndProc(HWND   hwnd,
  150.                          UINT   uMessage,
  151.                          WPARAM wparam,
  152.                          LPARAM lparam)
  153. {
  154.     return DispMessage(&msdiMain, hwnd, uMessage, wparam, lparam);
  155. }
  156.  
  157.  
  158. //
  159. //  FUNCTION: MsgCommand(HWND, UINT, WPARAM, LPARAM)
  160. //
  161. //  PURPOSE: Handle the WM_COMMAND messages for the main window.
  162. //
  163. //  PARAMETERS:
  164. //    hwnd     - window handle
  165. //    uMessage - WM_COMMAND (Unused)
  166. //    GET_WM_COMMAND_ID(wparam, lparam)   - Command identifier
  167. //    GET_WM_COMMAND_HWND(wparam, lparam) - Control handle
  168. //
  169. //  RETURN VALUE:
  170. //    The return value depends on the message number.  If the message
  171. //    is implemented in the message dispatch table, the return value is
  172. //    the value returned by the message handling function.  Otherwise,
  173. //    the return value is the value returned by the default window procedure.
  174. //
  175. //  COMMENTS:
  176. //    Call the DispCommand() function with the main window's command dispatch
  177. //    information (cmdiMain) and the command specific information.
  178. //
  179.  
  180. #pragma argsused
  181. LRESULT MsgCommand(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
  182. {
  183.     return DispCommand(&cmdiMain, hwnd, wparam, lparam);
  184. }
  185.  
  186.  
  187. //
  188. //  FUNCTION: MsgCreate(HWND, UINT, WPARAM, LPARAM)
  189. //
  190. //  PURPOSE: Handle the WM_CREATE message for the main frame windwo.
  191. //           Creates the MDI client window.
  192. //
  193. //  PARAMETERS:
  194. //    hwnd - The window handing the message.
  195. //    uMessage - WM_CREATE (unused)
  196. //    wparam - Message specific data (unused).
  197. //    lparam - Message specific data (unused).
  198. //
  199. //  RETURN VALUE:
  200. //    Always returns 0 - message handled.
  201. //
  202. //  COMMENTS:
  203. //
  204. //
  205.  
  206. #pragma argsused
  207. LRESULT MsgCreate(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
  208. {
  209.     CLIENTCREATESTRUCT ccs = {0};
  210.  
  211.     InitCommonControls();   // Initialize the common control library.
  212.  
  213.     CreateTBar(hwnd);       // Create tool bar
  214.     CreateSBar(hwnd);       // Create status bar
  215.  
  216.     // Find window menu where children will be listed
  217.     ccs.hWindowMenu  = GetSubMenu(GetMenu(hwnd), WINDOWMENU);
  218.     ccs.idFirstChild = IDM_WINDOWCHILD;
  219.  
  220.      // Create the MDI client filling the client area
  221.     hwndMDIClient = CreateWindow("mdiclient",
  222.                                  NULL,
  223.                                  WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL |
  224.                                  WS_HSCROLL,
  225.                                  0, 0, 0, 0,
  226.                                  hwnd,
  227.                                  (HMENU)0xCAC,
  228.                                  hInst,
  229.                                  (LPVOID)&ccs);
  230.  
  231.     ShowWindow(hwndMDIClient, SW_SHOW);
  232.  
  233.     hcursHourGlass = LoadCursor(NULL, IDC_WAIT);
  234.  
  235.      return 0;
  236. }
  237.  
  238.  
  239. //
  240. //  FUNCTION: MsgInitMenu(HWND, UINT, WPARAM, LPARAM)
  241. //
  242. //  PURPOSE: Enable/Disable the menu items as appropriate for the active
  243. //           MDI child window
  244. //
  245. //  PARAMETERS:
  246. //
  247. //    hwnd      - Window handle
  248. //    uMessage  - Message number (Unused)
  249. //    wparam    - HMENU - The menu about to be activated
  250. //    lparam    - Extra data     (Unused)
  251. //
  252. //  RETURN VALUE:
  253. //
  254. //    0 - The message was handled.
  255. //    1 - The message was not handled - wrong menu.
  256. //
  257. //  COMMENTS:
  258. //
  259. //
  260.  
  261. #pragma argsused
  262. LRESULT MsgInitMenu(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
  263. {
  264.     if (GetMenu(hwnd) == (HMENU)wparam)
  265.     {
  266.         UINT ichStart;
  267.         UINT ichEnd;
  268.         UINT mf = (cOpen) ? MF_ENABLED : MF_GRAYED;
  269.  
  270.         EnableMenuItem((HMENU)wparam, IDM_FILECLOSE, mf);
  271.  
  272.         mf = MF_GRAYED;
  273.  
  274.         // Enable/Disable Paste menu item
  275.         if (cOpen && OpenClipboard(hwnd))
  276.         {
  277.             if (IsClipboardFormatAvailable(CF_TEXT) ||
  278.                 IsClipboardFormatAvailable(CF_OEMTEXT))
  279.             {
  280.                 mf = MF_ENABLED;
  281.             }
  282.         }
  283.         CloseClipboard();
  284.  
  285.         EnableMenuItem((HMENU)wparam, IDM_EDITPASTE, mf);
  286.  
  287.         // Enable/Disable Undo menu item
  288.           if (cOpen)
  289.             mf = SendMessage(GetEditWindow(NULL), EM_CANUNDO, 0, 0L) ?
  290.                 MF_ENABLED : MF_GRAYED;
  291.         else
  292.             mf = MF_GRAYED;
  293.  
  294.         EnableMenuItem((HMENU)wparam, IDM_EDITUNDO, mf);
  295.  
  296.         // Enable/Disable Cut/Copy/Delete menu items
  297.         if (cOpen)
  298.         {
  299.             SendMessage(GetEditWindow(NULL), 
  300.                         EM_GETSEL, 
  301.                         (WPARAM)&ichStart, 
  302.                         (LPARAM)&ichEnd);
  303.                 mf = (ichEnd != ichStart) ? MF_ENABLED : MF_GRAYED;
  304.         }
  305.         else
  306.             mf = MF_GRAYED;
  307.  
  308.         EnableMenuItem((HMENU)wparam, IDM_EDITCUT, mf);
  309.         EnableMenuItem((HMENU)wparam, IDM_EDITCOPY, mf);
  310.         EnableMenuItem((HMENU)wparam, IDM_EDITCLEAR, mf);
  311.  
  312.         // Enable/Disable Save menu item
  313.         if (cOpen)
  314.             mf = SendMessage(GetEditWindow(NULL), 
  315.                              EM_GETMODIFY, 0, 0L) ? MF_ENABLED : MF_GRAYED;
  316.         else
  317.             mf = MF_GRAYED;
  318.  
  319.         EnableMenuItem((HMENU)wparam, IDM_FILESAVE, mf);
  320.  
  321.         // Enable/Disable Save As, Print, Find and Replace menu items
  322.         if (cOpen)
  323.             mf = SendMessage(GetEditWindow(NULL),
  324.                              WM_GETTEXTLENGTH, 0, 0L) ? MF_ENABLED : MF_GRAYED;
  325.         else
  326.             mf = MF_GRAYED;
  327.  
  328.         EnableMenuItem((HMENU)wparam, IDM_FILESAVEAS, mf);
  329.         EnableMenuItem((HMENU)wparam, IDM_FILEPRINT, mf);
  330.         EnableMenuItem((HMENU)wparam, IDM_FIND, mf);
  331.         EnableMenuItem((HMENU)wparam, IDM_REPLACE, mf);
  332.  
  333.           // Enable/Disable FindNext/FindPrev menu intes
  334.         if (cOpen)
  335.         {
  336.             mf = CanFind() ? MF_ENABLED : MF_GRAYED;
  337.         }
  338.         else
  339.             mf = MF_GRAYED;
  340.  
  341.         EnableMenuItem((HMENU)wparam, IDM_FINDNEXT, mf);
  342.         EnableMenuItem((HMENU)wparam, IDM_FINDPREV, mf);
  343.  
  344.         return 0;
  345.     }
  346.     else
  347.     {
  348.           return 1;
  349.     }
  350. }
  351.  
  352.  
  353. //
  354. //  FUNCTION: MsgSize(HWND, UINT, WPARAM, LPARAM)
  355. //
  356. //  PURPOSE:  This function resizes the toolbar and statusbar controls.
  357. //
  358. //
  359. //  PARAMETERS:
  360. //
  361. //    hwnd      - Window handle  (Used)
  362. //    uMessage  - Message number (Used)
  363. //    wparam    - Extra data     (Used)
  364. //    lparam    - Extra data     (Used)
  365. //
  366. //  RETURN VALUE:
  367. //
  368. //    Always returns 0 - Message handled
  369. //
  370. //  COMMENTS:
  371. //
  372. //    When the window procdure that has the status and tool bar controls
  373. //    receive the WM_SIZE message, it has to pass the message on to these
  374. //    controls so that these controls can adjust their size accordingly.
  375. //
  376. //
  377.  
  378. LRESULT MsgSize(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
  379. {
  380.     SendMessage(hWndToolbar, uMessage, wparam, lparam);
  381.     SendMessage(hWndStatusbar,  uMessage, wparam, lparam);
  382.  
  383.     // Re-position the panes in the status bar
  384.     InitializeStatusBar(hwnd);
  385.  
  386.     // Position the MDI client window between the tool and status bars
  387.     if (wparam != SIZE_MINIMIZED)
  388.     {
  389.         RECT rc, rcClient;
  390.  
  391.         GetClientRect(hwnd, &rcClient);
  392.  
  393.         GetWindowRect(hWndToolbar, &rc);
  394.         ScreenToClient(hwnd, (LPPOINT)&rc.right);
  395.         rcClient.top = rc.bottom;
  396.  
  397.         GetWindowRect(hWndStatusbar, &rc);
  398.         ScreenToClient(hwnd, (LPPOINT)&rc.left);
  399.         rcClient.bottom = rc.top;
  400.  
  401.         MoveWindow(hwndMDIClient,
  402.                    rcClient.left,
  403.                    rcClient.top,
  404.                    rcClient.right-rcClient.left,
  405.                    rcClient.bottom-rcClient.top,
  406.                    TRUE);
  407.     }
  408.  
  409.     return 0 ;
  410. }
  411.  
  412.  
  413. //
  414. //  FUNCTION: MsgClose(HWND, UINT, WPARAM, LPARAM)
  415. //
  416. //  PURPOSE: Close the editor.
  417. //
  418. //  PARAMETERS:
  419. //    hwnd     - The window handing the message.
  420. //    uMessage - The message number. (unused).
  421. //    wparam   - Message specific data (unused).
  422. //    lparam   - Message specific data (unused).
  423. //
  424. //  RETURN VALUE:
  425. //    Always returns 0 - message handled.
  426. //
  427. //  COMMENTS:
  428. //
  429. //
  430.  
  431. #pragma warn -pia
  432. LRESULT MsgClose(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
  433. {
  434.      HWND hwndT;
  435.      BOOL bClose = TRUE;
  436.  
  437.     // As long as the MDI client has a child, query to save it
  438.     while (hwndT = GetWindow(hwndMDIClient, GW_CHILD))
  439.     {
  440.         // Skip the icon and title windows
  441.         while (hwndT && GetWindow(hwndT, GW_OWNER))
  442.             hwndT = GetWindow(hwndT, GW_HWNDNEXT);
  443.  
  444.         if (hwndT)
  445.         {
  446.                 if (!QuerySaveFile(hwnd))
  447.             {
  448.                 bClose=FALSE;
  449.                 break;
  450.             }
  451.             else
  452.                 SendMessage(hwndMDIClient, WM_MDIDESTROY, (WPARAM)hwndT, 0L);
  453.         }
  454.         else
  455.             break;
  456.     }
  457.  
  458.     if (bClose)
  459.         return DefWindowProc(hwnd, uMessage, wparam, lparam);
  460.     else
  461.           return 0;
  462. }
  463. #pragma warn .pia
  464.  
  465. //
  466. //  FUNCTION: MsgQueryEndSession(HWND, UINT, WPARAM, LPARAM)
  467. //
  468. //  PURPOSE: Handles the case where user attempts to quit with unsaved changes.
  469. //
  470. //  PARAMETERS:
  471. //    hwnd - The window handing the message.
  472. //    uMessage - The message number. (unused).
  473. //    wparam - Message specific data (unused).
  474. //    lparam - Message specific data (unused).
  475. //
  476. //  RETURN VALUE:
  477. //    TRUE - Quiting is now safe.
  478. //    FALSE - Don't quit.
  479. //
  480. //  COMMENTS:
  481. //    Let the function QuerySaveFile handle the real work.
  482. //
  483.  
  484. #pragma argsused
  485. LRESULT MsgQueryEndSession(HWND hwnd,
  486.                                     UINT uMessage,
  487.                                     WPARAM wparam,
  488.                            LPARAM lparam)
  489. {
  490.     return QuerySaveFile(hwnd);
  491. }
  492.  
  493.  
  494. //
  495. //  FUNCTION: MsgDestroy(HWND, UINT, WPARAM, LPARAM)
  496. //
  497. //  PURPOSE: Calls PostQuitMessage().
  498. //
  499. //  PARAMETERS:
  500. //
  501. //    hwnd      - Window handle  (Unused)
  502. //    uMessage  - Message number (Unused)
  503. //    wparam    - Extra data     (Unused)
  504. //    lparam    - Extra data     (Unused)
  505. //
  506. //  RETURN VALUE:
  507. //
  508. //    Always returns 0 - Message handled
  509. //
  510. //  COMMENTS:
  511. //
  512. //
  513.  
  514. #pragma argsused
  515. LRESULT MsgDestroy(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
  516. {
  517.     PostQuitMessage(0);
  518.     return 0;
  519. }
  520.  
  521.  
  522. //
  523. //  FUNCTION: CmdFileNew(HWND, WORD, WORD, HWND)
  524. //
  525. //  PURPOSE: To create a new mdi child window.
  526. //
  527. //  PARAMETERS:
  528. //    hwnd     - The window handling the command.
  529. //    wCommand - IDM_FILENEW (unused)
  530. //    hwndCtrl - NULL (unused).
  531. //
  532. //  RETURN VALUE:
  533. //    Always returns 0 - command handled.
  534. //
  535. //  COMMENTS:
  536. //
  537. //
  538.  
  539. #pragma argsused
  540. LRESULT CmdFileNew(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  541. {
  542.      char rgch[15];
  543.  
  544.     wsprintf(rgch, "Untitled%d", cUntitled);
  545.  
  546.     CreateMDIChild(rgch);
  547.  
  548.     return 0;
  549. }
  550.  
  551.  
  552. //
  553. //  FUNCTION: CmdFileClose(HWND, WORD, WORD, HWND)
  554. //
  555. //  PURPOSE: To close the active mdi child window.
  556. //
  557. //  PARAMETERS:
  558. //    hwnd     - The window handling the command.
  559. //    wCommand - IDM_FILECLOSE (unused).
  560. //    hwndCtrl - NULL (unused).
  561. //
  562. //  RETURN VALUE:
  563. //    Always returns 0 - command handled.
  564. //
  565. //  COMMENTS:
  566. //
  567. //
  568.  
  569. #pragma argsused
  570. LRESULT CmdFileClose(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  571. {
  572.      HWND hwndT;
  573.  
  574.     hwndT = GetActiveMDIChild();
  575.     if (hwndT != NULL)
  576.         SendMessage(hwndT, WM_CLOSE, 0, 0L);
  577.  
  578.     return 0;
  579. }
  580.  
  581.  
  582. //
  583. //  FUNCTION: CmdClip(HWND, WORD, WORD, HWND)
  584. //
  585. //  PURPOSE: Handle clipboard commands.
  586. //
  587. //  PARAMETERS:
  588. //    hwnd     - The window.
  589. //    wCommand - IDM_CUT, IDM_COPY, IDM_CLEAR IDM_PASTE, IDM_UNDO
  590. //    wNotify  - Notification number (unused)
  591. //    hwndCtrl - NULL (unused)
  592. //
  593. //  RETURN VALUE:
  594. //    Always returns 0 - command handled.
  595. //
  596. //  COMMENTS:
  597. //    Translate the commands into messages and send them to the edit control.
  598. //
  599.  
  600. #pragma argsused
  601. LRESULT CmdClip(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  602. {
  603.      WORD wMessage = 0;
  604.  
  605.      switch (wCommand)
  606.      {
  607.           case IDM_EDITCUT:   wMessage = WM_CUT;   break;
  608.           case IDM_EDITCOPY:  wMessage = WM_COPY;  break;
  609.         case IDM_EDITPASTE: wMessage = WM_PASTE; break;
  610.         case IDM_EDITCLEAR: wMessage = WM_CLEAR; break;
  611.         case IDM_EDITUNDO:  wMessage = EM_UNDO;  break;
  612.     }
  613.  
  614.     SendMessage(GetEditWindow(NULL), wMessage, 0, 0L);
  615.     return 0;
  616. }
  617.  
  618.  
  619. //
  620. //  FUNCTION: CmdWindowTile(HWND, WORD, WORD, HWND)
  621. //
  622. //  PURPOSE: To tile the mdi child windows.
  623. //
  624. //  PARAMETERS:
  625. //    hwnd - The window handling the command.
  626. //    wCommand - IDM_WINDOWTILE (unused).
  627. //    hwndCtrl - NULL (unused).
  628. //
  629. //  RETURN VALUE:
  630. //    Always returns 0 - command handled.
  631. //
  632. //  COMMENTS:
  633. //
  634. //
  635.  
  636. #pragma argsused
  637. LRESULT CmdWindowTile(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  638. {
  639.     SendMessage(hwndMDIClient, WM_MDITILE, 0, 0L);
  640.  
  641.     return 0;
  642. }
  643.  
  644.  
  645. //
  646. //  FUNCTION: CmdWindowCascade(HWND, WORD, WORD, HWND)
  647. //
  648. //  PURPOSE: To cascade the mdi child windows.
  649. //
  650. //  PARAMETERS:
  651. //    hwnd - The window handling the command.
  652. //    wCommand - IDM_WINDOWCASCADE (unused).
  653. //    hwndCtrl - NULL (unused).
  654. //
  655. //  RETURN VALUE:
  656. //    Always returns 0 - command handled.
  657. //
  658. //  COMMENTS:
  659. //
  660. //
  661.  
  662. #pragma argsused
  663. LRESULT CmdWindowCascade(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  664. {
  665.     SendMessage(hwndMDIClient, WM_MDICASCADE, 0, 0L);
  666.  
  667.     return 0;
  668. }
  669.  
  670.  
  671. //
  672. //  FUNCTION: CmdWindowIcons(HWND, WORD, WORD, HWND)
  673. //
  674. //  PURPOSE: To arrage the mdi child icons.
  675. //
  676. //  PARAMETERS:
  677. //    hwnd - The window handling the command.
  678. //    wCommand - IDM_WINDOWICONS (unused).
  679. //    hwndCtrl - NULL (unused).
  680. //
  681. //  RETURN VALUE:
  682. //    Always returns 0 - command handled.
  683. //
  684. //  COMMENTS:
  685. //
  686. //
  687.  
  688. #pragma argsused
  689. LRESULT CmdWindowIcons(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  690. {
  691.     SendMessage(hwndMDIClient, WM_MDIICONARRANGE, 0, 0L);
  692.  
  693.     return 0;
  694. }
  695.  
  696.  
  697. //
  698. //  FUNCTION: CmdWindowCloseAll(HWND, WORD, WORD, HWND)
  699. //
  700. //  PURPOSE: To close all of the mdi child windows.
  701. //
  702. //  PARAMETERS:
  703. //    hwnd - The window handling the command.
  704. //    wCommand - IDM_WINDOWCLOSEALL (unused).
  705. //    wNotify  - Notification number (unused)
  706. //    hwndCtrl - NULL (unused).
  707. //
  708. //  RETURN VALUE:
  709. //    Always returns 0 - command handled.
  710. //
  711. //  COMMENTS:
  712. //
  713. //
  714.  
  715. #pragma argsused
  716. #pragma warn -pia
  717. LRESULT CmdWindowCloseAll(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  718. {
  719.      HWND hwndT;
  720.      BOOL bCancel = 0;
  721.  
  722.      // As long as the MDI client has a child, destroy it
  723.      while (!bCancel && (hwndT = GetWindow(hwndMDIClient, GW_CHILD)))
  724.      {
  725.           // Skip the icon and title windows
  726.           while (hwndT && GetWindow(hwndT, GW_OWNER))
  727.                 hwndT = GetWindow(hwndT, GW_HWNDNEXT);
  728.  
  729.           if (hwndT)
  730.         {
  731.                 if (!QuerySaveFile(hwnd))
  732.                     bCancel=TRUE;
  733.                 else
  734.                     SendMessage(hwndMDIClient, WM_MDIDESTROY, (WPARAM)hwndT, 0L);
  735.           }
  736.           else
  737.                 break;
  738.      }
  739.  
  740.      return bCancel;
  741. }
  742. #pragma warn .pia
  743.  
  744.  
  745. //
  746. //  FUNCTION: CmdExit(HWND, WORD, WORD, HWND)
  747. //
  748. //  PURPOSE: Exit the application.
  749. //
  750. //  PARAMETERS:
  751. //    hwnd     - The window.
  752. //    wCommand - IDM_EXIT (unused)
  753. //    wNotify  - Notification number (unused)
  754. //    hwndCtrl - NULL (unused)
  755. //
  756. //  RETURN VALUE:
  757. //    Always returns 0 - command handled.
  758. //
  759. //  COMMENTS:
  760. //
  761. //
  762.  
  763. #pragma argsused
  764. LRESULT CmdExit(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  765. {
  766.     BOOL bCancel;
  767.  
  768.     bCancel = SendMessage(hwnd, WM_COMMAND, IDM_WINDOWCLOSEALL, 0L);
  769.  
  770.     if (!bCancel)
  771.        DestroyWindow(hwnd);
  772.     return 0;
  773. }
  774.  
  775. //
  776. //  FUNCTION: GetFName(VOID)
  777. //
  778. //  PURPOSE: Get the current file name.
  779. //
  780. //  PARAMETERS:
  781. //    NONE
  782. //
  783. //  RETURN VALUE:
  784. //    The full path name of the current file.
  785. //
  786. //  COMMENTS:
  787. //
  788. //
  789.  
  790. char *GetFName(VOID)
  791. {
  792.      return szFName;
  793. }
  794.  
  795.