home *** CD-ROM | disk | FTP | other *** search
/ Mastering Microsoft Visual C++ 4 (2nd Edition) / VisualC4.ISO / minidrw5 / minidraw.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-30  |  8.0 KB  |  286 lines

  1. // MiniDraw.cpp : Defines the class behaviors for the application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "MiniDraw.h"
  6.  
  7. #include "MainFrm.h"
  8. #include "MiniDDoc.h"
  9. #include "MiniDrVw.h"
  10.  
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16.  
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CMiniDrawApp
  19.  
  20. BEGIN_MESSAGE_MAP(CMiniDrawApp, CWinApp)
  21.    //{{AFX_MSG_MAP(CMiniDrawApp)
  22.    ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  23.    ON_COMMAND(ID_LINE_DOUBLE, OnLineDouble)
  24.    ON_UPDATE_COMMAND_UI(ID_LINE_DOUBLE, OnUpdateLineDouble)
  25.    ON_COMMAND(ID_LINE_SINGLE, OnLineSingle)
  26.    ON_UPDATE_COMMAND_UI(ID_LINE_SINGLE, OnUpdateLineSingle)
  27.    ON_COMMAND(ID_LINE_TRIPLE, OnLineTriple)
  28.    ON_UPDATE_COMMAND_UI(ID_LINE_TRIPLE, OnUpdateLineTriple)
  29.    ON_COMMAND(ID_TOOLS_CIRCLE, OnToolsCircle)
  30.    ON_UPDATE_COMMAND_UI(ID_TOOLS_CIRCLE, OnUpdateToolsCircle)
  31.    ON_COMMAND(ID_TOOLS_CIRCLEFILL, OnToolsCirclefill)
  32.    ON_UPDATE_COMMAND_UI(ID_TOOLS_CIRCLEFILL, OnUpdateToolsCirclefill)
  33.    ON_COMMAND(ID_TOOLS_LINE, OnToolsLine)
  34.    ON_UPDATE_COMMAND_UI(ID_TOOLS_LINE, OnUpdateToolsLine)
  35.    ON_COMMAND(ID_TOOLS_RECTANGLE, OnToolsRectangle)
  36.    ON_UPDATE_COMMAND_UI(ID_TOOLS_RECTANGLE, OnUpdateToolsRectangle)
  37.    ON_COMMAND(ID_TOOLS_RECTFILL, OnToolsRectfill)
  38.    ON_UPDATE_COMMAND_UI(ID_TOOLS_RECTFILL, OnUpdateToolsRectfill)
  39.    ON_COMMAND(ID_TOOLS_RECTROUND, OnToolsRectround)
  40.    ON_UPDATE_COMMAND_UI(ID_TOOLS_RECTROUND, OnUpdateToolsRectround)
  41.    ON_COMMAND(ID_TOOLS_RECTROUNDFILL, OnToolsRectroundfill)
  42.    ON_UPDATE_COMMAND_UI(ID_TOOLS_RECTROUNDFILL, OnUpdateToolsRectroundfill)
  43.    //}}AFX_MSG_MAP
  44.    // Standard file based document commands
  45.    ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  46.    ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  47. END_MESSAGE_MAP()
  48.  
  49. /////////////////////////////////////////////////////////////////////////////
  50. // CMiniDrawApp construction
  51.  
  52. CMiniDrawApp::CMiniDrawApp()
  53. {
  54.    // TODO: add construction code here,
  55.    // Place all significant initialization in InitInstance
  56.  
  57.    m_CurrentThickness = 1;
  58.    m_CurrentTool = ID_TOOLS_LINE;
  59. }
  60.  
  61. /////////////////////////////////////////////////////////////////////////////
  62. // The one and only CMiniDrawApp object
  63.  
  64. CMiniDrawApp theApp;
  65.  
  66. /////////////////////////////////////////////////////////////////////////////
  67. // CMiniDrawApp initialization
  68.  
  69. BOOL CMiniDrawApp::InitInstance()
  70. {
  71.    // Standard initialization
  72.    // If you are not using these features and wish to reduce the size
  73.    //  of your final executable, you should remove from the following
  74.    //  the specific initialization routines you do not need.
  75.  
  76. #ifdef _AFXDLL
  77.    Enable3dControls();        // Call this when using MFC in a shared DLL
  78. #else
  79.    Enable3dControlsStatic();  // Call this when linking to MFC statically
  80. #endif
  81.  
  82.    LoadStdProfileSettings();  // Load standard INI file options (including MRU)
  83.  
  84.    // Register the application's document templates.  Document templates
  85.    //  serve as the connection between documents, frame windows and views.
  86.  
  87.    CSingleDocTemplate* pDocTemplate;
  88.    pDocTemplate = new CSingleDocTemplate(
  89.       IDR_MAINFRAME,
  90.       RUNTIME_CLASS(CMiniDrawDoc),
  91.       RUNTIME_CLASS(CMainFrame),       // main SDI frame window
  92.       RUNTIME_CLASS(CMiniDrawView));
  93.    AddDocTemplate(pDocTemplate);
  94.  
  95.    EnableShellOpen ();
  96.    RegisterShellFileTypes ();
  97.  
  98.    // Parse command line for standard shell commands, DDE, file open
  99.    CCommandLineInfo cmdInfo;
  100.    ParseCommandLine(cmdInfo);
  101.  
  102.    // Dispatch commands specified on the command line
  103.    if (!ProcessShellCommand(cmdInfo))
  104.       return FALSE;
  105.  
  106.    m_pMainWnd->DragAcceptFiles ();
  107.  
  108.    return TRUE;
  109. }
  110.  
  111. /////////////////////////////////////////////////////////////////////////////
  112. // CAboutDlg dialog used for App About
  113.  
  114. class CAboutDlg : public CDialog
  115. {
  116. public:
  117.    CAboutDlg();
  118.  
  119. // Dialog Data
  120.    //{{AFX_DATA(CAboutDlg)
  121.    enum { IDD = IDD_ABOUTBOX };
  122.    //}}AFX_DATA
  123.  
  124.    // ClassWizard generated virtual function overrides
  125.    //{{AFX_VIRTUAL(CAboutDlg)
  126.    protected:
  127.    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  128.    //}}AFX_VIRTUAL
  129.  
  130. // Implementation
  131. protected:
  132.    //{{AFX_MSG(CAboutDlg)
  133.       // No message handlers
  134.    //}}AFX_MSG
  135.    DECLARE_MESSAGE_MAP()
  136. };
  137.  
  138. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  139. {
  140.    //{{AFX_DATA_INIT(CAboutDlg)
  141.    //}}AFX_DATA_INIT
  142. }
  143.  
  144. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  145. {
  146.    CDialog::DoDataExchange(pDX);
  147.    //{{AFX_DATA_MAP(CAboutDlg)
  148.    //}}AFX_DATA_MAP
  149. }
  150.  
  151. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  152.    //{{AFX_MSG_MAP(CAboutDlg)
  153.       // No message handlers
  154.    //}}AFX_MSG_MAP
  155. END_MESSAGE_MAP()
  156.  
  157. // App command to run the dialog
  158. void CMiniDrawApp::OnAppAbout()
  159. {
  160.    CAboutDlg aboutDlg;
  161.    aboutDlg.DoModal();
  162. }
  163.  
  164. /////////////////////////////////////////////////////////////////////////////
  165. // CMiniDrawApp commands
  166.  
  167. void CMiniDrawApp::OnLineDouble() 
  168. {
  169.    // TODO: Add your command handler code here
  170.    m_CurrentThickness = 2; 
  171. }
  172.  
  173. void CMiniDrawApp::OnUpdateLineDouble(CCmdUI* pCmdUI) 
  174. {
  175.    // TODO: Add your command update UI handler code here
  176.    pCmdUI->SetCheck (m_CurrentThickness == 2 ? 1 : 0);   
  177. }
  178.  
  179. void CMiniDrawApp::OnLineSingle() 
  180. {
  181.    // TODO: Add your command handler code here
  182.    m_CurrentThickness = 1; 
  183. }
  184.  
  185. void CMiniDrawApp::OnUpdateLineSingle(CCmdUI* pCmdUI) 
  186. {
  187.    // TODO: Add your command update UI handler code here
  188.    pCmdUI->SetCheck (m_CurrentThickness == 1 ? 1 : 0);
  189. }
  190.  
  191. void CMiniDrawApp::OnLineTriple() 
  192. {
  193.    // TODO: Add your command handler code here
  194.    m_CurrentThickness = 3; 
  195. }
  196.  
  197. void CMiniDrawApp::OnUpdateLineTriple(CCmdUI* pCmdUI) 
  198. {
  199.    // TODO: Add your command update UI handler code here
  200.    pCmdUI->SetCheck (m_CurrentThickness == 3 ? 1 : 0);
  201. }
  202.  
  203. void CMiniDrawApp::OnToolsCircle() 
  204. {
  205.    // TODO: Add your command handler code here
  206.    m_CurrentTool = ID_TOOLS_CIRCLE;
  207. }
  208.  
  209. void CMiniDrawApp::OnUpdateToolsCircle(CCmdUI* pCmdUI) 
  210. {
  211.    // TODO: Add your command update UI handler code here
  212.    pCmdUI->SetCheck (m_CurrentTool == ID_TOOLS_CIRCLE ? 1 : 0);
  213. }
  214.  
  215. void CMiniDrawApp::OnToolsCirclefill() 
  216. {
  217.    // TODO: Add your command handler code here
  218.    m_CurrentTool = ID_TOOLS_CIRCLEFILL;   
  219. }
  220.  
  221. void CMiniDrawApp::OnUpdateToolsCirclefill(CCmdUI* pCmdUI) 
  222. {
  223.    // TODO: Add your command update UI handler code here
  224.    pCmdUI->SetCheck (m_CurrentTool == ID_TOOLS_CIRCLEFILL ? 1 : 0);
  225. }
  226.  
  227. void CMiniDrawApp::OnToolsLine() 
  228. {
  229.    // TODO: Add your command handler code here
  230.    m_CurrentTool = ID_TOOLS_LINE;   
  231. }
  232.  
  233. void CMiniDrawApp::OnUpdateToolsLine(CCmdUI* pCmdUI) 
  234. {
  235.    // TODO: Add your command update UI handler code here
  236.    pCmdUI->SetCheck (m_CurrentTool == ID_TOOLS_LINE ? 1 : 0);
  237. }
  238.  
  239. void CMiniDrawApp::OnToolsRectangle() 
  240. {
  241.    // TODO: Add your command handler code here
  242.    m_CurrentTool = ID_TOOLS_RECTANGLE;
  243. }
  244.  
  245. void CMiniDrawApp::OnUpdateToolsRectangle(CCmdUI* pCmdUI) 
  246. {
  247.    // TODO: Add your command update UI handler code here
  248.    pCmdUI->SetCheck (m_CurrentTool == ID_TOOLS_RECTANGLE ? 1 : 0);
  249. }
  250.  
  251. void CMiniDrawApp::OnToolsRectfill() 
  252. {
  253.    // TODO: Add your command handler code here
  254.    m_CurrentTool = ID_TOOLS_RECTFILL;  
  255. }
  256.  
  257. void CMiniDrawApp::OnUpdateToolsRectfill(CCmdUI* pCmdUI) 
  258. {
  259.    // TODO: Add your command update UI handler code here
  260.    pCmdUI->SetCheck (m_CurrentTool == ID_TOOLS_RECTFILL ? 1 : 0);
  261. }
  262.  
  263. void CMiniDrawApp::OnToolsRectround() 
  264. {
  265.    // TODO: Add your command handler code here
  266.    m_CurrentTool = ID_TOOLS_RECTROUND; 
  267. }
  268.  
  269. void CMiniDrawApp::OnUpdateToolsRectround(CCmdUI* pCmdUI) 
  270. {
  271.    // TODO: Add your command update UI handler code here
  272.    pCmdUI->SetCheck (m_CurrentTool == ID_TOOLS_RECTROUND ? 1 : 0);
  273. }
  274.  
  275. void CMiniDrawApp::OnToolsRectroundfill() 
  276. {
  277.    // TODO: Add your command handler code here
  278.    m_CurrentTool = ID_TOOLS_RECTROUNDFILL;   
  279. }
  280.  
  281. void CMiniDrawApp::OnUpdateToolsRectroundfill(CCmdUI* pCmdUI) 
  282. {
  283.    // TODO: Add your command update UI handler code here
  284.    pCmdUI->SetCheck (m_CurrentTool == ID_TOOLS_RECTROUNDFILL ? 1 : 0);  
  285. }
  286.