eDrawDlg.cpp
上传用户:fjzzwyy
上传日期:2007-01-14
资源大小:244k
文件大小:20k
源码类别:

绘图程序

开发平台:

Visual C++

  1. // eDrawDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "eDraw.h"
  5. #include "eDrawDlg.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. // CEDrawDlg dialog
  50. CEDrawDlg::CEDrawDlg(CWnd* pParent /*=NULL*/)
  51. : CDialog(CEDrawDlg::IDD, pParent)
  52. {
  53. m_BGBrush.CreateSolidBrush(RGB(255,255,255));
  54. //{{AFX_DATA_INIT(CEDrawDlg)
  55. // NOTE: the ClassWizard will add member initialization here
  56. //}}AFX_DATA_INIT
  57. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  58. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  59. }
  60. void CEDrawDlg::DoDataExchange(CDataExchange* pDX)
  61. {
  62. CDialog::DoDataExchange(pDX);
  63. //{{AFX_DATA_MAP(CEDrawDlg)
  64. DDX_Control(pDX, IDC_SBARCTRLAXIS, m_statusAxis);
  65. //}}AFX_DATA_MAP
  66. }
  67. BEGIN_MESSAGE_MAP(CEDrawDlg, CDialog)
  68. //{{AFX_MSG_MAP(CEDrawDlg)
  69. ON_WM_SYSCOMMAND()
  70. ON_WM_PAINT()
  71. ON_WM_QUERYDRAGICON()
  72. ON_WM_MOUSEMOVE()
  73. ON_WM_LBUTTONDOWN()
  74. ON_WM_LBUTTONUP()
  75. ON_WM_CTLCOLOR()
  76. ON_WM_SETCURSOR()
  77. ON_WM_LBUTTONDBLCLK()
  78. //}}AFX_MSG_MAP
  79. ON_MESSAGE(WM_OUTBAR_NOTIFY, OnOutbarNotify)
  80. END_MESSAGE_MAP()
  81. /////////////////////////////////////////////////////////////////////////////
  82. // CEDrawDlg message handlers
  83. BOOL CEDrawDlg::OnInitDialog()
  84. {
  85. CDialog::OnInitDialog();
  86. // Add "About..." menu item to system menu.
  87. // IDM_ABOUTBOX must be in the system command range.
  88. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  89. ASSERT(IDM_ABOUTBOX < 0xF000);
  90. CMenu* pSysMenu = GetSystemMenu(FALSE);
  91. if (pSysMenu != NULL)
  92. {
  93. CString strAboutMenu;
  94. strAboutMenu.LoadString(IDS_ABOUTBOX);
  95. if (!strAboutMenu.IsEmpty())
  96. {
  97. pSysMenu->AppendMenu(MF_SEPARATOR);
  98. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  99. }
  100. }
  101. // Set the icon for this dialog.  The framework does this automatically
  102. //  when the application's main window is not a dialog
  103. SetIcon(m_hIcon, TRUE); // Set big icon
  104. SetIcon(m_hIcon, FALSE); // Set small icon
  105. // TODO: Add extra initialization here
  106. DWORD dwf = CGfxOutBarCtrl::fDragItems|CGfxOutBarCtrl::fEditGroups|CGfxOutBarCtrl::fEditItems|CGfxOutBarCtrl::fRemoveGroups|
  107. CGfxOutBarCtrl::fRemoveItems|CGfxOutBarCtrl::fAddGroups|CGfxOutBarCtrl::fAnimation;
  108. // |CGfxOutBarCtrl::fSelHighlight;
  109. wndBar.Create(WS_CHILD|WS_VISIBLE|WS_CLIPCHILDREN, CRect(550,0,650,550),this,12345 , dwf);
  110. wndBar.SetOwner(this);
  111.     
  112.     CBitmap bm1,bm2,bm3;
  113.     bm1.LoadBitmap(IDB_IMAGELIST);
  114. imaLarge.Create( 36, 36, ILC_COLOR24,8, 8 );
  115. imaLarge.Add(&bm1,RGB(0,0,0));
  116. bm2.LoadBitmap(IDB_IMAGEDISABLELIST);
  117. imaDisable.Create( 36,36,ILC_COLOR24,8,8 );
  118. imaDisable.Add(&bm2,RGB(0,0,0));
  119. bm3.LoadBitmap(IDB_IMAGESUNKENLIST);
  120. imaSunken.Create( 36,36,ILC_COLOR24,8,8 );
  121. imaSunken.Add(&bm3,RGB(255,255,255));
  122. // imaLarge.Create(IDB_IMAGELIST, 36, 0, RGB(127,127,127));
  123. imaSmall.Create(IDB_SMALL_IMAGELIST, 16, 0, RGB(0,128,128));
  124. wndBar.SetImageList(&imaLarge, CGfxOutBarCtrl::fLargeIcon);
  125. wndBar.SetImageList(&imaSmall, CGfxOutBarCtrl::fSmallIcon);
  126. wndBar.SetImageList(&imaDisable, CGfxOutBarCtrl::fDisableIcon);
  127.     wndBar.SetImageList(&imaSunken,CGfxOutBarCtrl::fSunkenIcon);
  128. wndBar.SetAnimationTickCount(20);
  129. wndBar.SetAnimSelHighlight(200);
  130. wndBar.AddFolder("操作", 0);
  131. wndBar.AddFolder("直线", 1);
  132. wndBar.AddFolder("多边形 填充", 2);
  133. wndBar.AddFolder("二次曲线", 3);
  134. wndBar.InsertItem(0, 0, "打开存档", 0, 0,ENABLE);
  135. wndBar.InsertItem(0, 1, "保存档案", 1, 0,ENABLE);
  136. wndBar.InsertItem(0, 2, "擦除部分", 2, 0);
  137. wndBar.InsertItem(0, 3, "擦除全部", 3, 0);
  138. wndBar.InsertItem(0, 4, "设画笔色", 4, 0);
  139. wndBar.InsertItem(0, 5, "关于eDraw", 5, 0);
  140. wndBar.InsertItem(0, 6, "退出程序", 6, 0);
  141. wndBar.InsertItem(1, 0, "自由画线", 7,0);
  142. wndBar.InsertItem(1, 1, "逐点比较法",8,0);
  143. wndBar.InsertItem(1, 2, "DDA算法", 9,0);
  144. wndBar.InsertItem(1, 3, "Bresenham", 10,0);
  145. wndBar.InsertItem(1, 4, "粗线算法", 11,0);
  146. wndBar.InsertItem(1, 5, "虚线算法", 12,0);
  147. wndBar.InsertItem(2, 0, "画多边形", 13, 0);
  148. wndBar.InsertItem(2, 1, "判定凹凸性", 14, 0);
  149. wndBar.InsertItem(2, 2, "种子填充", 15, 0);
  150. wndBar.InsertItem(2, 3, "扫描线填充", 16, 0);
  151. wndBar.InsertItem(2, 4, "边标志填充", 17, 0);
  152. wndBar.InsertItem(3, 0, "画圆", 18, 0);
  153. wndBar.InsertItem(3, 1, "圆弧", 19, 0);
  154. wndBar.InsertItem(3, 2, "椭圆", 20, 0);
  155. wndBar.InsertItem(3, 3, "椭圆弧", 21, 0);
  156. wndBar.InsertItem(3, 4, "抛物线", 22, 0);
  157. wndBar.InsertItem(3, 5, "双曲线", 23, 0);
  158. wndBar.SetItemState(1,1,ENABLE);
  159. wndBar.SetSelFolder(0);
  160. CDC * pDC = GetDC();
  161. CRect clientRect(0,0,550,550);
  162. int cx = clientRect.Width();
  163. int cy = clientRect.Height();
  164.     CDC memDC;
  165. memDC.CreateCompatibleDC(pDC);
  166.     
  167. currentClientBmp.CreateCompatibleBitmap(pDC,
  168. cx,
  169. cy);
  170. memDC.SelectObject(&currentClientBmp);
  171. memDC.PatBlt(0,0,
  172. cx,cy,
  173. RGB(255,255,255));
  174.         
  175. memDC.DeleteDC();
  176. m_isDrawing=false;
  177. m_CurrentPenColor=RGB(0,0,0);
  178. m_CurrentBGColor=RGB(255,255,255);
  179. m_PolyPointCount=0;m_LastPolyPointCount;
  180. m_Step=0;
  181. return TRUE;  // return TRUE  unless you set the focus to a control
  182. }
  183. void CEDrawDlg::OnSysCommand(UINT nID, LPARAM lParam)
  184. {
  185. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  186. {
  187. CAboutDlg dlgAbout;
  188. dlgAbout.DoModal();
  189. }
  190. else
  191. {
  192. CDialog::OnSysCommand(nID, lParam);
  193. }
  194. }
  195. // If you add a minimize button to your dialog, you will need the code below
  196. //  to draw the icon.  For MFC applications using the document/view model,
  197. //  this is automatically done for you by the framework.
  198. void CEDrawDlg::OnPaint() 
  199. {
  200. RestoreClientFromDC();
  201. if (IsIconic())
  202. {
  203. CPaintDC dc(this); // device context for painting
  204. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  205. // Center icon in client rectangle
  206. int cxIcon = GetSystemMetrics(SM_CXICON);
  207. int cyIcon = GetSystemMetrics(SM_CYICON);
  208. CRect rect;
  209. GetClientRect(&rect);
  210. int x = (rect.Width() - cxIcon + 1) / 2;
  211. int y = (rect.Height() - cyIcon + 1) / 2;
  212. // Draw the icon
  213. dc.DrawIcon(x, y, m_hIcon);
  214. }
  215. else
  216. {
  217. CDialog::OnPaint();
  218. }
  219. }
  220. // The system calls this to obtain the cursor to display while the user drags
  221. //  the minimized window.
  222. HCURSOR CEDrawDlg::OnQueryDragIcon()
  223. {
  224. return (HCURSOR) m_hIcon;
  225. }
  226. void CEDrawDlg::OnMouseMove(UINT nFlags, CPoint point) 
  227. {
  228. CDC* pDC=GetDC();
  229. // TODO: Add your message handler code here and/or call default
  230. CString axis;
  231. axis.Format("X=%ld  Y=%ld",point.x,point.y);
  232. m_statusAxis.SetSimpleText(axis);
  233. if (!m_isDrawing) return;
  234. switch (m_DrawMode){
  235. case DRAWMODE_ERASE:
  236. {
  237. m_isDrawing = true;
  238. CPen pen,* oldpen;
  239. pen.CreatePen(PS_SOLID,1,RGB(255,255,255));
  240. oldpen = pDC->SelectObject(&pen);
  241. CBrush brush,* oldbrush;
  242. brush.CreateSolidBrush(RGB(255,255,255));
  243. oldbrush = pDC->SelectObject(&brush);
  244. pDC->Rectangle(point.x,point.y,
  245. point.x+14,point.y+11);
  246.             pDC->SelectObject(oldpen);
  247. pDC->SelectObject(oldbrush);
  248. }
  249. break;
  250. case DRAWMODE_LINE:
  251. if (m_LineMode!=LINEMODE_FREE) 
  252. RestoreClientFromDC();
  253. switch(m_LineMode){
  254. case LINEMODE_FREE:
  255. DrawLine_BresenHam(pDC,StartPoint.x,StartPoint.y,point.x,point.y,m_CurrentPenColor);
  256. StartPoint.x=point.x;StartPoint.y=point.y;
  257. break;
  258. case LINEMODE_BPB:
  259. DrawLine_BPB(pDC,StartPoint.x,StartPoint.y,point.x,point.y,m_CurrentPenColor);
  260. break;
  261. case LINEMODE_DDA:
  262. DrawLine_DDA(pDC,StartPoint.x,StartPoint.y,point.x,point.y,m_CurrentPenColor);
  263. break;
  264. case LINEMODE_BRESENHAM:
  265. DrawLine_BresenHam(pDC,StartPoint.x,StartPoint.y,point.x,point.y,m_CurrentPenColor);
  266. break;
  267. case LINEMODE_BROKEN:
  268. DrawLine_BresenHam_Broken(pDC,StartPoint.x,StartPoint.y,point.x,point.y,m_CurrentPenColor);
  269. break;
  270. case LINEMODE_THICK:
  271. DrawLine_Thick(pDC,StartPoint.x,StartPoint.y,point.x,point.y,10,m_CurrentPenColor);
  272. break;
  273. }
  274. break;
  275. case DRAWMODE_POLY:
  276. RestoreClientFromDC();
  277. if (m_PolyPointCount>0)
  278. DrawLine_BresenHam(pDC,m_PolyPoint[m_PolyPointCount-1].x,m_PolyPoint[m_PolyPointCount-1].y,point.x,point.y,m_CurrentPenColor);
  279. break;
  280. case DRAWMODE_CIRCLE:
  281. {
  282. RestoreClientFromDC();
  283. int minx=StartPoint.x>point.x?point.x:StartPoint.x;
  284. int maxx=StartPoint.x<point.x?point.x:StartPoint.x;
  285. int miny=StartPoint.y>point.y?point.y:StartPoint.y;
  286. int maxy=StartPoint.y<point.y?point.y:StartPoint.y;
  287. if ((maxx-minx)>(maxy-miny))
  288. DrawCircle(pDC,minx+(maxx-minx)/2,
  289. miny+(maxy-miny)/2,(maxx-minx)/2,m_CurrentPenColor);
  290. else
  291. DrawCircle(pDC,minx+(maxx-minx)/2,
  292. miny+(maxy-miny)/2,(maxy-miny)/2,m_CurrentPenColor);
  293. }
  294. break;
  295.     case DRAWMODE_ELLIPSE:
  296. {
  297. RestoreClientFromDC();
  298. int minx=StartPoint.x>point.x?point.x:StartPoint.x;
  299. int maxx=StartPoint.x<point.x?point.x:StartPoint.x;
  300. int miny=StartPoint.y>point.y?point.y:StartPoint.y;
  301. int maxy=StartPoint.y<point.y?point.y:StartPoint.y;
  302. DrawEllipse(pDC,minx+(maxx-minx)/2,
  303. miny+(maxy-miny)/2,(maxx-minx)/2,(maxy-miny)/2,m_CurrentPenColor);
  304. }
  305. break;
  306. case DRAWMODE_PIPO:
  307. {
  308. if (m_Step==2) {
  309.   RestoreClientFromDC();
  310.   DrawPipo(pDC,StartPoint.x,StartPoint.y,point.x,point.y,EndPoint.x,EndPoint.y,m_CurrentPenColor);
  311. }
  312. }
  313. break;
  314.   
  315. }
  316. CDialog::OnMouseMove(nFlags, point);
  317. }
  318. BOOL CEDrawDlg::SaveCurrentClientToDC()
  319. {
  320. CDC * pDC = GetDC();
  321.     CDC memDC;
  322.     CRect clientRect(0,0,550,550);
  323. int cx = clientRect.Width();
  324. int cy = clientRect.Height();
  325.     memDC.CreateCompatibleDC(pDC);
  326. memDC.SelectObject(&currentClientBmp);
  327. memDC.BitBlt(0,0,cx,
  328. cy,pDC,clientRect.left,clientRect.top,SRCCOPY);  
  329. memDC.DeleteDC();
  330.     ReleaseDC(pDC);
  331. return TRUE;
  332. }
  333. BOOL CEDrawDlg::RestoreClientFromDC()
  334. {
  335. CDC * pDC = GetDC();
  336.     CRect clientRect(0,0,550,550);
  337.     
  338. CDC memDC;
  339. memDC.CreateCompatibleDC(pDC);
  340. memDC.SelectObject(&currentClientBmp);
  341. int cx = clientRect.Width();
  342. int cy = clientRect.Height();
  343. pDC->BitBlt(clientRect.left,clientRect.top,cx,cy,
  344. &memDC,0,0,SRCCOPY);
  345. memDC.DeleteDC();
  346. ReleaseDC(pDC);
  347. return TRUE;
  348. }
  349. long CEDrawDlg::OnOutbarNotify(WPARAM wParam, LPARAM lParam)
  350. {
  351. CDC* pDC=GetDC();
  352.   switch (wParam)
  353. {
  354. case NM_OB_ITEMCLICK:   //项双击处理
  355. // cast the lParam to an integer to get the clicked item
  356. {
  357. int index = (int) lParam; //当前双击项的索引值
  358. int curFolder;
  359. curFolder = wndBar.GetSelFolder();  //当前组的索引值
  360. if(wndBar.GetItemState(curFolder,index)==DISABLE)
  361. break;
  362. //以下为要各个功能的接入处
  363. switch(curFolder)
  364. {
  365. case 0:  //operation
  366. switch(index)
  367. {
  368. case 0:  //open
  369. {
  370. CFileDialog Fdlg(TRUE,"BMP",0, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
  371. "位图文件(*.bmp)|*.bmp|所有文件(*.*)|*.*||");
  372. if (Fdlg.DoModal()==IDOK){
  373. bitmap.LoadBMP(Fdlg.GetFileName());
  374. bitmap.DrawImg(pDC,0,0,bitmap.m_Width,bitmap.m_Height);
  375. }
  376. }
  377. SaveCurrentClientToDC();
  378. break;
  379. case 1:
  380. {
  381. CFileDialog FDlg(FALSE,"BMP",0, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
  382. "位图文件(*.bmp)|*.bmp|所有文件(*.*)|*.*||");
  383. if (FDlg.DoModal()==IDOK){
  384. bitmap.SaveBMP(pDC,0,0,bitmap.m_Width,bitmap.m_Height,FDlg.GetFileName());
  385. }
  386. }
  387. break;
  388. case 2:
  389. m_DrawMode=DRAWMODE_ERASE;
  390. m_CursorMode=CURSORMODE_ERASE;
  391. SendMessage(WM_SETCURSOR);
  392. break;
  393. case 3:
  394. ClearClient();
  395. break;
  396. case 4:
  397. {
  398. CColorDialog dlg;
  399. dlg.DoModal();
  400. m_CurrentPenColor=dlg.GetColor();
  401. }
  402. break;
  403. case 5:
  404. {
  405. SetCapture();
  406. CAboutDlg about;
  407. about.DoModal();
  408. ReleaseCapture();
  409. }
  410. break;
  411. case 6:
  412. /* CPen pen;
  413. pen.CreatePen(PS_SOLID,10,RGB(0,0,0));
  414. pDC->SelectObject(&pen);
  415. pDC->MoveTo(200,200);
  416. pDC->LineTo(200,200);
  417. pen.DeleteObject();*/
  418. if(AfxMessageBox("确认退出吗?",MB_OKCANCEL)==IDOK)
  419.    exit(0);
  420. break;
  421. }
  422. break;
  423. case 1:
  424. m_DrawMode=DRAWMODE_LINE;
  425. m_CursorMode=CURSORMODE_PEN;
  426. switch(index)
  427. {
  428. case 0:
  429. m_LineMode=LINEMODE_FREE;
  430. break;
  431. case 1:
  432. m_LineMode=LINEMODE_BPB;
  433. break;
  434. case 2:
  435. m_LineMode=LINEMODE_DDA;
  436. break;
  437. case 3:
  438. m_LineMode=LINEMODE_BRESENHAM;
  439. break;
  440. case 4:
  441. m_LineMode=LINEMODE_THICK;
  442. break;
  443. case 5:
  444. m_LineMode=LINEMODE_BROKEN;
  445. break;
  446. }
  447. break;
  448. case 2:
  449. switch(index){  
  450. case 0:
  451. m_DrawMode=DRAWMODE_POLY;
  452. m_CursorMode=CURSORMODE_PEN;
  453. break;
  454. case 1:
  455. DecidePolygonUpper(m_LastPolyPointCount,m_PolyPoint);
  456.                     break;
  457. case 2:
  458. m_DrawMode=DRAWMODE_FILL;
  459. m_CursorMode=CURSORMODE_FILL;
  460. break;
  461. case 3:
  462. m_CursorMode=CURSORMODE_STANDARD;
  463.   if(m_LastPolyPointCount==NULL) AfxMessageBox("请先画一多边形!");
  464.                         else{
  465.                            PointType *pts;
  466.                             int ymax=m_PolyPoint[0].y;
  467.                             pts= (PointType *) malloc(sizeof(PointType)*m_LastPolyPointCount);
  468.                             for(int i=0;i<m_LastPolyPointCount;i++){
  469.                            pts[i].x =m_PolyPoint[i].x;
  470.                             pts[i].y =m_PolyPoint[i].y;
  471.                             if(m_PolyPoint[i].y>ymax) ymax=m_PolyPoint[i].y;
  472. }
  473.                     if(pts==NULL) AfxMessageBox("pts is null!");
  474.                     else scanFill(pDC,m_LastPolyPointCount,pts,ymax,m_CurrentPenColor);
  475. SaveCurrentClientToDC();                            
  476. }
  477. break;
  478. case 4:
  479. m_CursorMode=CURSORMODE_STANDARD;
  480.  if(m_LastPolyPointCount==0) AfxMessageBox("请先画一多边形!");
  481.                      else edgeflagscan(pDC,m_PolyPoint,m_LastPolyPointCount,m_CurrentPenColor);
  482.  SaveCurrentClientToDC();
  483.  break;
  484. }
  485. break;
  486. case 3:
  487. switch(index){
  488. case 0:
  489. m_DrawMode=DRAWMODE_CIRCLE;
  490. m_CursorMode=CURSORMODE_CROSS;
  491. break;
  492. case 2:
  493. m_DrawMode=DRAWMODE_ELLIPSE;
  494. m_CursorMode=CURSORMODE_CROSS;
  495. break;
  496. case 5:
  497. m_DrawMode=DRAWMODE_PIPO;
  498. m_CursorMode=CURSORMODE_CROSS;
  499. break;
  500. }
  501. }
  502. }
  503. }
  504. return 0;
  505. }
  506. void CEDrawDlg::OnLButtonDown(UINT nFlags, CPoint point) 
  507. {
  508. CDC* pDC=GetDC();
  509. CRect rect;
  510. GetWindowRect(&rect);
  511. rect.right-=105;rect.bottom-=30;
  512. rect.top+=25;rect.left+=5;
  513. // TODO: Add your message handler code here and/or call default
  514. switch (m_DrawMode){
  515. case DRAWMODE_ERASE:
  516. {
  517. m_isDrawing = true;
  518. CPen pen,* oldpen;
  519. pen.CreatePen(PS_SOLID,1,RGB(255,255,255));
  520. oldpen = pDC->SelectObject(&pen);
  521. CBrush brush,* oldbrush;
  522. brush.CreateSolidBrush(RGB(255,255,255));
  523. oldbrush = pDC->SelectObject(&brush);
  524. pDC->RoundRect(point.x,point.y,
  525. point.x+14,point.y+11,5,5);
  526.             pDC->SelectObject(oldpen);
  527. pDC->SelectObject(oldbrush);
  528. }
  529. break;
  530. case DRAWMODE_LINE:
  531. //if (m_LineMode!=LINEMODE_FREE) RestoreClientFromDC();
  532. StartPoint.x=point.x;StartPoint.y=point.y;
  533. ClipCursor(&rect);
  534. m_isDrawing=true;
  535. break;
  536. case DRAWMODE_POLY:
  537. if (m_PolyPointCount==0){
  538. m_PolyPoint[0].x=point.x;m_PolyPoint[0].y=point.y;
  539. m_PolyPointCount++;
  540. m_isDrawing=true;
  541. ClipCursor(&rect);
  542. }else{
  543. m_PolyPoint[m_PolyPointCount].x=point.x;m_PolyPoint[m_PolyPointCount].y=point.y;
  544. SaveCurrentClientToDC();
  545. m_PolyPointCount++;
  546. }
  547. break;
  548. case DRAWMODE_FILL:
  549. BeginWaitCursor();
  550. m_isDrawing=true;
  551. SeedFill(pDC,point,m_CurrentPenColor);
  552. m_isDrawing=false;
  553. SaveCurrentClientToDC();
  554. EndWaitCursor();
  555. break;
  556. case DRAWMODE_CIRCLE:
  557. case DRAWMODE_ELLIPSE:
  558. StartPoint.x=point.x;StartPoint.y=point.y;
  559. ClipCursor(&rect);
  560. m_isDrawing=true;
  561. break;
  562. case DRAWMODE_PIPO:
  563. if (m_Step==0) {
  564. StartPoint.x=point.x;StartPoint.y=point.y;
  565. pDC->SetPixelV(point.x,point.y,m_CurrentPenColor);
  566. m_Step++;
  567. m_isDrawing=true;
  568. break;
  569. }
  570. if (m_Step==1) {
  571. EndPoint.x=point.x;EndPoint.y=point.y;
  572. pDC->SetPixelV(point.x,point.y,m_CurrentPenColor);
  573. m_Step++;
  574. break;
  575. }
  576. if (m_Step==2) {
  577. SaveCurrentClientToDC();
  578. m_Step=0;
  579. m_isDrawing=false;
  580. break;
  581. }
  582. break;
  583. }
  584. CDialog::OnLButtonDown(nFlags, point);
  585. }
  586. void CEDrawDlg::OnLButtonUp(UINT nFlags, CPoint point) 
  587. {
  588. // TODO: Add your message handler code here and/or call default
  589. CDC* pDC=GetDC();
  590. // TODO: Add your message handler code here and/or call default
  591. switch (m_DrawMode){
  592. case DRAWMODE_ERASE:
  593. m_isDrawing=false;
  594. SaveCurrentClientToDC();
  595. break;
  596. case DRAWMODE_LINE:
  597. SaveCurrentClientToDC();
  598. m_isDrawing=false;
  599. ClipCursor(NULL);
  600. break;
  601. case DRAWMODE_CIRCLE:
  602. case DRAWMODE_ELLIPSE:
  603. SaveCurrentClientToDC();
  604. m_isDrawing=false;
  605. ClipCursor(NULL);
  606. break;
  607. }
  608. CDialog::OnLButtonUp(nFlags, point);
  609. }
  610. BOOL CEDrawDlg::ClearClient()
  611. {
  612. CDC* pDC=GetDC();
  613. CRect clientRect(0,0,550,550);
  614. int cx = clientRect.Width();
  615. int cy = clientRect.Height();
  616.     CDC memDC;
  617. memDC.CreateCompatibleDC(pDC);
  618.     
  619. memDC.SelectObject(&currentClientBmp);
  620. memDC.PatBlt(0,0,
  621. cx,cy,
  622. m_CurrentBGColor);        
  623. memDC.DeleteDC();
  624. Invalidate();
  625. m_isDrawing=false;
  626. return TRUE;
  627. }
  628. HBRUSH CEDrawDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
  629. {
  630. HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
  631. // TODO: Change any attributes of the DC here
  632. // TODO: Return a different brush if the default is not desired
  633. return m_BGBrush;
  634. }
  635. BOOL CEDrawDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) 
  636. {
  637. // TODO: Add your message handler code here and/or call default
  638. if (nHitTest!=HTCLIENT){
  639. HCURSOR hcursor=AfxGetApp()->LoadCursor(IDC_STANDARD);
  640. SetCursor(hcursor);
  641. return true;
  642. }
  643. if (m_CursorMode==CURSORMODE_STANDARD) {
  644. HCURSOR hcursor=AfxGetApp()->LoadCursor(IDC_STANDARD);
  645. SetCursor(hcursor);
  646. return true;
  647. }
  648. if (m_CursorMode==CURSORMODE_PEN) {
  649. HCURSOR hcursor=AfxGetApp()->LoadCursor(IDC_PEN);
  650. SetCursor(hcursor);
  651. return true;
  652. }
  653. if (m_CursorMode==CURSORMODE_FILL) {
  654. HCURSOR hcursor=AfxGetApp()->LoadCursor(IDC_FILL);
  655. SetCursor(hcursor);
  656. return true;
  657. }
  658. if (m_CursorMode==CURSORMODE_CROSS) {
  659. HCURSOR hcursor=AfxGetApp()->LoadCursor(IDC_CROSSCUR);
  660. SetCursor(hcursor);
  661. return true;
  662. }
  663. if (m_CursorMode==CURSORMODE_ERASE) {
  664. HCURSOR hcursor=AfxGetApp()->LoadCursor(IDC_ERASE);
  665. SetCursor(hcursor);
  666. return true;
  667. }
  668. return CDialog::OnSetCursor(pWnd, nHitTest, message);
  669. }
  670. void CEDrawDlg::OnLButtonDblClk(UINT nFlags, CPoint point) 
  671. {
  672. // TODO: Add your message handler code here and/or call default
  673. CDC* pDC=GetDC();
  674. switch (m_DrawMode){
  675. case DRAWMODE_POLY:
  676. DrawLine_BresenHam(pDC,m_PolyPoint[0].x,m_PolyPoint[0].y,point.x,point.y,m_CurrentPenColor);
  677. SaveCurrentClientToDC();
  678. m_isDrawing=false;
  679. m_LastPolyPointCount=m_PolyPointCount;
  680. m_PolyPointCount=0;
  681. ClipCursor(NULL);
  682. }
  683. CDialog::OnLButtonDblClk(nFlags, point);
  684. }