FillSetDlg.cpp
上传用户:lj3531212
上传日期:2007-06-18
资源大小:346k
文件大小:5k
源码类别:

绘图程序

开发平台:

Visual C++

  1. // FillSetDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "GraphSoft.h"
  5. #include "FillSetDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CFillSetDlg dialog
  13. CFillSetDlg::CFillSetDlg(CWnd* pParent /*=NULL*/)
  14. : CDialog(CFillSetDlg::IDD, pParent)
  15. {
  16. //{{AFX_DATA_INIT(CFillSetDlg)
  17. // NOTE: the ClassWizard will add member initialization here
  18. //}}AFX_DATA_INIT
  19. m_NoFillRect.left=1;
  20. m_NoFillRect.right=30;
  21. m_NoFillRect.top=0;
  22. m_NoFillRect.bottom=31;
  23.     
  24. m_SolidRect.left=0;
  25. m_SolidRect.right=30;
  26. m_SolidRect.top=31;
  27. m_SolidRect.bottom=61;
  28. m_nOld=0;
  29. m_nCurrent=0;
  30. m_nSelect=-1;
  31. m_nMargin=1;
  32. m_pWndParent=pParent;
  33. }
  34. void CFillSetDlg::DoDataExchange(CDataExchange* pDX)
  35. {
  36. CDialog::DoDataExchange(pDX);
  37. //{{AFX_DATA_MAP(CFillSetDlg)
  38. // NOTE: the ClassWizard will add DDX and DDV calls here
  39. //}}AFX_DATA_MAP
  40. }
  41. BEGIN_MESSAGE_MAP(CFillSetDlg, CDialog)
  42. //{{AFX_MSG_MAP(CFillSetDlg)
  43. ON_WM_KILLFOCUS()
  44. ON_WM_LBUTTONDOWN()
  45. ON_WM_LBUTTONUP()
  46. ON_WM_MOUSEMOVE()
  47. ON_WM_PAINT()
  48. //}}AFX_MSG_MAP
  49. END_MESSAGE_MAP()
  50. /////////////////////////////////////////////////////////////////////////////
  51. // CFillSetDlg message handlers
  52. BOOL CFillSetDlg::OnInitDialog() 
  53. {
  54. CDialog::OnInitDialog();
  55. // TODO: Add extra initialization here
  56. return TRUE;  // return TRUE unless you set the focus to a control
  57.               // EXCEPTION: OCX Property Pages should return FALSE
  58. }
  59. void CFillSetDlg::OnKillFocus(CWnd* pNewWnd) 
  60. {
  61. CDialog::OnKillFocus(pNewWnd);
  62. // TODO: Add your message handler code here
  63. this->PostMessage(WM_COMMAND,IDCANCEL) ;
  64. }
  65. void CFillSetDlg::OnLButtonDown(UINT nFlags, CPoint point) 
  66. {
  67. // TODO: Add your message handler code here and/or call default
  68. int i ;
  69. if(m_NoFillRect.PtInRect(point)) {
  70. SetStyle(0);
  71. this->PostMessage(WM_COMMAND,IDCANCEL) ;
  72. }else if(m_SolidRect.PtInRect(point)) {
  73. SetStyle(1);
  74. this->PostMessage(WM_COMMAND,IDCANCEL) ;
  75. CDialog::OnLButtonDown(nFlags, point);
  76. }
  77. void CFillSetDlg::OnLButtonUp(UINT nFlags, CPoint point) 
  78. {
  79. // TODO: Add your message handler code here and/or call default
  80. CDialog::OnLButtonUp(nFlags, point);
  81. }
  82. void CFillSetDlg::OnMouseMove(UINT nFlags, CPoint point) 
  83. {
  84. // TODO: Add your message handler code here and/or call default
  85. BOOL flag = FALSE ;
  86. if(m_NoFillRect.PtInRect(point)) {
  87. if(this->m_nSelect!=0) {
  88. CClientDC dc(this);  
  89. int old = m_nSelect ;
  90. m_nSelect = -1 ;
  91. if(old>=0) draw_cell(&dc,old) ;
  92. m_nSelect = 0 ;
  93. draw_cell(&dc,0) ;
  94. }
  95. flag = TRUE ;
  96. }
  97. if(!flag){
  98. if(m_SolidRect.PtInRect(point)) {
  99. if(m_nSelect!=1) {
  100. CClientDC dc(this); 
  101. int old = m_nSelect ;
  102. m_nSelect = -1 ;
  103. if(old>=0) draw_cell(&dc,old) ;
  104. m_nSelect = 1 ;
  105. draw_cell(&dc,1) ;
  106. }
  107. flag = TRUE ;
  108. }
  109. }
  110. CDialog::OnMouseMove(nFlags, point);
  111. }
  112. void CFillSetDlg::OnPaint() 
  113. {
  114. CPaintDC dc(this); // device context for painting
  115. // TODO: Add your message handler code here
  116. draw_cell(&dc,0);
  117. draw_cell(&dc,1) ;
  118. // Do not call CDialog::OnPaint() for painting messages
  119. }
  120. BOOL CFillSetDlg::GetCellRect(int i,CRect* pRect)
  121. {
  122. BOOL bRltVal=FALSE;
  123.     if(i==0){
  124. *pRect=m_NoFillRect;
  125. bRltVal=TRUE;
  126. }else if(i==1){
  127. *pRect=m_SolidRect;
  128. bRltVal=TRUE;
  129. }
  130. return bRltVal;
  131. }
  132. void CFillSetDlg::draw_cell(CDC* pDC,int i)
  133. {
  134. if(i==0) {
  135. CRect rect = m_NoFillRect ;       
  136.         // Fill background
  137.         pDC->FillSolidRect(rect, ::GetSysColor(COLOR_3DFACE));               
  138.         if (i==this->m_nSelect) pDC->DrawEdge(rect, BDR_RAISEDINNER, BF_RECT);
  139.         else if (i==this->m_nCurrent) pDC->DrawEdge(rect, BDR_SUNKENOUTER, BF_RECT);
  140. //Fill Black color
  141.         CPen   pen;
  142. pen.CreatePen(PS_SOLID, 1, ::GetSysColor(COLOR_3DSHADOW));
  143. CBrush brush ;
  144. brush.CreateSolidBrush(::GetSysColor(COLOR_3DFACE)) ;
  145. CPen*   pOldPen   = (CPen*)   pDC->SelectObject(&pen);
  146. CBrush* pOldBrush = (CBrush*) pDC->SelectObject(&brush);
  147. rect.DeflateRect(2*m_nMargin,2*m_nMargin); 
  148. pDC->Rectangle(rect);
  149. pDC->SelectObject(pOldBrush);
  150. pDC->SelectObject(pOldPen);
  151. }else if(i==1) {
  152. CRect rect = m_SolidRect ;        
  153.         // Fill background
  154.         pDC->FillSolidRect(rect, ::GetSysColor(COLOR_3DFACE));                  
  155.         if (i==this->m_nSelect) pDC->DrawEdge(rect, BDR_RAISEDINNER, BF_RECT);
  156.         else if (i==this->m_nCurrent) pDC->DrawEdge(rect, BDR_SUNKENOUTER, BF_RECT);
  157. //Fill Black color
  158.         CPen   pen;
  159. pen.CreatePen(PS_SOLID, 1, ::GetSysColor(COLOR_3DSHADOW));
  160. CBrush brush ;
  161. brush.CreateSolidBrush(RGB(0,0,0)) ;
  162. CPen*   pOldPen   = (CPen*)   pDC->SelectObject(&pen);
  163. CBrush* pOldBrush = (CBrush*) pDC->SelectObject(&brush);
  164. rect.DeflateRect(2*m_nMargin,2*m_nMargin); 
  165. pDC->Rectangle(rect);
  166. pDC->SelectObject(pOldBrush);
  167. pDC->SelectObject(pOldPen);
  168. }
  169. }
  170. void CFillSetDlg::Init()
  171. {
  172. m_nSelect=-1;
  173. }
  174. void CFillSetDlg::SetStyle(int nStyle)
  175. {
  176. m_nCurrent=nStyle;
  177. if(m_pWndParent!=NULL)
  178. m_pWndParent->PostMessage(WM_SETFILLSTYLE,WPARAM(nStyle));
  179. }