FillRegionDlg.cpp
上传用户:sdpcwz
上传日期:2009-12-14
资源大小:1237k
文件大小:5k
源码类别:

书籍源码

开发平台:

Visual C++

  1. // FillRegionDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "FillRegion.h"
  5. #include "FillRegionDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CAboutDlg dialog used for App About
  13. class CAboutDlg : public CDialog
  14. {
  15. public:
  16. CAboutDlg();
  17. // Dialog Data
  18. //{{AFX_DATA(CAboutDlg)
  19. enum { IDD = IDD_ABOUTBOX };
  20. //}}AFX_DATA
  21. // ClassWizard generated virtual function overrides
  22. //{{AFX_VIRTUAL(CAboutDlg)
  23. protected:
  24. virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  25. //}}AFX_VIRTUAL
  26. // Implementation
  27. protected:
  28. //{{AFX_MSG(CAboutDlg)
  29. //}}AFX_MSG
  30. DECLARE_MESSAGE_MAP()
  31. };
  32. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  33. {
  34. //{{AFX_DATA_INIT(CAboutDlg)
  35. //}}AFX_DATA_INIT
  36. }
  37. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  38. {
  39. CDialog::DoDataExchange(pDX);
  40. //{{AFX_DATA_MAP(CAboutDlg)
  41. //}}AFX_DATA_MAP
  42. }
  43. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  44. //{{AFX_MSG_MAP(CAboutDlg)
  45. // No message handlers
  46. //}}AFX_MSG_MAP
  47. END_MESSAGE_MAP()
  48. /////////////////////////////////////////////////////////////////////////////
  49. // CFillRegionDlg dialog
  50. CFillRegionDlg::CFillRegionDlg(CWnd* pParent /*=NULL*/)
  51. : CDialog(CFillRegionDlg::IDD, pParent)
  52. {
  53. //{{AFX_DATA_INIT(CFillRegionDlg)
  54. // NOTE: the ClassWizard will add member initialization here
  55. //}}AFX_DATA_INIT
  56. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  57. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  58. }
  59. void CFillRegionDlg::DoDataExchange(CDataExchange* pDX)
  60. {
  61. CDialog::DoDataExchange(pDX);
  62. //{{AFX_DATA_MAP(CFillRegionDlg)
  63. // NOTE: the ClassWizard will add DDX and DDV calls here
  64. //}}AFX_DATA_MAP
  65. }
  66. BEGIN_MESSAGE_MAP(CFillRegionDlg, CDialog)
  67. //{{AFX_MSG_MAP(CFillRegionDlg)
  68. ON_WM_SYSCOMMAND()
  69. ON_WM_PAINT()
  70. ON_WM_QUERYDRAGICON()
  71. //}}AFX_MSG_MAP
  72. END_MESSAGE_MAP()
  73. /////////////////////////////////////////////////////////////////////////////
  74. // CFillRegionDlg message handlers
  75. BOOL CFillRegionDlg::OnInitDialog()
  76. {
  77. CDialog::OnInitDialog();
  78. // Add "About..." menu item to system menu.
  79. // IDM_ABOUTBOX must be in the system command range.
  80. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  81. ASSERT(IDM_ABOUTBOX < 0xF000);
  82. CMenu* pSysMenu = GetSystemMenu(FALSE);
  83. if (pSysMenu != NULL)
  84. {
  85. CString strAboutMenu;
  86. strAboutMenu.LoadString(IDS_ABOUTBOX);
  87. if (!strAboutMenu.IsEmpty())
  88. {
  89. pSysMenu->AppendMenu(MF_SEPARATOR);
  90. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  91. }
  92. }
  93. // Set the icon for this dialog.  The framework does this automatically
  94. //  when the application's main window is not a dialog
  95. SetIcon(m_hIcon, TRUE); // Set big icon
  96. SetIcon(m_hIcon, FALSE); // Set small icon
  97. // TODO: Add extra initialization here
  98. return TRUE;  // return TRUE  unless you set the focus to a control
  99. }
  100. void CFillRegionDlg::OnSysCommand(UINT nID, LPARAM lParam)
  101. {
  102. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  103. {
  104. CAboutDlg dlgAbout;
  105. dlgAbout.DoModal();
  106. }
  107. else
  108. {
  109. CDialog::OnSysCommand(nID, lParam);
  110. }
  111. }
  112. // If you add a minimize button to your dialog, you will need the code below
  113. //  to draw the icon.  For MFC applications using the document/view model,
  114. //  this is automatically done for you by the framework.
  115. void CFillRegionDlg::OnPaint() 
  116. {
  117. CPaintDC dc(this); // device context for painting
  118. if (IsIconic())
  119. {
  120. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  121. // Center icon in client rectangle
  122. int cxIcon = GetSystemMetrics(SM_CXICON);
  123. int cyIcon = GetSystemMetrics(SM_CYICON);
  124. CRect rect;
  125. GetClientRect(&rect);
  126. int x = (rect.Width() - cxIcon + 1) / 2;
  127. int y = (rect.Height() - cyIcon + 1) / 2;
  128. // Draw the icon
  129. dc.DrawIcon(x, y, m_hIcon);
  130. }
  131. else
  132. {
  133. CDialog::OnPaint();
  134. }
  135. CBrush brush;
  136. brush.CreateSolidBrush(RGB(128,128,128));
  137. CPen pen;
  138. pen.CreatePen(PS_SOLID,1,RGB(0,0,0));
  139. CPen* pOldPen = dc.SelectObject(&pen);
  140. //画第一个矩形框
  141. dc.MoveTo(50,50);
  142. dc.LineTo(200,50);
  143. dc.LineTo(200,200);
  144. dc.LineTo(50,200);
  145. dc.LineTo(50,50);
  146. dc.MoveTo(100,100);
  147. dc.LineTo(150,100);
  148. dc.LineTo(150,150);
  149. dc.LineTo(100,150);
  150. dc.LineTo(100,100);
  151. //填充第一个矩形框
  152. CBrush* pOldBrush = dc.SelectObject(&brush);
  153. dc.FloodFill(125,125,RGB(0,0,0));
  154. //画第二个矩形框
  155. dc.MoveTo(250,50);
  156. dc.LineTo(400,50);
  157. dc.LineTo(400,200);
  158. dc.LineTo(250,200);
  159. dc.LineTo(250,50);
  160. dc.MoveTo(300,100);
  161. dc.LineTo(350,100);
  162. dc.LineTo(350,150);
  163. dc.LineTo(300,150);
  164. //填充第二个矩形框
  165. dc.FloodFill(325,125,RGB(0,0,0));
  166. dc.SelectObject(pOldBrush);
  167. dc.SelectObject(pOldPen);
  168. }
  169. // The system calls this to obtain the cursor to display while the user drags
  170. //  the minimized window.
  171. HCURSOR CFillRegionDlg::OnQueryDragIcon()
  172. {
  173. return (HCURSOR) m_hIcon;
  174. }