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