SettingDlg.cpp
上传用户:mcdz888
上传日期:2022-08-05
资源大小:118k
文件大小:4k
源码类别:

绘图程序

开发平台:

Visual C++

  1. // SettingDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "Graphic.h"
  5. #include "SettingDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CSettingDlg dialog
  13. CSettingDlg::CSettingDlg(CWnd* pParent /*=NULL*/)
  14. : CDialog(CSettingDlg::IDD, pParent)
  15. {
  16. //{{AFX_DATA_INIT(CSettingDlg)
  17. m_nLineWidth = 0;
  18. m_nLineStyle = -1;
  19. //}}AFX_DATA_INIT
  20. m_clr=RGB(255,0,0);
  21. m_brush.CreateSolidBrush(RGB(0,0,255));
  22. m_font.CreatePointFont(200,"华文行楷");
  23. }
  24. void CSettingDlg::DoDataExchange(CDataExchange* pDX)
  25. {
  26. CDialog::DoDataExchange(pDX);
  27. //{{AFX_DATA_MAP(CSettingDlg)
  28. DDX_Control(pDX, IDC_BTN_ST, m_btnST);
  29. DDX_Control(pDX, IDCANCEL, m_btnCancel);
  30. DDX_Control(pDX, IDOK, m_btnTest);
  31. DDX_Text(pDX, IDC_LINE_WIDTH, m_nLineWidth);
  32. DDX_Radio(pDX, IDC_RADIO1, m_nLineStyle);
  33. //}}AFX_DATA_MAP
  34. }
  35. BEGIN_MESSAGE_MAP(CSettingDlg, CDialog)
  36. //{{AFX_MSG_MAP(CSettingDlg)
  37. ON_EN_CHANGE(IDC_LINE_WIDTH, OnChangeLineWidth)
  38. ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
  39. ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
  40. ON_BN_CLICKED(IDC_RADIO3, OnRadio3)
  41. ON_WM_PAINT()
  42. ON_WM_CTLCOLOR()
  43. //}}AFX_MSG_MAP
  44. END_MESSAGE_MAP()
  45. /////////////////////////////////////////////////////////////////////////////
  46. // CSettingDlg message handlers
  47. void CSettingDlg::OnChangeLineWidth() 
  48. {
  49. // TODO: If this is a RICHEDIT control, the control will not
  50. // send this notification unless you override the CDialog::OnInitDialog()
  51. // function and call CRichEditCtrl().SetEventMask()
  52. // with the ENM_CHANGE flag ORed into the mask.
  53. // TODO: Add your control notification handler code here
  54. Invalidate();
  55. }
  56. void CSettingDlg::OnRadio1() 
  57. {
  58. // TODO: Add your control notification handler code here
  59. Invalidate();
  60. }
  61. void CSettingDlg::OnRadio2() 
  62. {
  63. // TODO: Add your control notification handler code here
  64. Invalidate();
  65. }
  66. void CSettingDlg::OnRadio3() 
  67. {
  68. // TODO: Add your control notification handler code here
  69. Invalidate();
  70. }
  71. void CSettingDlg::OnPaint() 
  72. {
  73. CPaintDC dc(this); // device context for painting
  74. // TODO: Add your message handler code here
  75. UpdateData();
  76. CPen pen(m_nLineStyle,m_nLineWidth,m_clr);
  77. dc.SelectObject(&pen);
  78. CRect rect;
  79. GetDlgItem(IDC_SAMPLE)->GetWindowRect(&rect);
  80. ScreenToClient(&rect);
  81. dc.MoveTo(rect.left+20,rect.top+rect.Height()/2);
  82. dc.LineTo(rect.right-20,rect.top+rect.Height()/2);
  83. // Do not call CDialog::OnPaint() for painting messages
  84. }
  85. HBRUSH CSettingDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
  86. {
  87. HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
  88. // TODO: Change any attributes of the DC here
  89. if(pWnd->GetDlgCtrlID()==IDC_LINE_STYLE)
  90. {
  91. pDC->SetTextColor(RGB(255,0,0));
  92. pDC->SetBkMode(TRANSPARENT);
  93. return m_brush;
  94. }
  95. if(pWnd->GetDlgCtrlID()==IDC_LINE_WIDTH)
  96. {
  97. pDC->SetTextColor(RGB(255,0,0));
  98. //pDC->SetBkMode(TRANSPARENT);
  99. pDC->SetBkColor(RGB(0,0,255));
  100. return m_brush;
  101. }
  102. if(pWnd->GetDlgCtrlID()==IDC_TEXT)
  103. {
  104. pDC->SelectObject(&m_font);
  105. }
  106. /*if(pWnd->GetDlgCtrlID()==IDOK)
  107. {
  108. pDC->SetTextColor(RGB(255,0,0));
  109. return m_brush;
  110. }*/
  111. // TODO: Return a different brush if the default is not desired
  112. return hbr;
  113. //return m_brush;
  114. }
  115. BOOL CSettingDlg::OnInitDialog() 
  116. {
  117. CDialog::OnInitDialog();
  118. // TODO: Add extra initialization here
  119. m_btnST.SetActiveBgColor(RGB(0,0,255));
  120. m_btnST.SetActiveFgColor(RGB(255,0,0));
  121. m_btnST.SetInactiveBgColor(RGB(255,0,255));
  122. m_btnST.SetInactiveFgColor(RGB(255,255,0));
  123. return TRUE;  // return TRUE unless you set the focus to a control
  124.               // EXCEPTION: OCX Property Pages should return FALSE
  125. }