DLineDlg1.cpp
Upload User: qiye66671
Upload Date: 2009-12-10
Package Size: 182k
Code Size: 9k
Category:

Graph Drawing

Development Platform:

C/C++

  1. // DLineDlg1.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "EastDraw.h"
  5. #include "DLineDlg1.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CDLineDlg1 property page
  13. IMPLEMENT_DYNCREATE(CDLineDlg1, CPropertyPage)
  14. CDLineDlg1::CDLineDlg1() : CPropertyPage(CDLineDlg1::IDD)
  15. {
  16. //{{AFX_DATA_INIT(CDLineDlg1)
  17. m_Edit_LineWidth = 1;
  18. m_radio_BrushHatch = 0;
  19. m_radio_BrushStyle = 0;
  20. //}}AFX_DATA_INIT
  21.     m_PenStyle=PS_SOLID;
  22. m_BrushStyle=BS_HOLLOW;
  23.      m_BKMode=OPAQUE;  
  24. }
  25. CDLineDlg1::~CDLineDlg1()
  26. {
  27. }
  28. void CDLineDlg1::DoDataExchange(CDataExchange* pDX)
  29. {
  30. CPropertyPage::DoDataExchange(pDX);
  31. //{{AFX_DATA_MAP(CDLineDlg1)
  32. DDX_Control(pDX, IDC_COMBO_BackgroundMode, m_Combo_BackgroundMode);
  33. DDX_Control(pDX, IDC_RADIO6_bs_hollow, m_radio_bs_Hollow);
  34. DDX_Control(pDX, IDC_RADIO_Ps_Solid, m_radio_ps_Solid);
  35. DDX_Control(pDX, IDC_RADIO_HS_VERTICAL, m_radio_vertical);
  36. DDX_Control(pDX, IDC_RADIO14_HS_HORIZONTAL, m_radio_horizontal);
  37. DDX_Control(pDX, IDC_RADIO13_HS_FDIAGONAL, m_radio_fdiagonal);
  38. DDX_Control(pDX, IDC_RADIO11_HS_DIAGCROSS, m_radio_diagcross);
  39. DDX_Control(pDX, IDC_RADIO9_HS_BDIAGONAL, m_radio_bdiagonal);
  40. DDX_Control(pDX, IDC_RADIO10_HS_CROSS, m_radio_corss);
  41. DDX_Control(pDX, IDC_STATIC_ShowBrushResult, m_Static_ShowBrushResult);
  42. DDX_Control(pDX, IDC_STATIC_ShowPenStyle, m_Static_ShowPenStyle);
  43. DDX_Control(pDX, IDC_SPIN_DDLineWidth, m_Spin_DLine_Width);
  44. DDX_Text(pDX, IDC_EDIT_LineWidth, m_Edit_LineWidth);
  45. DDV_MinMaxUInt(pDX, m_Edit_LineWidth, 1, 10000);
  46. DDX_Radio(pDX, IDC_RADIO9_HS_BDIAGONAL, m_radio_BrushHatch);
  47. DDX_Radio(pDX, IDC_RADIO6_bs_hollow, m_radio_BrushStyle);
  48. //}}AFX_DATA_MAP
  49. m_Combo_BackgroundMode.SetCurSel(m_BKMode==OPAQUE?0:1);
  50. }
  51. BEGIN_MESSAGE_MAP(CDLineDlg1, CPropertyPage)
  52. //{{AFX_MSG_MAP(CDLineDlg1)
  53. ON_BN_CLICKED(IDC_RADIO_Ps_Solid, OnRADIOPsSolid)
  54. ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
  55. ON_BN_CLICKED(IDC_RADIO3, OnRadio3)
  56. ON_BN_CLICKED(IDC_RADIO4, OnRadio4)
  57. ON_BN_CLICKED(IDC_RADIO5, OnRadio5)
  58. ON_BN_CLICKED(IDC_RADIO15, OnRadio15)
  59. ON_BN_CLICKED(IDC_RADIO16, OnRadio16)
  60. ON_WM_PAINT()
  61. ON_BN_CLICKED(IDC_RADIO6_bs_hollow, OnRADIO6bshollow)
  62. ON_BN_CLICKED(IDC_RADIO7_bs_solid, OnRADIO7bssolid)
  63. ON_BN_CLICKED(IDC_RADIO8_hatched, OnRADIO8hatched)
  64. ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_DDLineWidth, OnDeltaposSPINDDLineWidth)
  65. ON_EN_CHANGE(IDC_EDIT_LineWidth, OnChangeEDITLineWidth)
  66. ON_BN_CLICKED(IDC_RADIO9_HS_BDIAGONAL, OnRadioHs)
  67. ON_WM_CTLCOLOR()
  68. ON_BN_CLICKED(IDC_RADIO11_HS_DIAGCROSS, OnRadioHs)
  69. ON_BN_CLICKED(IDC_RADIO13_HS_FDIAGONAL, OnRadioHs)
  70. ON_BN_CLICKED(IDC_RADIO10_HS_CROSS, OnRadioHs)
  71. ON_BN_CLICKED(IDC_RADIO14_HS_HORIZONTAL, OnRadioHs)
  72. ON_BN_CLICKED(IDC_RADIO_HS_VERTICAL, OnRadioHs)
  73. ON_CBN_SELCHANGE(IDC_COMBO_BackgroundMode, OnSelchangeCOMBOBackgroundMode)
  74. //}}AFX_MSG_MAP
  75. END_MESSAGE_MAP()
  76. /////////////////////////////////////////////////////////////////////////////
  77. // CDLineDlg1 message handlers
  78. #include "DLineProperty.h"
  79. BOOL CDLineDlg1::OnInitDialog() 
  80. {
  81. CPropertyPage::OnInitDialog();
  82. // TODO: Add extra initialization here
  83. m_Spin_DLine_Width.SetBase(1);
  84. m_Spin_DLine_Width.SetPos(1);
  85. m_Spin_DLine_Width.SetRange(1,1000);
  86. m_radio_bdiagonal.SetCheck(2);
  87.     m_radio_ps_Solid.SetCheck(2);
  88. m_radio_bs_Hollow.SetCheck(2);
  89.     m_BrushHatch=HS_BDIAGONAL;
  90. m_Combo_BackgroundMode.SetCurSel(0);
  91.     
  92. return TRUE;  // return TRUE unless you set the focus to a control
  93.               // EXCEPTION: OCX Property Pages should return FALSE
  94. }
  95. void CDLineDlg1::OnRADIOPsSolid() 
  96. {
  97. // TODO: Add your control notification handler code here
  98.   m_PenStyle=PS_SOLID;
  99.   OnChangePenStyle();
  100. }
  101. void CDLineDlg1::OnRadio2() 
  102. {
  103. // TODO: Add your control notification handler code here
  104.   m_PenStyle=PS_DASH;
  105.   OnChangePenStyle();
  106. }
  107. void CDLineDlg1::OnRadio3() 
  108. {
  109. // TODO: Add your control notification handler code here
  110.   m_PenStyle=PS_DOT;
  111.   OnChangePenStyle();
  112. }
  113. void CDLineDlg1::OnRadio4() 
  114. {
  115. // TODO: Add your control notification handler code here
  116.   m_PenStyle=PS_DASHDOT;
  117.  
  118.   OnChangePenStyle();
  119. }
  120. void CDLineDlg1::OnRadio5() 
  121. {
  122. // TODO: Add your control notification handler code here
  123.   m_PenStyle=PS_DASHDOTDOT;
  124.   OnChangePenStyle();   
  125. }
  126. void CDLineDlg1::OnRadio15() 
  127. {
  128. // TODO: Add your control notification handler code here
  129.   m_PenStyle=PS_NULL;
  130.   OnChangePenStyle();
  131. }
  132. void CDLineDlg1::OnRadio16() 
  133. {
  134. // TODO: Add your control notification handler code here
  135.   m_PenStyle=PS_INSIDEFRAME;
  136.   OnChangePenStyle();
  137. }
  138. void CDLineDlg1::OnPaint() 
  139. {
  140.   CPaintDC dc(this); // device context for painting
  141. // TODO: Add your message handler code here
  142.   OnChangePenStyle();
  143.   OnChangeBrushStyle(m_BrushStyle==BS_HATCHED);
  144.   
  145. // Do not call CPropertyPage::OnPaint() for painting messages
  146. }
  147. void CDLineDlg1::OnChangePenStyle()
  148. {
  149.   UpdateData();
  150.   CDC * pDC; 
  151.   CRect rect;
  152.   CPen pen;
  153.   CBrush brush;
  154.   CDLineProperty*parent=(CDLineProperty*)this->GetParent();
  155.   this->m_PenColor=parent->m_DLineDlg2->m_PenColor;
  156.   brush.CreateSolidBrush(RGB(255,255,255));
  157.   pDC=m_Static_ShowPenStyle.GetDC();
  158.   pen.CreatePen(m_PenStyle,m_Edit_LineWidth>10?10:m_Edit_LineWidth,m_PenColor);
  159.   CPen*oldpen=pDC->SelectObject(&pen);
  160.   
  161.   m_Static_ShowPenStyle.GetClientRect(&rect);
  162.   pDC->FillRect(&rect,&brush);
  163.   
  164.   brush.DeleteObject();
  165.   LOGBRUSH brushlog;
  166.   brushlog.lbColor=m_BrushColor;
  167.   brushlog.lbHatch=m_BrushHatch;
  168.   brushlog.lbStyle=m_BrushStyle;
  169.   brush.CreateBrushIndirect(&brushlog);
  170.   CBrush*OldBrush=pDC->SelectObject(&brush);
  171.   int oldBKMode=pDC->SetBkMode(m_BKMode);
  172.   int oldBkColor=pDC->SetBkColor(parent->m_DLineDlg2->m_BackgroundColor);
  173.   pDC->MoveTo(rect.left+5,rect.Height()/2);
  174.   pDC->LineTo(rect.right-5,rect.Height()/2);
  175.   
  176.   pDC->SelectObject(oldpen);
  177.   pDC->SetBkMode(oldBKMode);
  178.   pDC->SelectObject(OldBrush);
  179.   m_Static_ShowPenStyle.ReleaseDC(pDC);
  180. }
  181. void CDLineDlg1::OnChangeBrushStyle(BOOL isHatched)
  182. {
  183.     m_radio_vertical.EnableWindow(isHatched);
  184. m_radio_horizontal.EnableWindow(isHatched);
  185. m_radio_fdiagonal.EnableWindow(isHatched);
  186. m_radio_diagcross.EnableWindow(isHatched);
  187. m_radio_bdiagonal.EnableWindow(isHatched);
  188. m_radio_corss.EnableWindow(isHatched);
  189.   UpdateData();
  190.   CDC * pDC; 
  191.   CRect rect;
  192.   CBrush brush;
  193.   
  194.   pDC=m_Static_ShowBrushResult.GetDC();
  195.   m_Static_ShowBrushResult.GetClientRect(&rect);
  196.   
  197.   CDLineProperty*parent=(CDLineProperty*)this->GetParent();
  198.   this->m_BrushColor=parent->m_DLineDlg2->m_BrushColor;
  199.   
  200.   brush.CreateSolidBrush(RGB(255,255,255));
  201.   pDC->FillRect(&rect,&brush);
  202.   brush.DeleteObject();
  203.   
  204.   
  205.   LOGBRUSH brushlog;
  206.   brushlog.lbColor=m_BrushColor;
  207.   brushlog.lbHatch=m_BrushHatch;
  208.   brushlog.lbStyle=m_BrushStyle;
  209.   brush.CreateBrushIndirect(&brushlog);
  210.   int oldBKMode=pDC->SetBkMode(m_BKMode);
  211.   COLORREF oldBkColor=pDC->SetBkColor(parent->m_DLineDlg2->m_BackgroundColor);
  212.   pDC->SelectObject(&brush);
  213.   pDC->Rectangle(rect);
  214.   m_Static_ShowBrushResult.ReleaseDC(pDC);
  215. }
  216. void CDLineDlg1::OnRADIO6bshollow() 
  217. {
  218. // TODO: Add your control notification handler code here
  219.   m_BrushStyle=BS_HOLLOW;
  220.   OnChangeBrushStyle(false);
  221. }
  222. void CDLineDlg1::OnRADIO7bssolid() 
  223. {
  224. // TODO: Add your control notification handler code here
  225.   m_BrushStyle=BS_SOLID;
  226.   OnChangeBrushStyle(false);
  227. }
  228. void CDLineDlg1::OnRADIO8hatched() 
  229. {
  230. // TODO: Add your control notification handler code here
  231.   
  232.   //m_radio_BDIAGONAL.EnableTypeLib();
  233.   m_BrushStyle=BS_HATCHED;
  234.   OnChangeBrushStyle(true);
  235. }
  236. void CDLineDlg1::OnDeltaposSPINDDLineWidth(NMHDR* pNMHDR, LRESULT* pResult) 
  237. {
  238. NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
  239. // TODO: Add your control notification handler code here
  240. OnChangePenStyle();
  241. *pResult = 0;
  242. }
  243. void CDLineDlg1::OnChangeEDITLineWidth() 
  244. {
  245. // TODO: If this is a RICHEDIT control, the control will not
  246. // send this notification unless you override the CPropertyPage::OnInitDialog()
  247. // function and call CRichEditCtrl().SetEventMask()
  248. // with the ENM_CHANGE flag ORed into the mask.
  249. // TODO: Add your control notification handler code here
  250.   if(this->IsWindowVisible())
  251.   {
  252. UpdateData();
  253. OnChangePenStyle();
  254.   }
  255. }
  256. void CDLineDlg1::OnRadioHs() 
  257. {
  258. // TODO: Add your control notification handler code here
  259. UpdateData();
  260. switch(m_radio_BrushHatch)
  261. {
  262.     case 0:m_BrushHatch=HS_BDIAGONAL;  break;
  263.     case 1:m_BrushHatch=HS_DIAGCROSS;  break;
  264.     case 2:m_BrushHatch=HS_FDIAGONAL;  break;
  265.     case 3:m_BrushHatch=HS_CROSS;      break;
  266. case 4:m_BrushHatch=HS_HORIZONTAL; break;
  267. case 5:m_BrushHatch=HS_VERTICAL;   break;
  268. }
  269. OnChangeBrushStyle(true);
  270. }
  271. HBRUSH CDLineDlg1::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
  272. {
  273. HBRUSH hbr = CPropertyPage::OnCtlColor(pDC, pWnd, nCtlColor);
  274. // TODO: Change any attributes of the DC here
  275. // TODO: Return a different brush if the default is not desired
  276.   // brush.CreateSolidBrush(RGB(230,254,255));
  277.    pDC->SetTextColor(RGB(0,100,255));
  278.    pDC->SetBkColor(RGB(118,143,255));
  279.    pDC->SelectObject(&brush);
  280.    pDC->SetBkMode(TRANSPARENT);
  281.   // hbr=(HBRUSH)brush.m_hObject;
  282.    return hbr;
  283. }
  284. void CDLineDlg1::OnSelchangeCOMBOBackgroundMode() 
  285. {
  286. // TODO: Add your control notification handler code here
  287. m_BKMode=m_Combo_BackgroundMode.GetCurSel()==0?OPAQUE:TRANSPARENT;
  288. this->OnChangePenStyle();
  289. this->OnChangeBrushStyle(true);
  290. }