home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / tybc4 / xped1 / xped1app.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-12  |  3.8 KB  |  179 lines

  1. /*  Project xped1
  2.     
  3.     Copyright ⌐ 1993. All Rights Reserved.
  4.  
  5.     SUBSYSTEM:    xped1.exe Application
  6.     FILE:         xped1app.cpp
  7.     AUTHOR:       
  8.  
  9.  
  10.     OVERVIEW
  11.     ========
  12.     Source file for implementation of XpEd1App (TApplication).      
  13. */
  14.  
  15.  
  16. #include <owl\owlpch.h>
  17. #pragma hdrstop
  18.  
  19.  
  20. #include "xped1app.h"
  21. #include "xped1abd.h"                        // Definition of about dialog.       
  22.  
  23.  
  24. //{{XpEd1App Implementation}}
  25.  
  26.  
  27. //
  28. // Build a response table for all messages/commands handled
  29. // by the application.
  30. //
  31. DEFINE_RESPONSE_TABLE1(XpEd1App, TApplication)
  32. //{{XpEd1AppRSP_TBL_BEGIN}}
  33.     EV_COMMAND(CM_FILENEW, CmFileNew),
  34.     EV_COMMAND(CM_FILEOPEN, CmFileOpen),
  35.     EV_COMMAND(CM_FILECLOSE, CmFileClose),
  36.     EV_COMMAND(CM_HELPABOUT, CmHelpAbout),
  37. //{{XpEd1AppRSP_TBL_END}}
  38. END_RESPONSE_TABLE;
  39.  
  40.  
  41. //
  42. // FrameWindow must be derived to override Paint for Preview and Print.
  43. //
  44. class SDIDecFrame : public TDecoratedFrame {
  45. public:
  46.     SDIDecFrame (TWindow *parent, const char far *title, TWindow *clientWnd, BOOL trackMenuSelection = FALSE, TModule *module = 0) :
  47.             TDecoratedFrame(parent, title, clientWnd, trackMenuSelection, module)
  48.       {  }
  49.     ~SDIDecFrame ()
  50.       {  }
  51. };
  52.  
  53.  
  54. //////////////////////////////////////////////////////////
  55. // XpEd1App
  56. // =====
  57. //
  58. XpEd1App::XpEd1App () : TApplication("xped1")
  59. {
  60.  
  61.     // Common file file flags and filters for Open/Save As dialogs.  Filename and directory are
  62.     // computed in the member functions CmFileOpen, and CmFileSaveAs.
  63.     FileData.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
  64.     FileData.SetFilter("All Files (*.*)|*.*|");
  65.  
  66.     // INSERT>> Your constructor code here.
  67.  
  68. }
  69.  
  70.  
  71. XpEd1App::~XpEd1App ()
  72. {
  73.     // INSERT>> Your destructor code here.
  74.  
  75. }
  76.  
  77.  
  78. //////////////////////////////////////////////////////////
  79. // XpEd1App
  80. // =====
  81. // Application intialization.
  82. //
  83. void XpEd1App::InitMainWindow ()
  84. {
  85.     Client = new TEditFile(0, 0, 0);
  86.     SDIDecFrame *frame = new SDIDecFrame(0, GetName(), Client, FALSE);
  87.  
  88.     nCmdShow = nCmdShow != SW_SHOWMINIMIZED ? SW_SHOWNORMAL : nCmdShow;
  89.  
  90.     //
  91.     // Assign ICON w/ this application.
  92.     //
  93.     frame->SetIcon(this, IDI_SDIAPPLICATION);
  94.  
  95.     //
  96.     // Menu associated with window and accelerator table associated with table.
  97.     //
  98.     frame->AssignMenu(SDI_MENU);
  99.     
  100.     //
  101.     // Associate with the accelerator table.
  102.     //
  103.     frame->Attr.AccelTable = SDI_MENU;
  104.  
  105.   
  106.     MainWindow = frame;
  107.  
  108. }
  109.  
  110.  
  111. //////////////////////////////////////////////////////////
  112. // XpEd1App
  113. // ===========
  114. // Menu File New command
  115. void XpEd1App::CmFileNew ()
  116. {
  117.     Client->NewFile();
  118. }
  119.  
  120.  
  121. //////////////////////////////////////////////////////////
  122. // XpEd1App
  123. // ===========
  124. // Menu File Open command
  125. void XpEd1App::CmFileOpen ()
  126. {
  127.     //
  128.     // Display standard Open dialog box to select a file name.
  129.     //
  130.     *FileData.FileName = 0;
  131.     if (Client->CanClose())
  132.         if (TFileOpenDialog(MainWindow, FileData).Execute() == IDOK)
  133.             OpenFile();
  134. }
  135.  
  136.  
  137. void XpEd1App::OpenFile (const char *fileName)
  138. {
  139.     if (fileName)
  140.         lstrcpy(FileData.FileName, fileName);
  141.  
  142.     Client->ReplaceWith(FileData.FileName);
  143. }
  144.  
  145.  
  146. //////////////////////////////////////////////////////////
  147. // XpEd1App
  148. // =====
  149. // Menu File Close command
  150. void XpEd1App::CmFileClose ()
  151. {
  152.      if (Client->CanClose())
  153.              Client->DeleteSubText(0, UINT(-1));
  154. }
  155.  
  156.  
  157. //////////////////////////////////////////////////////////
  158. // XpEd1App
  159. // ===========
  160. // Menu Help About xped1.exe command
  161. void XpEd1App::CmHelpAbout ()
  162. {
  163.     //
  164.     // Show the modal dialog.
  165.     //
  166.     XpEd1AboutDlg(MainWindow).Execute();
  167. }
  168.  
  169.  
  170. int OwlMain (int , char* [])
  171. {
  172.     XpEd1App     App;
  173.     int             result;
  174.  
  175.     result = App.Run();
  176.  
  177.     return result;
  178. }
  179.