GandyDrawView.cpp
上传用户:do_tie
上传日期:2007-11-03
资源大小:1095k
文件大小:48k
源码类别:

GDI/图象编程

开发平台:

Visual C++

  1. // GandyDrawView.cpp : CGandyDrawView 类的实现
  2. //
  3. #include "stdafx.h"
  4. #include "GandyDraw.h"
  5. #include "GandyDrawDoc.h"
  6. #include "GandyDrawView.h"
  7. #include "MainFrm.h"
  8. #include "InputStr.h"
  9. #include "SetWidthDlg.h"
  10. #include "DukeDlg.h"
  11. #include "ChangeBmp.h"
  12. #include "DrawSetDlg.h"
  13. #ifdef _DEBUG
  14. #define new DEBUG_NEW
  15. #endif
  16. // CGandyDrawView
  17. IMPLEMENT_DYNCREATE(CGandyDrawView, CView)
  18. BEGIN_MESSAGE_MAP(CGandyDrawView, CView)
  19. // 标准打印命令
  20. ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
  21. ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
  22. ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CView::OnFilePrintPreview)
  23. ON_COMMAND(ID_VIEW_DS_TBAR, &CGandyDrawView::OnViewDsTbar)
  24. ON_UPDATE_COMMAND_UI(ID_VIEW_DS_TBAR, &CGandyDrawView::OnUpdateViewDsTbar)
  25. ON_COMMAND(ID_LINE, &CGandyDrawView::OnLine)
  26. ON_COMMAND(ID_POLYLINE, &CGandyDrawView::OnPolyline)
  27. ON_COMMAND(ID_RECT, &CGandyDrawView::OnRect)
  28. ON_COMMAND(ID_ELLIRECT, &CGandyDrawView::OnEllirect)
  29. ON_COMMAND(ID_ELLIPSE, &CGandyDrawView::OnEllipse)
  30. ON_COMMAND(ID_POLYGON, &CGandyDrawView::OnPolygon)
  31. ON_COMMAND(ID_TEXTDRAW, &CGandyDrawView::OnTextdraw)
  32. ON_COMMAND(ID_SOLID, &CGandyDrawView::OnSolid)
  33. ON_COMMAND(ID_DASH, &CGandyDrawView::OnDash)
  34. ON_COMMAND(ID_DOT, &CGandyDrawView::OnDot)
  35. ON_COMMAND(ID_DASHDOT, &CGandyDrawView::OnDashdot)
  36. ON_COMMAND(ID_DASHDOTDOT, &CGandyDrawView::OnDashdotdot)
  37. ON_COMMAND(ID_SETWIDTH1, &CGandyDrawView::OnSetwidth1)
  38. ON_COMMAND(ID_SETWIDTH2, &CGandyDrawView::OnSetwidth2)
  39. ON_COMMAND(ID_SETWIDTH3, &CGandyDrawView::OnSetwidth3)
  40. ON_COMMAND(ID_SETWIDTH4, &CGandyDrawView::OnSetwidth4)
  41. ON_COMMAND(ID_SETWIDTH8, &CGandyDrawView::OnSetwidth8)
  42. ON_COMMAND(ID_SETWIDTH10, &CGandyDrawView::OnSetwidth10)
  43. ON_COMMAND(ID_SETWIDTH20, &CGandyDrawView::OnSetwidth20)
  44. ON_COMMAND(ID_SETWIDTH50, &CGandyDrawView::OnSetwidth50)
  45. ON_COMMAND(ID_BRU_HOLLOW, &CGandyDrawView::OnBruHollow)
  46. ON_COMMAND(ID_BRU_SOLID, &CGandyDrawView::OnBruSolid)
  47. ON_COMMAND(ID_FILLWITHPICTURE, &CGandyDrawView::OnFillwithpicture)
  48. ON_COMMAND(ID_STR_HOR, &CGandyDrawView::OnStrHor)
  49. ON_COMMAND(ID_STR_VER, &CGandyDrawView::OnStrVer)
  50. ON_COMMAND(ID_STR_BIA, &CGandyDrawView::OnStrBia)
  51. ON_COMMAND(ID_STR_BLA, &CGandyDrawView::OnStrBla)
  52. ON_COMMAND(ID_STR_CRO, &CGandyDrawView::OnStrCro)
  53. ON_COMMAND(ID_STR_CCRO, &CGandyDrawView::OnStrCcro)
  54. ON_COMMAND(ID_PENCOLOR, &CGandyDrawView::OnPencolor)
  55. ON_COMMAND(ID_BRU_COLOR, &CGandyDrawView::OnBruColor)
  56. ON_WM_SETCURSOR()
  57. ON_WM_CREATE()
  58. ON_WM_LBUTTONDOWN()
  59. ON_WM_MOUSEMOVE()
  60. ON_WM_LBUTTONUP()
  61. ON_WM_RBUTTONUP()
  62. ON_COMMAND(ID_SETFONT, &CGandyDrawView::OnSetfont)
  63. ON_COMMAND(ID_TESTROTATION, &CGandyDrawView::OnTestrotation)
  64. ON_COMMAND(ID_SETFONTCOLOR, &CGandyDrawView::OnSetfontcolor)
  65. ON_COMMAND(ID_CLEARALL, &CGandyDrawView::OnClearall)
  66. ON_COMMAND(ID_INPUTSTR, &CGandyDrawView::OnInputstr)
  67. ON_COMMAND(ID_OUTPUTSTR, &CGandyDrawView::OnOutputstr)
  68. ON_COMMAND(ID_SETFONTBKCOLOR, &CGandyDrawView::OnSetfontbkcolor)
  69. ON_COMMAND(ID_OUTPUTFONTSIZE, &CGandyDrawView::OnOutputfontsize)
  70. ON_COMMAND(ID_DRAWOEMBMP, &CGandyDrawView::OnDrawoembmp)
  71. ON_COMMAND(ID_OPENBMP, &CGandyDrawView::OnOpenbmp)
  72. ON_COMMAND(ID_BLACKONWHITE, &CGandyDrawView::OnBlackonwhite)
  73. ON_COMMAND(ID_WHITEONBLACK, &CGandyDrawView::OnWhiteonblack)
  74. ON_COMMAND(ID_COLORONCOLOR, &CGandyDrawView::OnColoroncolor)
  75. ON_COMMAND(ID_HALFTONE, &CGandyDrawView::OnHalftone)
  76. ON_COMMAND(ID_DISPSTRBMP, &CGandyDrawView::OnDispstrbmp)
  77. ON_COMMAND(ID_DISPVIRBMP, &CGandyDrawView::OnDispvirbmp)
  78. ON_COMMAND(ID_STRFILLCLIENT, &CGandyDrawView::OnStrfillclient)
  79. ON_COMMAND(ID_STRKEEPRATE, &CGandyDrawView::OnStrkeeprate)
  80. ON_UPDATE_COMMAND_UI(ID_STRKEEPRATE, &CGandyDrawView::OnUpdateStrkeeprate)
  81. ON_UPDATE_COMMAND_UI(ID_DISPVIRBMP, &CGandyDrawView::OnUpdateDispvirbmp)
  82. ON_UPDATE_COMMAND_UI(ID_DISPSTRBMP, &CGandyDrawView::OnUpdateDispstrbmp)
  83. ON_UPDATE_COMMAND_UI(ID_STRFILLCLIENT, &CGandyDrawView::OnUpdateStrfillclient)
  84. ON_UPDATE_COMMAND_UI(ID_BLACKONWHITE, &CGandyDrawView::OnUpdateBlackonwhite)
  85. ON_UPDATE_COMMAND_UI(ID_WHITEONBLACK, &CGandyDrawView::OnUpdateWhiteonblack)
  86. ON_UPDATE_COMMAND_UI(ID_COLORONCOLOR, &CGandyDrawView::OnUpdateColoroncolor)
  87. ON_UPDATE_COMMAND_UI(ID_HALFTONE, &CGandyDrawView::OnUpdateHalftone)
  88. ON_COMMAND(ID_SETWIDTH, &CGandyDrawView::OnSetwidth)
  89. ON_COMMAND(ID_JAVADUKE, &CGandyDrawView::OnJavaduke)
  90. ON_COMMAND(ID_CHANGEBMP, &CGandyDrawView::OnChangebmp)
  91. ON_COMMAND(ID_DRAWSET, &CGandyDrawView::OnDrawset)
  92. ON_UPDATE_COMMAND_UI(ID_LINE, &CGandyDrawView::OnUpdateLine)
  93. ON_UPDATE_COMMAND_UI(ID_ELLIPSE, &CGandyDrawView::OnUpdateEllipse)
  94. ON_UPDATE_COMMAND_UI(ID_ELLIRECT, &CGandyDrawView::OnUpdateEllirect)
  95. ON_UPDATE_COMMAND_UI(ID_POLYGON, &CGandyDrawView::OnUpdatePolygon)
  96. ON_UPDATE_COMMAND_UI(ID_RECT, &CGandyDrawView::OnUpdateRect)
  97. ON_UPDATE_COMMAND_UI(ID_POLYLINE, &CGandyDrawView::OnUpdatePolyline)
  98. ON_UPDATE_COMMAND_UI(ID_TEXTDRAW, &CGandyDrawView::OnUpdateTextdraw)
  99. ON_UPDATE_COMMAND_UI(ID_DASH, &CGandyDrawView::OnUpdateDash)
  100. ON_UPDATE_COMMAND_UI(ID_DOT, &CGandyDrawView::OnUpdateDot)
  101. ON_UPDATE_COMMAND_UI(ID_DASHDOT, &CGandyDrawView::OnUpdateDashdot)
  102. ON_UPDATE_COMMAND_UI(ID_DASHDOTDOT, &CGandyDrawView::OnUpdateDashdotdot)
  103. ON_UPDATE_COMMAND_UI(ID_SOLID, &CGandyDrawView::OnUpdateSolid)
  104. ON_UPDATE_COMMAND_UI(ID_BRU_HOLLOW, &CGandyDrawView::OnUpdateBruHollow)
  105. ON_UPDATE_COMMAND_UI(ID_BRU_SOLID, &CGandyDrawView::OnUpdateBruSolid)
  106. ON_UPDATE_COMMAND_UI(ID_FILLWITHPICTURE, &CGandyDrawView::OnUpdateFillwithpicture)
  107. ON_UPDATE_COMMAND_UI(ID_STR_BIA, &CGandyDrawView::OnUpdateStrBia)
  108. ON_UPDATE_COMMAND_UI(ID_STR_BLA, &CGandyDrawView::OnUpdateStrBla)
  109. ON_UPDATE_COMMAND_UI(ID_STR_CCRO, &CGandyDrawView::OnUpdateStrCcro)
  110. ON_UPDATE_COMMAND_UI(ID_STR_CRO, &CGandyDrawView::OnUpdateStrCro)
  111. ON_UPDATE_COMMAND_UI(ID_STR_HOR, &CGandyDrawView::OnUpdateStrHor)
  112. ON_UPDATE_COMMAND_UI(ID_STR_VER, &CGandyDrawView::OnUpdateStrVer)
  113. ON_UPDATE_COMMAND_UI(ID_SETWIDTH1, &CGandyDrawView::OnUpdateSetwidth1)
  114. ON_UPDATE_COMMAND_UI(ID_SETWIDTH10, &CGandyDrawView::OnUpdateSetwidth10)
  115. ON_UPDATE_COMMAND_UI(ID_SETWIDTH2, &CGandyDrawView::OnUpdateSetwidth2)
  116. ON_UPDATE_COMMAND_UI(ID_SETWIDTH20, &CGandyDrawView::OnUpdateSetwidth20)
  117. ON_UPDATE_COMMAND_UI(ID_SETWIDTH3, &CGandyDrawView::OnUpdateSetwidth3)
  118. ON_UPDATE_COMMAND_UI(ID_SETWIDTH4, &CGandyDrawView::OnUpdateSetwidth4)
  119. ON_UPDATE_COMMAND_UI(ID_SETWIDTH50, &CGandyDrawView::OnUpdateSetwidth50)
  120. ON_UPDATE_COMMAND_UI(ID_SETWIDTH8, &CGandyDrawView::OnUpdateSetwidth8)
  121. END_MESSAGE_MAP()
  122. // CGandyDrawView 构造/析构
  123. CGandyDrawView::CGandyDrawView()
  124. : m_bTBar(true)
  125. , m_bDoing(false)
  126. , m_iMaxX(0)
  127. , m_iMaxY(0)
  128. , m_iWidth(0)
  129. , m_pBmp(NULL)
  130. , m_pMDC(NULL)
  131. , m_PointOld(0)
  132. , m_PointNew(0)
  133. , m_DrawType(0)
  134. , m_iPenStyle(0)
  135. , m_iHatchStyle(0)
  136. , m_iBrushStyle(0)
  137. , m_iPCount(0)
  138. , m_PointLast_PL(0)
  139. , m_PointFirst_PL(0)
  140. , m_bClick(false)
  141. , fontSize(0)
  142. , italic(false)
  143. , bold(false)
  144. , underline(false)
  145. , strikeOut(false)
  146. , m_PointLast_StatusBar(0)
  147. , m_strText(_T("默认测试文本"))
  148. , m_bBitmapLoaded(false)
  149. , m_iStretchBltMode(3)
  150. , m_bIsStretchBlt(false)
  151. , m_bIsKeepingRate(false)
  152. , m_bIsOpeningBmp(false)
  153. , m_BmpPathName(_T(""))
  154. {
  155. // TODO: 在此处添加构造代码
  156. m_bDoing = false;
  157. m_DrawType = 0;
  158. m_iWidth = 1;
  159. m_PenColor = RGB(0,0,0);
  160. textBkColor = RGB(255,255,255);
  161. m_pMDC = new CDC;
  162. m_pBmp = new CBitmap;
  163. m_iStretchBltMode = 3;
  164. //CFont font;
  165. //font.CreatePointFont(120, L"宋体");
  166. //font.GetLogFont(&logFont);
  167. fontName = "宋体";
  168. fontSize = 105;
  169. textColor = RGB(0,0,255);
  170. m_Bitmap.LoadBitmapW(IDB_BITMAP_MM);
  171. }
  172. CGandyDrawView::~CGandyDrawView()
  173. {
  174. delete m_pBmp;
  175. delete m_pMDC;
  176. }
  177. BOOL CGandyDrawView::PreCreateWindow(CREATESTRUCT& cs)
  178. {
  179. // TODO: 在此处通过修改
  180. //  CREATESTRUCT cs 来修改窗口类或样式
  181. return CView::PreCreateWindow(cs);
  182. }
  183. // CGandyDrawView 绘制
  184. void CGandyDrawView::OnDraw(CDC* pDC)
  185. {
  186. CGandyDrawDoc* pDoc = GetDocument();
  187. ASSERT_VALID(pDoc);
  188. if (!pDoc)
  189. return;
  190. //画直线 矩形 椭圆 时的OnDraw()函数
  191. if(m_DrawType <= 6)
  192. {
  193. CBitmap *pOldBmp = m_pMDC->SelectObject(m_pBmp);
  194. pDC->BitBlt(0,0,m_iMaxX,m_iMaxY,m_pMDC,0,0,SRCCOPY);
  195. m_pMDC->SelectObject(pOldBmp);
  196. }
  197. //(m_DrawType > 6) 即显示位图时的OnDraw()函数
  198. else 
  199. {
  200. CRect crect;
  201. GetClientRect(&crect);
  202. if(m_bIsStretchBlt == false)//******显示原始位图时的OnDraw()函数 功能:1.可以直线矩形等绘图 2.可以擦除客户区
  203. {
  204. CBitmap * pOldBmp1 = m_pMDC->SelectObject(m_pBmp);
  205. CBitmap *pOldBmp;
  206. pDC->BitBlt(0,0,m_iMaxX,m_iMaxY,m_pMDC,0,0,SRCCOPY);
  207. dc.CreateCompatibleDC(m_pMDC);
  208. m_FileBitmap.GetBitmap(&bs);
  209. pOldBmp=dc.SelectObject(&m_FileBitmap);
  210. m_pMDC->BitBlt(0,0,bs.bmWidth,bs.bmHeight,&dc,0,0,SRCCOPY);
  211. dc.SelectObject(pOldBmp);
  212. dc.DeleteDC();
  213. Invalidate(false);
  214. m_pMDC->SelectObject(pOldBmp1);
  215. ReleaseDC(m_pMDC);
  216. }
  217. if(m_bIsStretchBlt == true)//******显示缩放位图时的OnDraw()函数
  218. {
  219. CBitmap * pOldBmp1 = m_pMDC->SelectObject(m_pBmp);
  220. CBitmap *pOldBmp;
  221. pDC->BitBlt(0,0,m_iMaxX,m_iMaxY,m_pMDC,0,0,SRCCOPY);
  222. m_pMDC->FillSolidRect(&crect,RGB(255,255,255));
  223. m_DrawType = 20;
  224. m_pMDC->SetStretchBltMode(m_iStretchBltMode);
  225. dc.CreateCompatibleDC(m_pMDC);
  226. dc.SetStretchBltMode(m_iStretchBltMode); //将dc设置缩放模式
  227. m_FileBitmap.GetBitmap(&bs);
  228. pOldBmp=dc.SelectObject(&m_FileBitmap);
  229. //m_pMDC->StretchBlt(0, 0, crect.right,crect.bottom, &dc, 0, 0, 
  230. // bs.bmWidth, bs.bmHeight, SRCCOPY);
  231. //*********以下代码实现“保持宽高比”与“填充客户区”两种缩放,并能支持缩放的类型如白去黑,多彩等**************
  232. if(m_bIsKeepingRate == true) //保持宽高比缩放 m_bIsKeepingRate == true;
  233. {
  234. if(crect.bottom!=0 && crect.right!=0)
  235. {
  236. if(crect.right*bs.bmHeight >= crect.bottom*bs.bmWidth)
  237. {
  238. m_pMDC->StretchBlt((crect.right-bs.bmWidth*crect.bottom/bs.bmHeight)/2,0
  239. ,bs.bmWidth*crect.bottom/bs.bmHeight,crect.bottom, &dc, 0,0,bs.bmWidth, bs.bmHeight, SRCCOPY);
  240. }
  241. else
  242. {
  243. m_pMDC->StretchBlt(0,(crect.bottom-bs.bmHeight*crect.right/bs.bmWidth)/2
  244. ,crect.right,bs.bmHeight*crect.right/bs.bmWidth, &dc, 0,0,bs.bmWidth, bs.bmHeight, SRCCOPY);
  245. }
  246.  }
  247. }
  248. else //填满整个客户区缩放 m_bIsKeepingRate == false
  249. {
  250. m_pMDC->StretchBlt(0, 0, crect.right,crect.bottom, &dc, 0, 0, 
  251. bs.bmWidth, bs.bmHeight, SRCCOPY);
  252. }
  253. //*********以下代码实现“保持宽高比”与“填充客户区”两种缩放,并能支持缩放的类型如白去黑,多彩等**************
  254. Invalidate(false);
  255. dc.SelectObject(pOldBmp);
  256. Invalidate(false);
  257. m_pMDC->SelectObject(pOldBmp1);
  258. ReleaseDC(m_pMDC);
  259. }//属于缩放型位图时刷新函数
  260. }
  261. }
  262. // CGandyDrawView 打印
  263. BOOL CGandyDrawView::OnPreparePrinting(CPrintInfo* pInfo)
  264. {
  265. // 默认准备
  266. return DoPreparePrinting(pInfo);
  267. }
  268. void CGandyDrawView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  269. {
  270. // TODO: 添加额外的打印前进行的初始化过程
  271. }
  272. void CGandyDrawView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  273. {
  274. // TODO: 添加打印后进行的清除过程
  275. }
  276. // CGandyDrawView 诊断
  277. #ifdef _DEBUG
  278. void CGandyDrawView::AssertValid() const
  279. {
  280. CView::AssertValid();
  281. }
  282. void CGandyDrawView::Dump(CDumpContext& dc) const
  283. {
  284. CView::Dump(dc);
  285. }
  286. CGandyDrawDoc* CGandyDrawView::GetDocument() const // 非调试版本是内联的
  287. {
  288. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGandyDrawDoc)));
  289. return (CGandyDrawDoc*)m_pDocument;
  290. }
  291. #endif //_DEBUG
  292. // CGandyDrawView 消息处理程序
  293. void CGandyDrawView::OnViewDsTbar()
  294. {
  295. // TODO: 在此添加命令处理程序代码
  296. CMainFrame *pFrmWnd = (CMainFrame*)GetTopLevelFrame();
  297. if(m_bTBar==true)
  298. {
  299. m_bTBar = false;
  300. pFrmWnd->ShowControlBar(&pFrmWnd->m_ToolBar_ds, FALSE, FALSE);
  301. }
  302. else
  303. {
  304.     m_bTBar = true;
  305. pFrmWnd->ShowControlBar(&pFrmWnd->m_ToolBar_ds, TRUE, FALSE);
  306. }
  307. }
  308. void CGandyDrawView::OnUpdateViewDsTbar(CCmdUI *pCmdUI)
  309. {
  310. // TODO: 绘图风格选中与否
  311. if(m_bTBar==true)   
  312. {
  313. pCmdUI->SetCheck(true);  
  314. }
  315. else
  316. {
  317. pCmdUI->SetCheck(false);
  318. }
  319. }
  320. void CGandyDrawView::OnLine()
  321. {
  322. // TODO: 在此添加命令处理程序代码
  323. m_DrawType  = 0;
  324. CMainFrame *pFrmWnd = (CMainFrame*)GetTopLevelFrame();
  325. pFrmWnd->m_wndStatusBar.SetPaneText(pFrmWnd->prompt,L"画直线:单击拖动绘直线");
  326. }
  327. void CGandyDrawView::OnPolyline()
  328. {
  329. // TODO: 在此添加命令处理程序代码
  330. m_DrawType  = 1;
  331. CMainFrame *pFrmWnd = (CMainFrame*)GetTopLevelFrame();
  332. pFrmWnd->m_wndStatusBar.SetPaneText(pFrmWnd->prompt,L"画折线:单击开始,右键结束折线绘制");
  333. }
  334. void CGandyDrawView::OnRect()
  335. {
  336. // TODO: 在此添加命令处理程序代码
  337. m_DrawType   = 2;
  338. CMainFrame *pFrmWnd = (CMainFrame*)GetTopLevelFrame();
  339. pFrmWnd->m_wndStatusBar.SetPaneText(pFrmWnd->prompt,L"按住Shift时,拖动鼠标画正方形");
  340. }
  341. void CGandyDrawView::OnEllirect()
  342. {
  343. // TODO: 在此添加命令处理程序代码
  344. m_DrawType  = 3;
  345. CMainFrame *pFrmWnd = (CMainFrame*)GetTopLevelFrame();
  346. pFrmWnd->m_wndStatusBar.SetPaneText(pFrmWnd->prompt,L"画圆角矩形");
  347. }
  348. void CGandyDrawView::OnEllipse()
  349. {
  350. // TODO: 在此添加命令处理程序代码
  351. m_DrawType  = 4;
  352. CMainFrame *pFrmWnd = (CMainFrame*)GetTopLevelFrame();
  353. pFrmWnd->m_wndStatusBar.SetPaneText(pFrmWnd->prompt,L"按住Shift时,拖动鼠标画圆");
  354. }
  355. void CGandyDrawView::OnPolygon()
  356. {
  357. // TODO: 在此添加命令处理程序代码
  358. m_DrawType   = 5;
  359. CMainFrame *pFrmWnd = (CMainFrame*)GetTopLevelFrame();
  360. pFrmWnd->m_wndStatusBar.SetPaneText(pFrmWnd->prompt,L"画多边形:单击开始,右键结束折线绘制");
  361. }
  362. void CGandyDrawView::OnTextdraw()
  363. {
  364. // TODO: 在此添加命令处理程序代码
  365. m_DrawType = 6;
  366. CMainFrame *pFrmWnd = (CMainFrame*)GetTopLevelFrame();
  367. pFrmWnd->m_wndStatusBar.SetPaneText(pFrmWnd->prompt,L"在单击处显示输入的文本(默认为“默认测试文本”)");
  368. }
  369. void CGandyDrawView::OnSolid()
  370. {
  371. m_iPenStyle = PS_SOLID;
  372. }
  373. void CGandyDrawView::OnDash()
  374. {
  375. m_iPenStyle = PS_DASH;
  376. }
  377. void CGandyDrawView::OnDot()
  378. {
  379. m_iPenStyle = PS_DOT;
  380. }
  381. void CGandyDrawView::OnDashdot()
  382. {
  383. m_iPenStyle = PS_DASHDOT;
  384. }
  385. void CGandyDrawView::OnDashdotdot()
  386. {
  387. m_iPenStyle = PS_DASHDOTDOT;
  388. }
  389. void CGandyDrawView::OnSetwidth1()
  390. {
  391. m_iWidth = 1;
  392. }
  393. void CGandyDrawView::OnSetwidth2()
  394. {
  395. m_iWidth = 2;
  396. }
  397. void CGandyDrawView::OnSetwidth3()
  398. {
  399. m_iWidth = 3;
  400. }
  401. void CGandyDrawView::OnSetwidth4()
  402. {
  403. m_iWidth = 4;
  404. }
  405. void CGandyDrawView::OnSetwidth8()
  406. {
  407. m_iWidth = 8;
  408. }
  409. void CGandyDrawView::OnSetwidth10()
  410. {
  411. m_iWidth = 10;
  412. }
  413. void CGandyDrawView::OnSetwidth20()
  414. {
  415. m_iWidth = 20;
  416. }
  417. void CGandyDrawView::OnSetwidth50()
  418. {
  419. m_iWidth = 50;
  420. }
  421. void CGandyDrawView::OnBruHollow()
  422. {
  423. m_iBrushStyle = 0;
  424. }
  425. void CGandyDrawView::OnBruSolid()
  426. {
  427. m_iBrushStyle = 1;
  428. }
  429. void CGandyDrawView::OnFillwithpicture()
  430. {
  431. m_iBrushStyle = 3;
  432. // BITMAP bm;
  433. m_Bitmap.LoadBitmapW(IDB_BITMAP_MM);
  434. //m_Bitmap.GetBitmap(&bm);
  435. //m_Bitmap.SetBitmapDimension(bm.bmWidth/4,bm.bmHeight/4);
  436. }
  437. void CGandyDrawView::OnStrHor()
  438. {
  439. // TODO: 在此添加命令处理程序代码
  440. m_iBrushStyle = 2;
  441. m_iHatchStyle = HS_HORIZONTAL;
  442. }
  443. void CGandyDrawView::OnStrVer()
  444. {
  445. m_iBrushStyle = 2;
  446. m_iHatchStyle = HS_VERTICAL;
  447. }
  448. void CGandyDrawView::OnStrBia()
  449. {
  450. m_iBrushStyle = 2;
  451. m_iHatchStyle = HS_FDIAGONAL;
  452. }
  453. void CGandyDrawView::OnStrBla()
  454. {
  455. m_iBrushStyle = 2;
  456. m_iHatchStyle = HS_BDIAGONAL;
  457. }
  458. void CGandyDrawView::OnStrCro()
  459. {
  460. m_iBrushStyle = 2;
  461. m_iHatchStyle = HS_CROSS;
  462. }
  463. void CGandyDrawView::OnStrCcro()
  464. {
  465. m_iBrushStyle = 2;
  466. m_iHatchStyle = HS_DIAGCROSS;
  467. }
  468. void CGandyDrawView::OnPencolor()
  469. {
  470. CColorDialog dlg;
  471. dlg.m_cc.Flags |=CC_PREVENTFULLOPEN | CC_RGBINIT;
  472. dlg.m_cc.rgbResult = m_PenColor;
  473. if(dlg.DoModal()==IDOK)
  474. {
  475. m_PenColor = dlg.GetColor();
  476. }
  477. }
  478. void CGandyDrawView::OnBruColor()
  479. {
  480. CColorDialog dlg;
  481. dlg.m_cc.Flags |=CC_PREVENTFULLOPEN | CC_RGBINIT;
  482. dlg.m_cc.rgbResult = m_BrushColor;
  483. if(dlg.DoModal()==IDOK)
  484. {
  485. m_BrushColor = dlg.GetColor();
  486. }
  487. }
  488. BOOL CGandyDrawView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
  489. {
  490. switch(m_DrawType)
  491. {
  492. case 0:
  493. ::SetCursor(AfxGetApp()->LoadCursorW(IDC_CURSOR1));
  494. break;
  495. case 1:
  496. ::SetCursor(AfxGetApp()->LoadCursorW(IDC_CURSOR5));
  497. break;
  498. case 2:
  499. ::SetCursor(AfxGetApp()->LoadCursorW(IDC_CURSOR2));
  500. break;
  501. case 3:
  502. ::SetCursor(AfxGetApp()->LoadCursorW(IDC_CURSOR4));
  503. break;
  504. case 4:
  505. ::SetCursor(AfxGetApp()->LoadCursorW(IDC_CURSOR3));
  506. break;
  507. case 5:
  508. ::SetCursor(AfxGetApp()->LoadCursorW(IDC_CURSOR6));
  509. break;
  510. case 6:
  511. ::SetCursor(AfxGetApp()->LoadCursorW(IDC_CURSOR7));
  512. break;
  513. default:
  514. ::SetCursor(AfxGetApp()->LoadCursorW(IDC_ARROW));
  515. break;
  516. }
  517. //::SetCursor(AfxGetApp()->LoadCursorW(IDC_CURSOR1));
  518. // return CView::OnSetCursor(pWnd, nHitTest, message);
  519. return true;
  520. }
  521. int CGandyDrawView::OnCreate(LPCREATESTRUCT lpCreateStruct)
  522. {
  523. if (CView::OnCreate(lpCreateStruct) == -1)
  524. return -1;
  525. // TODO:  创建OnCreate()函数。。。
  526. //GetSystemMetrics()得到屏幕尺寸 
  527. m_iMaxX = GetSystemMetrics(SM_CXSCREEN);
  528. m_iMaxY = GetSystemMetrics(SM_CYSCREEN);
  529. CDC * pDC = GetDC();
  530. m_pMDC->CreateCompatibleDC(pDC);
  531. m_pBmp->CreateCompatibleBitmap(pDC,m_iMaxX,m_iMaxY);
  532. CBitmap * pOldBitmap = m_pMDC->SelectObject(m_pBmp);
  533. CBrush brush;
  534. brush.CreateStockObject(WHITE_BRUSH);
  535. CRect rect(-1,-1,m_iMaxX,m_iMaxY);
  536. m_pMDC->FillRect(rect,&brush);
  537. m_pMDC->SelectObject(pOldBitmap);
  538. ReleaseDC(pDC);
  539. return 0;
  540. }
  541. void CGandyDrawView::OnLButtonDown(UINT nFlags, CPoint point)
  542. {
  543. m_PointLast_StatusBar = point;
  544. if(m_bDoing==true)
  545. {
  546.     return;
  547. }
  548. SetCapture();
  549. m_bDoing = true;
  550. m_PointNew = point;
  551. m_PointOld = point;
  552. if(m_DrawType == 1)  //画折线时,每单击一次,将点坐标记入arrayP数组
  553. {
  554. //CDC * pDC = GetDC();
  555. //pDC->SetPixel(point,m_PenColor);
  556. //arrayP[m_iPCount++] = point;
  557. //m_PointLast_PL = point;
  558. }
  559. //*****************************************************
  560. if(m_DrawType == 10) //实现区域填充功能 m_DrawType == 10
  561. {
  562.    CBrush * pOldBrush;
  563.    CBitmap * pOldBmp;
  564.    CBrush bfill;
  565.    bfill.CreateSolidBrush(m_BrushColor);
  566.    pOldBrush = m_pMDC->SelectObject(&bfill);
  567.    pOldBmp = m_pMDC->SelectObject(m_pBmp);
  568.    m_pMDC->ExtFloodFill(point.x,point.y,m_pMDC->GetPixel(point),FLOODFILLSURFACE);
  569.    Invalidate(false);
  570.    m_pMDC->SelectObject(pOldBrush);
  571.    m_pMDC->SelectObject(pOldBmp);
  572.    m_bDoing = false;
  573. }
  574. //*****************************************************
  575. CView::OnLButtonDown(nFlags, point);
  576. }
  577. void CGandyDrawView::OnMouseMove(UINT nFlags, CPoint point)
  578. {
  579. // TODO: 在此添加消息处理程序代码和/或调用默认值
  580. wchar_t buf[20];
  581. CMainFrame *pFrmWnd = (CMainFrame*)GetTopLevelFrame();
  582. _itow_s(point.x, buf, 20, 10);
  583. pFrmWnd->m_wndStatusBar.SetPaneText(pFrmWnd->xVal, buf);
  584. _itow_s(point.y, buf, 20, 10);
  585. pFrmWnd->m_wndStatusBar.SetPaneText(pFrmWnd->yVal, buf);
  586. _itow_s(abs(point.x-m_PointLast_StatusBar.x), buf, 20, 10);
  587. pFrmWnd->m_wndStatusBar.SetPaneText(pFrmWnd->dxVal, buf);
  588. _itow_s(abs(point.y-m_PointLast_StatusBar.y), buf, 20, 10);
  589. pFrmWnd->m_wndStatusBar.SetPaneText(pFrmWnd->dyVal, buf);
  590. if(m_bDoing==true)
  591. {
  592. CDC * pDC = GetDC();
  593. CBitmap * pOldBmp = m_pMDC->SelectObject(m_pBmp);
  594. CPen pen;
  595. pen.CreatePen(m_iPenStyle,m_iWidth,m_PenColor);
  596. CPen * pOldPen  = pDC->SelectObject(&pen);
  597.         //确定刷子类型****************
  598. CBrush brush;
  599. switch(m_iBrushStyle)
  600. {
  601. case 0 :
  602. {
  603. brush.CreateStockObject(HOLLOW_BRUSH);
  604. break;
  605. }
  606. case 1 :
  607. {
  608. brush.CreateSolidBrush(m_BrushColor);
  609. break;
  610. }
  611. case 2 :
  612. {
  613. brush.CreateHatchBrush(m_iHatchStyle,m_BrushColor);
  614. break;
  615. }
  616. case 3 :
  617. {
  618. brush.CreatePatternBrush(&m_Bitmap);
  619. //brush.UnrealizeObject();  ////////////////////////
  620. break;
  621. }
  622. }
  623. //*******************************
  624. CBrush * pOldBrush = (CBrush *) pDC->SelectObject(&brush);
  625. CRect rectOld(m_PointOld,m_PointNew);
  626. if(m_DrawType==1 || m_DrawType==5)
  627. {
  628. rectOld.SetRect(m_PointLast_PL,m_PointNew);
  629. }
  630. /*else
  631. {
  632. CRect rectOld(m_PointOld,m_PointNew);
  633. }*/
  634. rectOld.NormalizeRect();
  635. rectOld.InflateRect(m_iWidth,m_iWidth);
  636. pDC->BitBlt(rectOld.left,rectOld.top,rectOld.Width(),rectOld.Height(),
  637. m_pMDC,rectOld.left,rectOld.top,SRCCOPY);
  638. CRect rectNew(m_PointOld,point);
  639. switch(m_DrawType)
  640. {
  641. case 0: //画直线
  642. {
  643. pDC->MoveTo(m_PointOld);
  644. pDC->LineTo(point);
  645. break;
  646. }
  647. case 1://画折线
  648. {
  649. pDC->MoveTo(m_PointLast_PL);
  650. pDC->LineTo(point);
  651. break;
  652. }
  653. case 2://画矩形
  654. {
  655. //pFrmWnd->m_wndStatusBar.SetPaneText(pFrmWnd->prompt,L"按住Shift时,拖动鼠标画正方形");
  656. SetBrushOrgEx(pDC->m_hDC, rectNew.left, rectNew.top, NULL);
  657. if(GetKeyState(VK_SHIFT)&(1<<15))
  658. {
  659. if(abs(rectNew.right-rectNew.left)>abs(rectNew.bottom-rectNew.top))
  660. {
  661. if(rectNew.right>rectNew.left)
  662. {
  663. rectNew.SetRect(m_PointOld.x,m_PointOld.y,m_PointOld.x+abs(point.y-m_PointOld.y),point.y);
  664. pDC->Rectangle(rectNew);
  665. rectNew.SetRect(m_PointOld,point);
  666. }
  667. else
  668. {
  669. rectNew.SetRect(m_PointOld.x,m_PointOld.y,m_PointOld.x-abs(point.y-m_PointOld.y),point.y);
  670. pDC->Rectangle(rectNew);
  671. rectNew.SetRect(m_PointOld,point);
  672. }
  673. }
  674. else
  675. {
  676. if(rectNew.bottom>rectNew.top)
  677. {
  678. rectNew.SetRect(m_PointOld.x,m_PointOld.y,point.x,m_PointOld.y+abs(point.x-m_PointOld.x));
  679. pDC->Rectangle(rectNew);
  680. rectNew.SetRect(m_PointOld,point);
  681. }
  682. else
  683. {
  684. rectNew.SetRect(m_PointOld.x,m_PointOld.y,point.x,m_PointOld.y-abs(point.x-m_PointOld.x));
  685. pDC->Rectangle(rectNew);
  686. rectNew.SetRect(m_PointOld,point);
  687. }
  688. }
  689. }
  690. else
  691. {
  692. pDC->Rectangle(rectNew);
  693. }
  694. break;
  695. }
  696. case 3: //画圆角矩形
  697. {
  698. SetBrushOrgEx(pDC->m_hDC, rectNew.left, rectNew.top, NULL);
  699. int d = min(rectNew.Width(),rectNew.Height())/4;
  700. pDC-> RoundRect(rectNew, CPoint(d, d));
  701. break;
  702. }
  703. case 4://画椭圆
  704. {
  705. SetBrushOrgEx(pDC->m_hDC, rectNew.left, rectNew.top, NULL);
  706. //pFrmWnd->m_wndStatusBar.SetPaneText(pFrmWnd->prompt,L"按住Shift时,拖动鼠标画圆");
  707. if(GetKeyState(VK_SHIFT)&(1<<15))
  708. {
  709. if(abs(rectNew.right-rectNew.left)>abs(rectNew.bottom-rectNew.top))
  710. {
  711. if(rectNew.right>rectNew.left)
  712. {
  713. rectNew.SetRect(m_PointOld.x,m_PointOld.y,m_PointOld.x+abs(point.y-m_PointOld.y),point.y);
  714. pDC->Ellipse(rectNew);
  715. rectNew.SetRect(m_PointOld,point);
  716. }
  717. else
  718. {
  719. rectNew.SetRect(m_PointOld.x,m_PointOld.y,m_PointOld.x-abs(point.y-m_PointOld.y),point.y);
  720. pDC->Ellipse(rectNew);
  721. rectNew.SetRect(m_PointOld,point);
  722. }
  723. }
  724. else
  725. {
  726. if(rectNew.bottom>rectNew.top)
  727. {
  728. rectNew.SetRect(m_PointOld.x,m_PointOld.y,point.x,m_PointOld.y+abs(point.x-m_PointOld.x));
  729. pDC->Ellipse(rectNew);
  730. rectNew.SetRect(m_PointOld,point);
  731. }
  732. else
  733. {
  734. rectNew.SetRect(m_PointOld.x,m_PointOld.y,point.x,m_PointOld.y-abs(point.x-m_PointOld.x));
  735. pDC->Ellipse(rectNew);
  736. rectNew.SetRect(m_PointOld,point);
  737. }
  738. }
  739. }
  740. else
  741. {
  742. rectNew.SetRect(m_PointOld,point);
  743.     pDC->Ellipse(rectNew);
  744. }
  745. break;
  746. }
  747. case 5: //画多边形
  748. {
  749. pDC->MoveTo(m_PointLast_PL);
  750. pDC->LineTo(point);
  751. break;
  752. }
  753. case 6: //文本输出
  754. {
  755. //pDC->TextOutW(point.x,point.y,m_strText);
  756. break;
  757. }
  758. }
  759. m_pMDC->SelectObject(pOldBmp);
  760. pDC->SelectObject(pOldPen);
  761. pDC->SelectObject(pOldBrush);
  762. ReleaseDC(pDC);
  763. m_PointNew = point;
  764. }
  765. CView::OnMouseMove(nFlags, point);
  766. }
  767. void CGandyDrawView::OnLButtonUp(UINT nFlags, CPoint point)
  768. {
  769. // TODO: 在此添加ONLButtonUP()函数
  770. if(m_bDoing==true)
  771. {
  772. m_bDoing = false;
  773. CBitmap * pOldBmp = m_pMDC->SelectObject(m_pBmp);
  774. CPen pen;
  775. pen.CreatePen(m_iPenStyle,m_iWidth,m_PenColor);
  776. CPen * pOldPen  = m_pMDC->SelectObject(&pen);
  777. //确定刷子类型****************
  778. CBrush brush;
  779. switch(m_iBrushStyle)
  780. {
  781. case 0 :
  782. {
  783. brush.CreateStockObject(HOLLOW_BRUSH);
  784. break;
  785. }
  786. case 1 :
  787. {
  788. brush.CreateSolidBrush(m_BrushColor);
  789. break;
  790. }
  791. case 2 :
  792. {
  793. brush.CreateHatchBrush(m_iHatchStyle,m_BrushColor);
  794. break;
  795. }
  796. case 3 :
  797. {
  798. brush.CreatePatternBrush(&m_Bitmap);
  799. //brush.UnrealizeObject();
  800. break;
  801. }
  802. }
  803. //*******************************
  804. CBrush * pOldBrush = (CBrush *) m_pMDC->SelectObject(&brush);
  805. //CBrush * pOldBrush = (CBrush *) m_pMDC->SelectStockObject(NULL_BRUSH);
  806. CRect rect(m_PointNew,m_PointOld);
  807. CRect rectNew(m_PointOld,point);
  808. //CRect rect33(55,55,200,200);
  809. /*if(m_DrawType == 1)
  810. {
  811. rect.SetRect(m_PointNew,m_PointLast_PL);
  812. rectNew.SetRect(m_PointLast_PL,point);
  813. }*/
  814. switch(m_DrawType)
  815. {
  816. case 0:
  817. {
  818. m_pMDC->MoveTo(m_PointOld);
  819. m_pMDC->LineTo(point);
  820. break;
  821. }
  822. case 1:
  823. {
  824. m_bClick = true;
  825. //CDC * pDC = GetDC();
  826. m_bDoing = true;
  827. m_pMDC->SetPixel(point,m_PenColor);
  828. arrayP[m_iPCount++] = point;
  829. m_PointLast_PL = point;
  830. rect.SetRect(m_PointNew,m_PointLast_PL);
  831. rectNew.SetRect(m_PointLast_PL,point);
  832. if(m_iPCount >= 2) //画折线 有两点以上时
  833. {
  834. m_pMDC->Polyline(arrayP,m_iPCount);
  835. }
  836. }
  837. case 2:
  838. {
  839. SetBrushOrgEx(m_pMDC->m_hDC, rectNew.left, rectNew.top, NULL);
  840. if(GetKeyState(VK_SHIFT)&(1<<15))
  841. {
  842. if(abs(rectNew.right-rectNew.left)>abs(rectNew.bottom-rectNew.top))
  843. {
  844. if(rectNew.right>rectNew.left)
  845. {
  846. rectNew.SetRect(m_PointOld.x,m_PointOld.y,m_PointOld.x+abs(point.y-m_PointOld.y),point.y);
  847. m_pMDC->Rectangle(rectNew);
  848. rectNew.SetRect(m_PointOld,point);
  849. }
  850. else
  851. {
  852. rectNew.SetRect(m_PointOld.x,m_PointOld.y,m_PointOld.x-abs(point.y-m_PointOld.y),point.y);
  853. m_pMDC->Rectangle(rectNew);
  854. rectNew.SetRect(m_PointOld,point);
  855. }
  856. }
  857. else
  858. {
  859. if(rectNew.bottom>rectNew.top)
  860. {
  861. rectNew.SetRect(m_PointOld.x,m_PointOld.y,point.x,m_PointOld.y+abs(point.x-m_PointOld.x));
  862. m_pMDC->Rectangle(rectNew);
  863. rectNew.SetRect(m_PointOld,point);
  864. }
  865. else
  866. {
  867. rectNew.SetRect(m_PointOld.x,m_PointOld.y,point.x,m_PointOld.y-abs(point.x-m_PointOld.x));
  868. m_pMDC->Rectangle(rectNew);
  869. rectNew.SetRect(m_PointOld,point);
  870. }
  871. }
  872. }
  873. else
  874. {
  875. m_pMDC->Rectangle(rectNew);
  876. }
  877. break;
  878. }
  879. case 3:
  880. {
  881. SetBrushOrgEx(m_pMDC->m_hDC, rectNew.left, rectNew.top, NULL);
  882. int d = min(rectNew.Width(), rectNew.Height())/4;
  883. m_pMDC-> RoundRect(rectNew, CPoint(d, d));
  884. break;
  885. }
  886. case 4:
  887. {
  888. SetBrushOrgEx(m_pMDC->m_hDC, rectNew.left, rectNew.top, NULL);
  889. if(GetKeyState(VK_SHIFT)&(1<<15))
  890. {
  891. if(abs(rectNew.right-rectNew.left)>abs(rectNew.bottom-rectNew.top))
  892. {
  893. if(rectNew.right>rectNew.left)
  894. {
  895. rectNew.SetRect(m_PointOld.x,m_PointOld.y,m_PointOld.x+abs(point.y-m_PointOld.y),point.y);
  896. m_pMDC->Ellipse(rectNew);
  897. rectNew.SetRect(m_PointOld,point);
  898. }
  899. else
  900. {
  901. rectNew.SetRect(m_PointOld.x,m_PointOld.y,m_PointOld.x-abs(point.y-m_PointOld.y),point.y);
  902. m_pMDC->Ellipse(rectNew);
  903. rectNew.SetRect(m_PointOld,point);
  904. }
  905. }
  906. else
  907. {
  908. if(rectNew.bottom>rectNew.top)
  909. {
  910. rectNew.SetRect(m_PointOld.x,m_PointOld.y,point.x,m_PointOld.y+abs(point.x-m_PointOld.x));
  911. m_pMDC->Ellipse(rectNew);
  912. rectNew.SetRect(m_PointOld,point);
  913. }
  914. else
  915. {
  916. rectNew.SetRect(m_PointOld.x,m_PointOld.y,point.x,m_PointOld.y-abs(point.x-m_PointOld.x));
  917. m_pMDC->Ellipse(rectNew);
  918. rectNew.SetRect(m_PointOld,point);
  919. }
  920. }
  921. }
  922. else
  923. {
  924. rectNew.SetRect(m_PointOld,point);
  925. m_pMDC->Ellipse(rectNew);
  926. }
  927. break;
  928. }
  929. case 5:
  930. {
  931. m_bClick = true;
  932. if(m_iPCount==0)
  933. {
  934. m_PointFirst_PL = point;
  935. }
  936. m_bDoing = true;
  937. m_pMDC->SetPixel(point,m_PenColor);
  938. arrayP[m_iPCount++] = point;
  939. m_PointLast_PL = point;
  940. rect.SetRect(m_PointNew,m_PointLast_PL);
  941. rectNew.SetRect(m_PointLast_PL,point);
  942. if(m_iPCount >= 2) //画折线 有两点以上时
  943. {
  944. m_pMDC->Polyline(arrayP,m_iPCount);
  945. }
  946. break;
  947. }
  948. case 6:
  949. {
  950. //m_pMDC->TextOutW(point.x,point.y,m_strText);
  951. //break;
  952. CFont *pOldFont = (CFont *) m_pMDC->SelectObject(&font);
  953. CBitmap *pOldBmp = m_pMDC->SelectObject(m_pBmp);
  954. SetFont(m_pMDC, fontName, fontSize, textColor, 0, italic, 
  955. bold, underline, strikeOut);
  956. m_pMDC->TextOutW(point.x, point.y, m_strText);
  957. Invalidate(false);
  958. m_pMDC->SelectObject(pOldFont);
  959. m_pMDC->SelectObject(pOldBmp);
  960. ReleaseDC(m_pMDC);
  961. }
  962. }
  963. Invalidate(false);
  964. m_pMDC->SelectObject(pOldBmp);
  965. m_pMDC->SelectObject(pOldPen);
  966. m_pMDC->SelectObject(pOldBrush);
  967. }
  968. if((m_DrawType!=1)&&(m_DrawType!=5))
  969. {
  970. ReleaseCapture();
  971. }
  972. // CView::OnLButtonUp(nFlags, point);
  973. }
  974. void CGandyDrawView::OnRButtonUp(UINT nFlags, CPoint point)
  975. {
  976. // TODO: 在此添加消息处理程序代码和/或调用默认值
  977. if(m_bClick == true)
  978. {
  979. CBitmap * pOldBmp = m_pMDC->SelectObject(m_pBmp);
  980. CPen pen;
  981. pen.CreatePen(m_iPenStyle,m_iWidth,m_PenColor);
  982. CPen * pOldPen  = m_pMDC->SelectObject(&pen);
  983. //CBrush * pOldBrush = (CBrush *) m_pMDC->SelectStockObject(NULL_BRUSH);
  984. //确定刷子类型****************
  985. CBrush brush;
  986. switch(m_iBrushStyle)
  987. {
  988. case 0 :
  989. {
  990. brush.CreateStockObject(HOLLOW_BRUSH);
  991. break;
  992. }
  993. case 1 :
  994. {
  995. brush.CreateSolidBrush(m_BrushColor);
  996. break;
  997. }
  998. case 2 :
  999. {
  1000. brush.CreateHatchBrush(m_iHatchStyle,m_BrushColor);
  1001. break;
  1002. }
  1003. case 3 :
  1004. {
  1005. brush.UnrealizeObject();
  1006. brush.CreatePatternBrush(&m_Bitmap);
  1007. break;
  1008. }
  1009. }
  1010. //*******************************
  1011. CBrush * pOldBrush = (CBrush *) m_pMDC->SelectObject(&brush);
  1012. CRect rect(m_PointNew,m_PointOld);
  1013. CRect rectNew(m_PointOld,point);
  1014. //CDC * pDC=GetDC();
  1015. if(m_DrawType == 1)
  1016. {
  1017. m_pMDC->SetPixel(point,m_PenColor);
  1018. arrayP[m_iPCount++] = point;
  1019. if(m_iPCount >= 2) //画折线 有两点以上时
  1020. {
  1021. m_pMDC->Polyline(arrayP,m_iPCount);
  1022. }
  1023. m_bDoing = false;
  1024.     ReleaseCapture();
  1025. m_iPCount = 0;
  1026. }
  1027. if(m_DrawType == 5)
  1028. {
  1029. m_pMDC->MoveTo(m_PointLast_PL);
  1030. m_pMDC->LineTo(point);
  1031. m_pMDC->MoveTo(point);
  1032. m_pMDC->LineTo(m_PointFirst_PL);
  1033. m_bDoing = false;
  1034.     ReleaseCapture();
  1035. m_iPCount = 0;
  1036. }
  1037. //ReleaseDC(pDC);
  1038. Invalidate(false);
  1039. m_pMDC->SelectObject(pOldBmp);
  1040. m_pMDC->SelectObject(pOldPen);
  1041. m_pMDC->SelectObject(pOldBrush);
  1042. }
  1043. m_bClick = false;
  1044. CView::OnRButtonUp(nFlags, point);
  1045. }
  1046. //字体选择对话框
  1047. void CGandyDrawView::OnSetfont()
  1048. {
  1049. // TODO: 在此添加命令处理程序代码
  1050. CDC *pDC = GetDC();
  1051. CFontDialog fontDlg(&logFont);
  1052. fontDlg.m_cf.rgbColors = textColor;
  1053. //fontDlg.m_cf.iPointSize = 105;
  1054. //fontDlg.m_cf.lpLogFont->lfFaceName = L"宋体";
  1055. if (fontDlg.DoModal() == IDOK) {
  1056. //fontName = fontDlg.GetFaceName(); // Error! As wchar_t fontName[LF_FACESIZE];
  1057. //wcscpy_s(fontName, LF_FACESIZE, fontDlg.GetFaceName());
  1058. // wcscpy_s(fontName, LF_FACESIZE, fontDlg.GetFaceName().AllocSysString());
  1059. fontName = fontDlg.GetFaceName();
  1060. fontSize = fontDlg.GetSize();
  1061. textColor = fontDlg.GetColor();
  1062. italic = fontDlg.IsItalic();
  1063. bold = fontDlg.IsBold();
  1064. strikeOut = fontDlg.IsStrikeOut();
  1065. underline = fontDlg.IsUnderline();
  1066. if (!SetFont(pDC, fontName, fontSize, textColor, 0, italic, bold, underline, 
  1067. strikeOut)) {
  1068. MessageBox(L"Create font wrong!", L"Error");
  1069. return;
  1070. }
  1071. font.GetLogFont(&logFont);
  1072. }
  1073. ReleaseDC(pDC);
  1074. }
  1075. void CGandyDrawView::OnTestrotation()
  1076. {
  1077. // TODO: 在此添加命令处理程序代码
  1078. //CDC *pDC = GetDC();
  1079. CFont *pOldFont = (CFont *) m_pMDC->SelectObject(&font);
  1080. CBitmap *pOldBmp = m_pMDC->SelectObject(m_pBmp);
  1081. RECT rect;
  1082. GetClientRect(&rect);
  1083. wchar_t buf[100];
  1084. CString sFontNum;
  1085. m_pMDC->FillSolidRect(&rect, RGB(255, 255, 255));
  1086. for (int angle = 0; angle <= 360; angle += 10) {
  1087. SetFont(m_pMDC, fontName, fontSize, textColor, angle * 10, italic, 
  1088. bold, underline, strikeOut);
  1089. sFontNum = GetFontNumber(fontSize);
  1090. swprintf_s(buf,100, L"字体:名称=%s,字号=%s,大小=%g磅", fontName, 
  1091. sFontNum, fontSize / 10.0);
  1092. m_pMDC->TextOutW(rect.right / 2, rect.bottom / 2, buf);
  1093. }
  1094. Invalidate(false);
  1095. m_pMDC->SelectObject(pOldFont);
  1096. m_pMDC->SelectObject(pOldBmp);
  1097. ReleaseDC(m_pMDC);
  1098. }
  1099. void CGandyDrawView::OnSetfontcolor()
  1100. {
  1101. // TODO  字体颜色 前景
  1102. CColorDialog dlg;
  1103. dlg.m_cc.Flags |=CC_PREVENTFULLOPEN | CC_RGBINIT;
  1104. dlg.m_cc.rgbResult = textColor;
  1105. if(dlg.DoModal()==IDOK)
  1106. {
  1107. textColor= dlg.GetColor();
  1108. }
  1109. }
  1110. // 将字体大小fontSize转换为中文字号sFontNum的自定义函数
  1111. CString CGandyDrawView::GetFontNumber(int size)
  1112. {
  1113. switch(size) {
  1114. case 420: return L"初号";
  1115. case 360: return L"小初";
  1116. case 260: return L"一号";
  1117. case 240: return L"小一";
  1118. case 220: return L"二号";
  1119. case 180: return L"小二";
  1120. case 160: return L"三号";
  1121. case 150: return L"小三";
  1122. case 140: return L"四号";
  1123. case 120: return L"小四";
  1124. case 105: return L"五号";
  1125. case  90: return L"小五";
  1126. case  75: return L"六号";
  1127. case  65: return L"小六";
  1128. case  55: return L"七号";
  1129. case  50: return L"八号";
  1130. }
  1131. return L"未知";
  1132. }
  1133. BOOL CGandyDrawView::SetFont(CDC * pDC, LPCTSTR name, int size, COLORREF col, int angle, bool italic, bool bold, bool underline, bool strikeOut)
  1134. {
  1135. int height = -MulDiv(size, pDC->GetDeviceCaps(LOGPIXELSY), 720);
  1136. CFont font;
  1137. BOOL bOk = font.CreateFont(height, 0, angle, angle, bold?700:400, italic, 
  1138. underline, strikeOut, DEFAULT_CHARSET, 
  1139. OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
  1140.     CLIP_DEFAULT_PRECIS, DEFAULT_PITCH | 
  1141. FF_DONTCARE, name);
  1142. if (bOk) {
  1143. font.GetLogFont(&logFont);
  1144. pDC->SelectObject(font);
  1145. pDC->SetTextColor(col);
  1146. pDC->SetBkColor(textBkColor);
  1147. }
  1148. return bOk;
  1149. }
  1150. void CGandyDrawView::OnClearall()
  1151. {
  1152. // TODO: 在此添加命令处理程序代码
  1153. CBitmap * pOldBmp = m_pMDC->SelectObject(m_pBmp);
  1154. RECT rect;
  1155. GetClientRect(&rect);
  1156. m_pMDC->FillSolidRect(&rect,RGB(255,255,255));
  1157. Invalidate(false);
  1158. m_pMDC->SelectObject(pOldBmp);
  1159. ReleaseDC(m_pMDC);
  1160. }
  1161. void CGandyDrawView::OnInputstr()
  1162. {
  1163. // TODO: 在此添加命令处理程序代码
  1164. CInputStr StrInputDlg;
  1165. if(StrInputDlg.DoModal()==IDOK)
  1166. {
  1167. m_strText = StrInputDlg.m_strInput;
  1168. }
  1169. }
  1170. void CGandyDrawView::OnOutputstr()
  1171. {
  1172. // TODO: 在此添加命令处理程序代码
  1173. m_DrawType = 6;
  1174. }
  1175. void CGandyDrawView::OnSetfontbkcolor()
  1176. {
  1177. CColorDialog dlg;
  1178. dlg.m_cc.Flags |=CC_PREVENTFULLOPEN | CC_RGBINIT;
  1179. dlg.m_cc.rgbResult = textBkColor;
  1180. if(dlg.DoModal()==IDOK)
  1181. {
  1182. textBkColor= dlg.GetColor();
  1183. }
  1184. }
  1185. void CGandyDrawView::OnOutputfontsize()
  1186. {
  1187. int fs[16] = {420, 360, 260, 240, 220, 180, 160, 150, 140, 120, 105, 90, 75, 65, 55, 50};
  1188. //CDC *pDC = GetDC();
  1189. CBitmap *pOldBmp = m_pMDC->SelectObject(m_pBmp);
  1190. CFont *pOldFont = (CFont *)m_pMDC->SelectObject(&font);
  1191. wchar_t buf[40];
  1192. CString no;
  1193. int y = 0, size;
  1194. for (int i = 0; i < 16; i++) {
  1195. size = fs[i];
  1196. SetFont(m_pMDC, fontName, size, textColor, 0, italic, bold, underline, strikeOut);
  1197. no = GetFontNumber(size);
  1198. swprintf_s(buf, 40, L"这是%s%s字(%g磅)", fontName, no, size / 10.0);
  1199. m_pMDC->TextOut(0, y, buf);
  1200. y += fs[i] / 6;
  1201. }
  1202. Invalidate(false);
  1203. m_pMDC->SelectObject(pOldBmp);
  1204. m_pMDC->SelectObject(pOldFont);
  1205. ReleaseDC(m_pMDC);
  1206. }
  1207. void CGandyDrawView::OnDrawoembmp()
  1208. {
  1209. CBitmap * pOldBmp1 = m_pMDC->SelectObject(m_pBmp);
  1210. //CDC dc;// , *pDC = GetDC();
  1211. CBitmap bmp, *pOldBmp;
  1212. //BITMAP bs;
  1213. int i, j, id = 32734;
  1214. wchar_t buf[8];
  1215. dc.CreateCompatibleDC(m_pMDC);
  1216. for (i = 0; i < 4; i++) 
  1217. for (j = 0; j < 10; j++) {
  1218. if(bmp.LoadOEMBitmap(id)) {
  1219. bmp.GetBitmap(&bs);
  1220. pOldBmp = (CBitmap*)dc.SelectObject(&bmp);
  1221. m_pMDC->BitBlt(j * 50, i * 80, bs.bmWidth, bs.bmHeight, &dc, 0, 0, SRCCOPY);
  1222. dc.SelectObject(pOldBmp);
  1223. bmp.DeleteObject();
  1224. }
  1225. _itow_s(id, buf, 8, 10);
  1226. m_pMDC->TextOut(j * 50, 40 + i * 80, buf);
  1227. id++;
  1228. if(id>32767) break;
  1229. }
  1230. Invalidate(false);
  1231. m_pMDC->SelectObject(pOldBmp1);
  1232. ReleaseDC(m_pMDC);
  1233. }
  1234. void CGandyDrawView::OnOpenbmp()
  1235. {
  1236. wchar_t filters[] = L"位图文件(*.bmp)|*.bmp|所有文件(*.*)|*.*||";
  1237. CFileDialog fileDlg(TRUE, NULL, NULL, OFN_HIDEREADONLY, filters);
  1238. if (fileDlg.DoModal() == IDOK) {
  1239. HBITMAP hBmp = (HBITMAP)LoadImage(NULL, fileDlg.GetPathName(), 
  1240. IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | 
  1241. LR_DEFAULTCOLOR | LR_DEFAULTSIZE);
  1242. if (hBmp != NULL) {
  1243. BITMAP bm;
  1244. GetObject(hBmp, sizeof(bm), &bm);
  1245. long cb = bm.bmBitsPixel * bm.bmHeight * bm.bmWidthBytes;
  1246. bm.bmBits = new char[cb];
  1247. GetBitmapBits(hBmp, cb, bm.bmBits);
  1248. m_FileBitmap.CreateBitmapIndirect(&bm);
  1249. m_bBitmapLoaded = true;
  1250. }
  1251. }
  1252. CBitmap * pOldBmp1 = m_pMDC->SelectObject(m_pBmp);
  1253. //CDC dc;// , *pDC = GetDC();
  1254. CBitmap *pOldBmp;
  1255. //BITMAP bs;
  1256. dc.CreateCompatibleDC(m_pMDC);
  1257. m_FileBitmap.GetBitmap(&bs);
  1258. pOldBmp=dc.SelectObject(&m_FileBitmap);
  1259. m_pMDC->BitBlt(0,0,bs.bmWidth,bs.bmHeight,&dc,0,0,SRCCOPY);
  1260. dc.SelectObject(pOldBmp);
  1261. Invalidate(false);
  1262. m_pMDC->SelectObject(pOldBmp1);
  1263. ReleaseDC(m_pMDC);
  1264. m_bIsOpeningBmp = true;
  1265. m_DrawType = 20;
  1266. }
  1267. void CGandyDrawView::OnBlackonwhite()
  1268. {
  1269. m_iStretchBltMode = 1;
  1270. Invalidate(false);
  1271. OnDispstrbmp();
  1272. }
  1273. void CGandyDrawView::OnWhiteonblack()
  1274. {
  1275. m_iStretchBltMode = 2;
  1276. Invalidate(false);
  1277. OnDispstrbmp();
  1278. }
  1279. void CGandyDrawView::OnColoroncolor()
  1280. {
  1281. m_iStretchBltMode = 3;
  1282. Invalidate(false);
  1283. OnDispstrbmp();
  1284. }
  1285. void CGandyDrawView::OnHalftone()
  1286. {
  1287. m_iStretchBltMode = 4;
  1288. Invalidate(false);
  1289. OnDispstrbmp();
  1290. }
  1291. void CGandyDrawView::OnDispstrbmp()  //显示缩放位图
  1292. {
  1293. m_DrawType = 20;
  1294. m_bIsStretchBlt = true;
  1295. m_bIsKeepingRate = false;
  1296. OnClearall();
  1297. CRect crect;
  1298. GetClientRect(&crect);
  1299. m_pMDC->FillSolidRect(&crect,RGB(255,255,255));
  1300. CBitmap * pOldBmp1 = m_pMDC->SelectObject(m_pBmp);
  1301. CBitmap *pOldBmp;
  1302. m_pMDC->SetStretchBltMode(m_iStretchBltMode);
  1303. dc.CreateCompatibleDC(m_pMDC);
  1304. dc.SetStretchBltMode(m_iStretchBltMode);
  1305. m_FileBitmap.GetBitmap(&bs);
  1306. pOldBmp=dc.SelectObject(&m_FileBitmap);
  1307. m_pMDC->StretchBlt(0, 0, crect.right,crect.bottom, &dc, 0, 0, 
  1308. bs.bmWidth, bs.bmHeight, SRCCOPY);
  1309. Invalidate(false);
  1310. dc.SelectObject(pOldBmp);
  1311. m_pMDC->SelectObject(pOldBmp1);
  1312. ReleaseDC(m_pMDC);
  1313. }
  1314. void CGandyDrawView::OnDispvirbmp()  //显示原始位图
  1315. {
  1316. m_bIsStretchBlt = false;
  1317. m_DrawType = 20;
  1318. CBitmap * pOldBmp1 = m_pMDC->SelectObject(m_pBmp);
  1319. CBitmap *pOldBmp;
  1320. OnClearall();
  1321. CRect crect;
  1322. GetClientRect(&crect);
  1323. m_pMDC->FillSolidRect(&crect,RGB(255,255,255));
  1324. dc.CreateCompatibleDC(m_pMDC);
  1325. m_FileBitmap.GetBitmap(&bs);
  1326. pOldBmp=dc.SelectObject(&m_FileBitmap);
  1327. m_pMDC->BitBlt(0,0,bs.bmWidth,bs.bmHeight,&dc,0,0,SRCCOPY);
  1328. dc.SelectObject(pOldBmp);
  1329. Invalidate(false);
  1330. m_pMDC->SelectObject(pOldBmp1);
  1331. ReleaseDC(m_pMDC);
  1332. }
  1333. void CGandyDrawView::OnStrfillclient()
  1334. {
  1335. OnDispstrbmp();
  1336. m_bIsKeepingRate = false;
  1337. }
  1338. void CGandyDrawView::OnStrkeeprate() //保持宽高比缩放
  1339. {
  1340. m_DrawType = 20;
  1341. m_bIsStretchBlt = true;
  1342. m_bIsKeepingRate = true;
  1343. CBitmap * pOldBmp1 = m_pMDC->SelectObject(m_pBmp);
  1344. CBitmap *pOldBmp;
  1345. OnClearall();
  1346. CRect crect;
  1347. GetClientRect(&crect);
  1348. m_pMDC->FillSolidRect(&crect,RGB(255,255,255));
  1349. m_pMDC->SetStretchBltMode(m_iStretchBltMode);
  1350. dc.CreateCompatibleDC(m_pMDC);
  1351. dc.SetStretchBltMode(m_iStretchBltMode); //将dc设置缩放模式
  1352. m_FileBitmap.GetBitmap(&bs);
  1353. pOldBmp=dc.SelectObject(&m_FileBitmap);
  1354. if((float)(crect.right/crect.bottom) >= (float)(bs.bmWidth/bs.bmHeight) )
  1355. {
  1356. m_pMDC->StretchBlt((crect.right-bs.bmWidth*crect.bottom/bs.bmHeight)/2,0
  1357. ,bs.bmWidth*crect.bottom/bs.bmHeight,crect.bottom, &dc, 0,0,bs.bmWidth, bs.bmHeight, SRCCOPY);
  1358. }
  1359. if((float)(crect.bottom/crect.right) >= (float)(bs.bmHeight/bs.bmWidth))
  1360. {
  1361. OnClearall();
  1362. m_pMDC->StretchBlt(0,(crect.bottom-bs.bmHeight*crect.right/bs.bmWidth)/2
  1363. ,crect.right,bs.bmHeight*crect.right/bs.bmWidth, &dc, 0,0,bs.bmWidth, bs.bmHeight, SRCCOPY);
  1364. }
  1365. //m_pMDC->StretchBlt(0, 0, crect.right,crect.bottom, &dc, 0, 0, 
  1366. //bs.bmWidth, bs.bmHeight, SRCCOPY);
  1367. Invalidate(false);
  1368. dc.SelectObject(pOldBmp);
  1369. m_pMDC->SelectObject(pOldBmp1);
  1370. ReleaseDC(m_pMDC);
  1371. }
  1372. void CGandyDrawView::OnUpdateStrkeeprate(CCmdUI *pCmdUI)
  1373. {
  1374. if(m_bIsStretchBlt == true)
  1375. {
  1376. pCmdUI->Enable(true);
  1377. }
  1378. else
  1379. {
  1380. pCmdUI->Enable(false);
  1381. }
  1382. }
  1383. void CGandyDrawView::OnUpdateDispvirbmp(CCmdUI *pCmdUI)
  1384. {
  1385. if(m_bIsOpeningBmp == true)
  1386. {
  1387. pCmdUI->Enable(true);
  1388. }
  1389. else
  1390. {
  1391. pCmdUI->Enable(false);
  1392. }
  1393. }
  1394. void CGandyDrawView::OnUpdateDispstrbmp(CCmdUI *pCmdUI)
  1395. {
  1396. if(m_bIsOpeningBmp == true)
  1397. {
  1398. pCmdUI->Enable(true);
  1399. }
  1400. else
  1401. {
  1402. pCmdUI->Enable(false);
  1403. }
  1404. }
  1405. void CGandyDrawView::OnUpdateStrfillclient(CCmdUI *pCmdUI)
  1406. {
  1407. if(m_bIsStretchBlt == true)
  1408. {
  1409. pCmdUI->Enable(true);
  1410. }
  1411. else
  1412. {
  1413. pCmdUI->Enable(false);
  1414. }
  1415. }
  1416. void CGandyDrawView::OnUpdateBlackonwhite(CCmdUI *pCmdUI)
  1417. {
  1418. if(m_bIsStretchBlt == true)
  1419. {
  1420. pCmdUI->Enable(true);
  1421. }
  1422. else
  1423. {
  1424. pCmdUI->Enable(false);
  1425. }
  1426. }
  1427. void CGandyDrawView::OnUpdateWhiteonblack(CCmdUI *pCmdUI)
  1428. {
  1429. if(m_bIsStretchBlt == true)
  1430. {
  1431. pCmdUI->Enable(true);
  1432. }
  1433. else
  1434. {
  1435. pCmdUI->Enable(false);
  1436. }
  1437. }
  1438. void CGandyDrawView::OnUpdateColoroncolor(CCmdUI *pCmdUI)
  1439. {
  1440. if(m_bIsStretchBlt == true)
  1441. {
  1442. pCmdUI->Enable(true);
  1443. }
  1444. else
  1445. {
  1446. pCmdUI->Enable(false);
  1447. }
  1448. }
  1449. void CGandyDrawView::OnUpdateHalftone(CCmdUI *pCmdUI)
  1450. {
  1451. if(m_bIsStretchBlt == true)
  1452. {
  1453. pCmdUI->Enable(true);
  1454. }
  1455. else
  1456. {
  1457. pCmdUI->Enable(false);
  1458. }
  1459. }
  1460. void CGandyDrawView::OnSetwidth()
  1461. {
  1462. CSetWidthDlg setwidthdlg;
  1463. if(setwidthdlg.DoModal()==IDOK)
  1464. {
  1465. UpdateData(false);
  1466. m_iWidth = setwidthdlg.GetWidth();
  1467. }
  1468. }
  1469. void CGandyDrawView::OnJavaduke()
  1470. {
  1471. CDukeDlg dlg;
  1472. dlg.DoModal();
  1473. }
  1474. void CGandyDrawView::OnChangebmp()
  1475. {
  1476. CChangeBmp dlg;
  1477. if(dlg.DoModal()==IDOK)
  1478. {
  1479. //m_Bitmap.CreateBitmapIndirect(dlg.m_FileBitmap);
  1480. HBITMAP hBmp = (HBITMAP)LoadImage(NULL, dlg.m_BmpPathName, 
  1481. IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | 
  1482. LR_DEFAULTCOLOR | LR_DEFAULTSIZE);
  1483. if (hBmp != NULL) {
  1484. BITMAP bm;
  1485. GetObject(hBmp, sizeof(bm), &bm);
  1486. long cb = bm.bmBitsPixel * bm.bmHeight * bm.bmWidthBytes;
  1487. bm.bmBits = new char[cb];
  1488. GetBitmapBits(hBmp, cb, bm.bmBits);
  1489. m_Bitmap.CreateBitmapIndirect(&bm);
  1490. m_BmpPathName = dlg.m_BmpPathName;
  1491. //m_bBitmapLoaded = true;
  1492. }
  1493. }
  1494. }
  1495. void CGandyDrawView::OnDrawset()
  1496. {
  1497. CDrawSetDlg dlg;
  1498. // dlg.m_Bmp = m_Bitmap;
  1499. dlg.m_BmpPathName = m_BmpPathName;
  1500. dlg.m_BrushColor = m_BrushColor;
  1501. dlg.m_PenColor = m_PenColor;
  1502. dlg.m_ComboIndex = m_iPenStyle;
  1503. dlg.m_DrawRadio = m_DrawType;
  1504. dlg.m_iBruHatchStyle = m_iHatchStyle;
  1505. dlg.m_iBruStyle = m_iBrushStyle;
  1506. dlg.m_iPenWidth = m_iWidth;
  1507. if(dlg.DoModal()==IDOK)
  1508. {
  1509. // m_Bitmap =dlg.m_Bmp;
  1510. m_BmpPathName = dlg.m_BmpPathName;
  1511. m_BrushColor = dlg.m_BrushColor;
  1512. m_PenColor = dlg.m_PenColor;
  1513.    m_DrawType = dlg.m_DrawRadio;
  1514.    m_iHatchStyle = dlg.m_iBruHatchStyle;
  1515. m_iBrushStyle = dlg.m_iBruStyle;
  1516. m_iWidth = dlg.m_iPenWidth;
  1517. m_iPenStyle = dlg.m_ComboIndex;
  1518. }
  1519. }
  1520. void CGandyDrawView::OnUpdateLine(CCmdUI *pCmdUI)
  1521. {
  1522. if(m_DrawType == 0)
  1523. {
  1524. pCmdUI->SetCheck(1);
  1525. }
  1526. else 
  1527. {
  1528. pCmdUI->SetCheck(0);
  1529. }
  1530. }
  1531. void CGandyDrawView::OnUpdateEllipse(CCmdUI *pCmdUI)
  1532. {
  1533. if(m_DrawType == 4)
  1534. {
  1535. pCmdUI->SetCheck(1);
  1536. }
  1537. else 
  1538. {
  1539. pCmdUI->SetCheck(0);
  1540. }
  1541. }
  1542. void CGandyDrawView::OnUpdateEllirect(CCmdUI *pCmdUI)
  1543. {
  1544. if(m_DrawType == 3)
  1545. {
  1546. pCmdUI->SetCheck(1);
  1547. }
  1548. else 
  1549. {
  1550. pCmdUI->SetCheck(0);
  1551. }
  1552. }
  1553. void CGandyDrawView::OnUpdatePolygon(CCmdUI *pCmdUI)
  1554. {
  1555. if(m_DrawType == 5)
  1556. {
  1557. pCmdUI->SetCheck(1);
  1558. }
  1559. else 
  1560. {
  1561. pCmdUI->SetCheck(0);
  1562. }
  1563. }
  1564. void CGandyDrawView::OnUpdateRect(CCmdUI *pCmdUI)
  1565. {
  1566. if(m_DrawType == 2)
  1567. {
  1568. pCmdUI->SetCheck(1);
  1569. }
  1570. else 
  1571. {
  1572. pCmdUI->SetCheck(0);
  1573. }
  1574. }
  1575. void CGandyDrawView::OnUpdatePolyline(CCmdUI *pCmdUI)
  1576. {
  1577. if(m_DrawType == 1)
  1578. {
  1579. pCmdUI->SetCheck(1);
  1580. }
  1581. else 
  1582. {
  1583. pCmdUI->SetCheck(0);
  1584. }
  1585. }
  1586. void CGandyDrawView::OnUpdateTextdraw(CCmdUI *pCmdUI)
  1587. {
  1588. if(m_DrawType == 6)
  1589. {
  1590. pCmdUI->SetCheck(1);
  1591. }
  1592. else 
  1593. {
  1594. pCmdUI->SetCheck(0);
  1595. }
  1596. }
  1597. void CGandyDrawView::OnUpdateDash(CCmdUI *pCmdUI)
  1598. {
  1599. if(m_iPenStyle == 1)
  1600. {
  1601. pCmdUI->SetCheck(1);
  1602. }
  1603. else
  1604. {
  1605. pCmdUI->SetCheck(0);
  1606. }
  1607. }
  1608. void CGandyDrawView::OnUpdateDot(CCmdUI *pCmdUI)
  1609. {
  1610. if(m_iPenStyle == 2)
  1611. {
  1612. pCmdUI->SetCheck(1);
  1613. }
  1614. else
  1615. {
  1616. pCmdUI->SetCheck(0);
  1617. }
  1618. }
  1619. void CGandyDrawView::OnUpdateDashdot(CCmdUI *pCmdUI)
  1620. {
  1621. if(m_iPenStyle == 3)
  1622. {
  1623. pCmdUI->SetCheck(1);
  1624. }
  1625. else
  1626. {
  1627. pCmdUI->SetCheck(0);
  1628. }
  1629. }
  1630. void CGandyDrawView::OnUpdateDashdotdot(CCmdUI *pCmdUI)
  1631. {
  1632. if(m_iPenStyle == 4)
  1633. {
  1634. pCmdUI->SetCheck(1);
  1635. }
  1636. else
  1637. {
  1638. pCmdUI->SetCheck(0);
  1639. }
  1640. }
  1641. void CGandyDrawView::OnUpdateSolid(CCmdUI *pCmdUI)
  1642. {
  1643. if(m_iPenStyle == 0)
  1644. {
  1645. pCmdUI->SetCheck(1);
  1646. }
  1647. else
  1648. {
  1649. pCmdUI->SetCheck(0);
  1650. }
  1651. }
  1652. void CGandyDrawView::OnUpdateBruHollow(CCmdUI *pCmdUI)
  1653. {
  1654. if(m_iBrushStyle == 0)
  1655. {
  1656. pCmdUI->SetCheck(1);
  1657. }
  1658. else
  1659. {
  1660. pCmdUI->SetCheck(0);
  1661. }
  1662. }
  1663. void CGandyDrawView::OnUpdateBruSolid(CCmdUI *pCmdUI)
  1664. {
  1665. if(m_iBrushStyle == 1)
  1666. {
  1667. pCmdUI->SetCheck(1);
  1668. }
  1669. else
  1670. {
  1671. pCmdUI->SetCheck(0);
  1672. }
  1673. }
  1674. void CGandyDrawView::OnUpdateFillwithpicture(CCmdUI *pCmdUI)
  1675. {
  1676. if(m_iBrushStyle == 3)
  1677. {
  1678. pCmdUI->SetCheck(1);
  1679. }
  1680. else
  1681. {
  1682. pCmdUI->SetCheck(0);
  1683. }
  1684. }
  1685. void CGandyDrawView::OnUpdateStrBia(CCmdUI *pCmdUI)
  1686. {
  1687. if((m_iHatchStyle == 2)&&(m_iBrushStyle == 2))
  1688. {
  1689. pCmdUI->SetCheck(1);
  1690. }
  1691. else
  1692. {
  1693. pCmdUI->SetCheck(0);
  1694. }
  1695. }
  1696. void CGandyDrawView::OnUpdateStrBla(CCmdUI *pCmdUI)
  1697. {
  1698. if((m_iHatchStyle == 3)&&(m_iBrushStyle == 2))
  1699. {
  1700. pCmdUI->SetCheck(1);
  1701. }
  1702. else
  1703. {
  1704. pCmdUI->SetCheck(0);
  1705. }
  1706. }
  1707. void CGandyDrawView::OnUpdateStrCcro(CCmdUI *pCmdUI)
  1708. {
  1709. if((m_iHatchStyle == 5)&&(m_iBrushStyle == 2))
  1710. {
  1711. pCmdUI->SetCheck(1);
  1712. }
  1713. else
  1714. {
  1715. pCmdUI->SetCheck(0);
  1716. }
  1717. }
  1718. void CGandyDrawView::OnUpdateStrCro(CCmdUI *pCmdUI)
  1719. {
  1720. if((m_iHatchStyle == 4)&&(m_iBrushStyle == 2))
  1721. {
  1722. pCmdUI->SetCheck(1);
  1723. }
  1724. else
  1725. {
  1726. pCmdUI->SetCheck(0);
  1727. }
  1728. }
  1729. void CGandyDrawView::OnUpdateStrHor(CCmdUI *pCmdUI)
  1730. {
  1731. if((m_iHatchStyle == 0)&&(m_iBrushStyle == 2))
  1732. {
  1733. pCmdUI->SetCheck(1);
  1734. }
  1735. else
  1736. {
  1737. pCmdUI->SetCheck(0);
  1738. }
  1739. }
  1740. void CGandyDrawView::OnUpdateStrVer(CCmdUI *pCmdUI)
  1741. {
  1742. if((m_iHatchStyle == 1)&&(m_iBrushStyle == 2))
  1743. {
  1744. pCmdUI->SetCheck(1);
  1745. }
  1746. else
  1747. {
  1748. pCmdUI->SetCheck(0);
  1749. }
  1750. }
  1751. void CGandyDrawView::OnUpdateSetwidth1(CCmdUI *pCmdUI)
  1752. {
  1753. if(m_iWidth == 1)
  1754. {
  1755. pCmdUI->SetCheck(1);
  1756. }
  1757. else
  1758. {
  1759. pCmdUI->SetCheck(0);
  1760. }
  1761. }
  1762. void CGandyDrawView::OnUpdateSetwidth10(CCmdUI *pCmdUI)
  1763. {
  1764. if(m_iWidth == 10)
  1765. {
  1766. pCmdUI->SetCheck(1);
  1767. }
  1768. else
  1769. {
  1770. pCmdUI->SetCheck(0);
  1771. }
  1772. }
  1773. void CGandyDrawView::OnUpdateSetwidth2(CCmdUI *pCmdUI)
  1774. {
  1775. if(m_iWidth == 2)
  1776. {
  1777. pCmdUI->SetCheck(1);
  1778. }
  1779. else
  1780. {
  1781. pCmdUI->SetCheck(0);
  1782. }
  1783. }
  1784. void CGandyDrawView::OnUpdateSetwidth20(CCmdUI *pCmdUI)
  1785. {
  1786. if(m_iWidth == 20)
  1787. {
  1788. pCmdUI->SetCheck(1);
  1789. }
  1790. else
  1791. {
  1792. pCmdUI->SetCheck(0);
  1793. }
  1794. }
  1795. void CGandyDrawView::OnUpdateSetwidth3(CCmdUI *pCmdUI)
  1796. {
  1797. if(m_iWidth == 3)
  1798. {
  1799. pCmdUI->SetCheck(1);
  1800. }
  1801. else
  1802. {
  1803. pCmdUI->SetCheck(0);
  1804. }
  1805. }
  1806. void CGandyDrawView::OnUpdateSetwidth4(CCmdUI *pCmdUI)
  1807. {
  1808. if(m_iWidth == 4)
  1809. {
  1810. pCmdUI->SetCheck(1);
  1811. }
  1812. else
  1813. {
  1814. pCmdUI->SetCheck(0);
  1815. }
  1816. }
  1817. void CGandyDrawView::OnUpdateSetwidth50(CCmdUI *pCmdUI)
  1818. {
  1819. if(m_iWidth == 50)
  1820. {
  1821. pCmdUI->SetCheck(1);
  1822. }
  1823. else
  1824. {
  1825. pCmdUI->SetCheck(0);
  1826. }
  1827. }
  1828. void CGandyDrawView::OnUpdateSetwidth8(CCmdUI *pCmdUI)
  1829. {
  1830. if(m_iWidth == 8)
  1831. {
  1832. pCmdUI->SetCheck(1);
  1833. }
  1834. else
  1835. {
  1836. pCmdUI->SetCheck(0);
  1837. }
  1838. }