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