home *** CD-ROM | disk | FTP | other *** search
/ Mastering Microsoft Visual C++ 4 (2nd Edition) / VisualC4.ISO / minidrw6 / minidraw.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-30  |  12.3 KB  |  428 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.    ON_COMMAND(ID_COLOR_BLACK, OnColorBlack)
  44.    ON_UPDATE_COMMAND_UI(ID_COLOR_BLACK, OnUpdateColorBlack)
  45.    ON_COMMAND(ID_COLOR_BLUE, OnColorBlue)
  46.    ON_UPDATE_COMMAND_UI(ID_COLOR_BLUE, OnUpdateColorBlue)
  47.    ON_COMMAND(ID_COLOR_CUSTOM, OnColorCustom)
  48.    ON_UPDATE_COMMAND_UI(ID_COLOR_CUSTOM, OnUpdateColorCustom)
  49.    ON_COMMAND(ID_COLOR_CYAN, OnColorCyan)
  50.    ON_UPDATE_COMMAND_UI(ID_COLOR_CYAN, OnUpdateColorCyan)
  51.    ON_COMMAND(ID_COLOR_GREEN, OnColorGreen)
  52.    ON_UPDATE_COMMAND_UI(ID_COLOR_GREEN, OnUpdateColorGreen)
  53.    ON_COMMAND(ID_COLOR_MAGENTA, OnColorMagenta)
  54.    ON_UPDATE_COMMAND_UI(ID_COLOR_MAGENTA, OnUpdateColorMagenta)
  55.    ON_COMMAND(ID_COLOR_RED, OnColorRed)
  56.    ON_UPDATE_COMMAND_UI(ID_COLOR_RED, OnUpdateColorRed)
  57.    ON_COMMAND(ID_COLOR_WHITE, OnColorWhite)
  58.    ON_UPDATE_COMMAND_UI(ID_COLOR_WHITE, OnUpdateColorWhite)
  59.    ON_COMMAND(ID_COLOR_YELLOW, OnColorYellow)
  60.    ON_UPDATE_COMMAND_UI(ID_COLOR_YELLOW, OnUpdateColorYellow)
  61.    //}}AFX_MSG_MAP
  62.    // Standard file based document commands
  63.    ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  64.    ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  65. END_MESSAGE_MAP()
  66.  
  67. /////////////////////////////////////////////////////////////////////////////
  68. // CMiniDrawApp construction
  69.  
  70. CMiniDrawApp::CMiniDrawApp()
  71. {
  72.    // TODO: add construction code here,
  73.    // Place all significant initialization in InitInstance
  74.  
  75.    m_CurrentColor = RGB (0,0,0);
  76.    m_CurrentThickness = 1;
  77.    m_CurrentTool = ID_TOOLS_LINE;
  78.    m_IdxColorCmd = ID_COLOR_BLACK;
  79. }
  80.  
  81. /////////////////////////////////////////////////////////////////////////////
  82. // The one and only CMiniDrawApp object
  83.  
  84. CMiniDrawApp theApp;
  85.  
  86. /////////////////////////////////////////////////////////////////////////////
  87. // CMiniDrawApp initialization
  88.  
  89. BOOL CMiniDrawApp::InitInstance()
  90. {
  91.    // Standard initialization
  92.    // If you are not using these features and wish to reduce the size
  93.    //  of your final executable, you should remove from the following
  94.    //  the specific initialization routines you do not need.
  95.  
  96. #ifdef _AFXDLL
  97.    Enable3dControls();        // Call this when using MFC in a shared DLL
  98. #else
  99.    Enable3dControlsStatic();  // Call this when linking to MFC statically
  100. #endif
  101.  
  102.    LoadStdProfileSettings();  // Load standard INI file options (including MRU)
  103.  
  104.    // Register the application's document templates.  Document templates
  105.    //  serve as the connection between documents, frame windows and views.
  106.  
  107.    CSingleDocTemplate* pDocTemplate;
  108.    pDocTemplate = new CSingleDocTemplate(
  109.       IDR_MAINFRAME,
  110.       RUNTIME_CLASS(CMiniDrawDoc),
  111.       RUNTIME_CLASS(CMainFrame),       // main SDI frame window
  112.       RUNTIME_CLASS(CMiniDrawView));
  113.    AddDocTemplate(pDocTemplate);
  114.  
  115.    EnableShellOpen ();
  116.    RegisterShellFileTypes ();
  117.  
  118.    // Parse command line for standard shell commands, DDE, file open
  119.    CCommandLineInfo cmdInfo;
  120.    ParseCommandLine(cmdInfo);
  121.  
  122.    // Dispatch commands specified on the command line
  123.    if (!ProcessShellCommand(cmdInfo))
  124.       return FALSE;
  125.  
  126.    m_pMainWnd->DragAcceptFiles ();
  127.  
  128.    return TRUE;
  129. }
  130.  
  131. /////////////////////////////////////////////////////////////////////////////
  132. // CAboutDlg dialog used for App About
  133.  
  134. class CAboutDlg : public CDialog
  135. {
  136. public:
  137.    CAboutDlg();
  138.  
  139. // Dialog Data
  140.    //{{AFX_DATA(CAboutDlg)
  141.    enum { IDD = IDD_ABOUTBOX };
  142.    //}}AFX_DATA
  143.  
  144.    // ClassWizard generated virtual function overrides
  145.    //{{AFX_VIRTUAL(CAboutDlg)
  146.    protected:
  147.    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  148.    //}}AFX_VIRTUAL
  149.  
  150. // Implementation
  151. protected:
  152.    //{{AFX_MSG(CAboutDlg)
  153.       // No message handlers
  154.    //}}AFX_MSG
  155.    DECLARE_MESSAGE_MAP()
  156. };
  157.  
  158. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  159. {
  160.    //{{AFX_DATA_INIT(CAboutDlg)
  161.    //}}AFX_DATA_INIT
  162. }
  163.  
  164. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  165. {
  166.    CDialog::DoDataExchange(pDX);
  167.    //{{AFX_DATA_MAP(CAboutDlg)
  168.    //}}AFX_DATA_MAP
  169. }
  170.  
  171. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  172.    //{{AFX_MSG_MAP(CAboutDlg)
  173.       // No message handlers
  174.    //}}AFX_MSG_MAP
  175. END_MESSAGE_MAP()
  176.  
  177. // App command to run the dialog
  178. void CMiniDrawApp::OnAppAbout()
  179. {
  180.    CAboutDlg aboutDlg;
  181.    aboutDlg.DoModal();
  182. }
  183.  
  184. /////////////////////////////////////////////////////////////////////////////
  185. // CMiniDrawApp commands
  186.  
  187. void CMiniDrawApp::OnLineDouble() 
  188. {
  189.    // TODO: Add your command handler code here
  190.    m_CurrentThickness = 2; 
  191. }
  192.  
  193. void CMiniDrawApp::OnUpdateLineDouble(CCmdUI* pCmdUI) 
  194. {
  195.    // TODO: Add your command update UI handler code here
  196.    pCmdUI->SetCheck (m_CurrentThickness == 2 ? 1 : 0);   
  197. }
  198.  
  199. void CMiniDrawApp::OnLineSingle() 
  200. {
  201.    // TODO: Add your command handler code here
  202.    m_CurrentThickness = 1; 
  203. }
  204.  
  205. void CMiniDrawApp::OnUpdateLineSingle(CCmdUI* pCmdUI) 
  206. {
  207.    // TODO: Add your command update UI handler code here
  208.    pCmdUI->SetCheck (m_CurrentThickness == 1 ? 1 : 0);
  209. }
  210.  
  211. void CMiniDrawApp::OnLineTriple() 
  212. {
  213.    // TODO: Add your command handler code here
  214.    m_CurrentThickness = 3; 
  215. }
  216.  
  217. void CMiniDrawApp::OnUpdateLineTriple(CCmdUI* pCmdUI) 
  218. {
  219.    // TODO: Add your command update UI handler code here
  220.    pCmdUI->SetCheck (m_CurrentThickness == 3 ? 1 : 0);
  221. }
  222.  
  223. void CMiniDrawApp::OnToolsCircle() 
  224. {
  225.    // TODO: Add your command handler code here
  226.    m_CurrentTool = ID_TOOLS_CIRCLE;
  227. }
  228.  
  229. void CMiniDrawApp::OnUpdateToolsCircle(CCmdUI* pCmdUI) 
  230. {
  231.    // TODO: Add your command update UI handler code here
  232.    pCmdUI->SetCheck (m_CurrentTool == ID_TOOLS_CIRCLE ? 1 : 0);
  233. }
  234.  
  235. void CMiniDrawApp::OnToolsCirclefill() 
  236. {
  237.    // TODO: Add your command handler code here
  238.    m_CurrentTool = ID_TOOLS_CIRCLEFILL;   
  239. }
  240.  
  241. void CMiniDrawApp::OnUpdateToolsCirclefill(CCmdUI* pCmdUI) 
  242. {
  243.    // TODO: Add your command update UI handler code here
  244.    pCmdUI->SetCheck (m_CurrentTool == ID_TOOLS_CIRCLEFILL ? 1 : 0);
  245. }
  246.  
  247. void CMiniDrawApp::OnToolsLine() 
  248. {
  249.    // TODO: Add your command handler code here
  250.    m_CurrentTool = ID_TOOLS_LINE;   
  251. }
  252.  
  253. void CMiniDrawApp::OnUpdateToolsLine(CCmdUI* pCmdUI) 
  254. {
  255.    // TODO: Add your command update UI handler code here
  256.    pCmdUI->SetCheck (m_CurrentTool == ID_TOOLS_LINE ? 1 : 0);
  257. }
  258.  
  259. void CMiniDrawApp::OnToolsRectangle() 
  260. {
  261.    // TODO: Add your command handler code here
  262.    m_CurrentTool = ID_TOOLS_RECTANGLE;
  263. }
  264.  
  265. void CMiniDrawApp::OnUpdateToolsRectangle(CCmdUI* pCmdUI) 
  266. {
  267.    // TODO: Add your command update UI handler code here
  268.    pCmdUI->SetCheck (m_CurrentTool == ID_TOOLS_RECTANGLE ? 1 : 0);
  269. }
  270.  
  271. void CMiniDrawApp::OnToolsRectfill() 
  272. {
  273.    // TODO: Add your command handler code here
  274.    m_CurrentTool = ID_TOOLS_RECTFILL;  
  275. }
  276.  
  277. void CMiniDrawApp::OnUpdateToolsRectfill(CCmdUI* pCmdUI) 
  278. {
  279.    // TODO: Add your command update UI handler code here
  280.    pCmdUI->SetCheck (m_CurrentTool == ID_TOOLS_RECTFILL ? 1 : 0);
  281. }
  282.  
  283. void CMiniDrawApp::OnToolsRectround() 
  284. {
  285.    // TODO: Add your command handler code here
  286.    m_CurrentTool = ID_TOOLS_RECTROUND; 
  287. }
  288.  
  289. void CMiniDrawApp::OnUpdateToolsRectround(CCmdUI* pCmdUI) 
  290. {
  291.    // TODO: Add your command update UI handler code here
  292.    pCmdUI->SetCheck (m_CurrentTool == ID_TOOLS_RECTROUND ? 1 : 0);
  293. }
  294.  
  295. void CMiniDrawApp::OnToolsRectroundfill() 
  296. {
  297.    // TODO: Add your command handler code here
  298.    m_CurrentTool = ID_TOOLS_RECTROUNDFILL;   
  299. }
  300.  
  301. void CMiniDrawApp::OnUpdateToolsRectroundfill(CCmdUI* pCmdUI) 
  302. {
  303.    // TODO: Add your command update UI handler code here
  304.    pCmdUI->SetCheck (m_CurrentTool == ID_TOOLS_RECTROUNDFILL ? 1 : 0);  
  305. }
  306.  
  307. void CMiniDrawApp::OnColorBlack() 
  308. {
  309.    // TODO: Add your command handler code here
  310.    m_CurrentColor = RGB (0,0,0);
  311.    m_IdxColorCmd = ID_COLOR_BLACK;   
  312. }
  313.  
  314. void CMiniDrawApp::OnUpdateColorBlack(CCmdUI* pCmdUI) 
  315. {
  316.    // TODO: Add your command update UI handler code here
  317.    pCmdUI->SetCheck (m_IdxColorCmd == ID_COLOR_BLACK ? 1 : 0); 
  318. }
  319.  
  320. void CMiniDrawApp::OnColorBlue() 
  321. {
  322.    // TODO: Add your command handler code here
  323.    m_CurrentColor = RGB (0,0,255);
  324.    m_IdxColorCmd = ID_COLOR_BLUE;   
  325. }
  326.  
  327. void CMiniDrawApp::OnUpdateColorBlue(CCmdUI* pCmdUI) 
  328. {
  329.    // TODO: Add your command update UI handler code here
  330.    pCmdUI->SetCheck (m_IdxColorCmd == ID_COLOR_BLUE ? 1 : 0);  
  331. }
  332.  
  333. void CMiniDrawApp::OnColorCustom() 
  334. {
  335.    // TODO: Add your command handler code here
  336.    CColorDialog ColorDialog;
  337.    
  338.    if (ColorDialog.DoModal () == IDOK)
  339.       {
  340.       m_CurrentColor = ColorDialog.GetColor ();
  341.       m_IdxColorCmd = ID_COLOR_CUSTOM;
  342.       }
  343. }
  344.  
  345. void CMiniDrawApp::OnUpdateColorCustom(CCmdUI* pCmdUI) 
  346. {
  347.    // TODO: Add your command update UI handler code here
  348.    pCmdUI->SetCheck (m_IdxColorCmd == ID_COLOR_CUSTOM ? 1 : 0);   
  349. }
  350.  
  351. void CMiniDrawApp::OnColorCyan() 
  352. {
  353.    // TODO: Add your command handler code here
  354.    m_CurrentColor = RGB (0,255,255);
  355.    m_IdxColorCmd = ID_COLOR_CYAN;   
  356. }
  357.  
  358. void CMiniDrawApp::OnUpdateColorCyan(CCmdUI* pCmdUI) 
  359. {
  360.    // TODO: Add your command update UI handler code here
  361.    pCmdUI->SetCheck (m_IdxColorCmd == ID_COLOR_CYAN ? 1 : 0);  
  362. }
  363.  
  364. void CMiniDrawApp::OnColorGreen() 
  365. {
  366.    // TODO: Add your command handler code here
  367.    m_CurrentColor = RGB (0,255,0);
  368.    m_IdxColorCmd = ID_COLOR_GREEN;   
  369. }
  370.  
  371. void CMiniDrawApp::OnUpdateColorGreen(CCmdUI* pCmdUI) 
  372. {
  373.    // TODO: Add your command update UI handler code here
  374.    pCmdUI->SetCheck (m_IdxColorCmd == ID_COLOR_GREEN ? 1 : 0); 
  375. }
  376.  
  377. void CMiniDrawApp::OnColorMagenta() 
  378. {
  379.    // TODO: Add your command handler code here
  380.    m_CurrentColor = RGB (255,0,255);
  381.    m_IdxColorCmd = ID_COLOR_MAGENTA;   
  382. }
  383.  
  384. void CMiniDrawApp::OnUpdateColorMagenta(CCmdUI* pCmdUI) 
  385. {
  386.    // TODO: Add your command update UI handler code here
  387.    pCmdUI->SetCheck (m_IdxColorCmd == ID_COLOR_MAGENTA ? 1 : 0);  
  388. }
  389.  
  390. void CMiniDrawApp::OnColorRed() 
  391. {
  392.    // TODO: Add your command handler code here
  393.    m_CurrentColor = RGB (255,0,0);
  394.    m_IdxColorCmd = ID_COLOR_RED;   
  395. }
  396.  
  397. void CMiniDrawApp::OnUpdateColorRed(CCmdUI* pCmdUI) 
  398. {
  399.    // TODO: Add your command update UI handler code here
  400.    pCmdUI->SetCheck (m_IdxColorCmd == ID_COLOR_RED ? 1 : 0);   
  401. }
  402.  
  403. void CMiniDrawApp::OnColorWhite() 
  404. {
  405.    // TODO: Add your command handler code here
  406.    m_CurrentColor = RGB (255,255,255);
  407.    m_IdxColorCmd = ID_COLOR_WHITE;   
  408. }
  409.  
  410. void CMiniDrawApp::OnUpdateColorWhite(CCmdUI* pCmdUI) 
  411. {
  412.    // TODO: Add your command update UI handler code here
  413.    pCmdUI->SetCheck (m_IdxColorCmd == ID_COLOR_WHITE ? 1 : 0); 
  414. }
  415.  
  416. void CMiniDrawApp::OnColorYellow() 
  417. {
  418.    // TODO: Add your command handler code here
  419.    m_CurrentColor = RGB (255,255,0);
  420.    m_IdxColorCmd = ID_COLOR_YELLOW;   
  421. }
  422.  
  423. void CMiniDrawApp::OnUpdateColorYellow(CCmdUI* pCmdUI) 
  424. {
  425.    // TODO: Add your command update UI handler code here
  426.    pCmdUI->SetCheck (m_IdxColorCmd == ID_COLOR_YELLOW ? 1 : 0);   
  427. }
  428.