NewEdit.cpp
上传用户:ckg1000
上传日期:2013-01-26
资源大小:630k
文件大小:3k
源码类别:

CAD

开发平台:

Visual C++

  1. // NewEdit.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "CAD2006.h"
  5. #include "NewEdit.h"
  6. #include "MainFrm.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // NewEdit
  14. NewEdit::NewEdit()
  15. {
  16. m_text = NULL;
  17. m_rect = NULL;
  18. }
  19. NewEdit::~NewEdit()
  20. {
  21. for( int i = 0; i < m_ptarray.GetSize(); i++ )
  22. {
  23. delete m_ptarray.operator [](i);
  24. }
  25. }
  26. BEGIN_MESSAGE_MAP(NewEdit, CEdit)
  27. //{{AFX_MSG_MAP(NewEdit)
  28. ON_WM_KILLFOCUS()
  29. ON_WM_CHAR()
  30. //}}AFX_MSG_MAP
  31. END_MESSAGE_MAP()
  32. /////////////////////////////////////////////////////////////////////////////
  33. // NewEdit message handlers
  34. void NewEdit::draw(CRect rect)
  35. {
  36. m_text = new CEdit;
  37. m_text->Create(WS_CHILD | WS_VISIBLE|ES_AUTOHSCROLL|ES_LEFT,rect,
  38. ::AfxGetApp()->m_pMainWnd,2000);
  39. m_text->SetLimitText(10);
  40. m_text->SetFocus();
  41. SaveText(m_text);
  42. }
  43. void NewEdit::SaveText(CEdit *m_text)
  44. {
  45. m_ptarray.Add(m_text);
  46. }
  47. void NewEdit::DeleteText(CDC * pDC, int index, CRect rect )
  48. {
  49. delete (CEdit *)m_ptarray[index];
  50. m_ptarray.RemoveAt(index);
  51. LostTextFouce(pDC,rect);
  52. }
  53. void NewEdit::SetTextFouce(CDC *pDC,CRect rect )
  54. {
  55. HBRUSH hbrush = (HBRUSH)::GetStockObject(NULL_BRUSH);
  56. CBrush *hbru = NULL;
  57. hbru = hbru->FromHandle(hbrush);
  58. CBrush* hbrutemp = pDC->SelectObject(hbru);
  59. pDC->Rectangle(&rect);
  60. pDC->SelectObject(hbrutemp);
  61. }
  62. void NewEdit::LostTextFouce(CDC *pDC, CRect rect)
  63. {
  64. HBRUSH hbrush = (HBRUSH)::GetStockObject(NULL_BRUSH);
  65. CBrush *hbru = NULL;
  66. hbru = hbru->FromHandle(hbrush);
  67. CBrush* hbrutemp = pDC->SelectObject(hbru);
  68. CPen hpen;
  69. hpen.CreatePen(PS_SOLID,1,RGB(255,255,255));
  70. CPen* pentemp = pDC->SelectObject(&hpen);
  71. //int temp = pDC->SetROP2(R2_XORPEN);
  72. pDC->Rectangle(&rect);
  73. pDC->SelectObject(hbrutemp);
  74. pDC->SelectObject(pentemp);
  75. //pDC->SetROP2(temp);
  76. }
  77. void NewEdit::SetFouceRect(CRect rect)
  78. {
  79. m_rect = rect;
  80. }
  81. CRect NewEdit::GetFouceText()
  82. {
  83. return m_rect;
  84. }
  85. void NewEdit::TextMove(CDC *pDC,CPoint pt,int index,CRect rectrect)
  86. {
  87. /* m_rect.left += pt.x - m_rect.CenterPoint().x;
  88. m_rect.top += pt.y - m_rect.CenterPoint().y;
  89. m_rect.right += pt.x - m_rect.CenterPoint().x;
  90. m_rect.bottom += pt.y - m_rect.CenterPoint().y;
  91. m_textrect.left += pt.x - m_rect.CenterPoint().x;
  92. m_textrect.top += pt.y - m_rect.CenterPoint().y;
  93. m_textrect.right += pt.x - m_rect.CenterPoint().x;
  94. m_textrect.bottom += pt.y - m_rect.CenterPoint().y;
  95. DeleteText(pDC,index,rectrect);
  96. pDC->TextOut(m_textrect.left,m_textrect.top,"DSFDS");
  97. SetTextFouce(pDC,m_rect);
  98. //m_text->ReplaceSel("sdfdsfds");*/
  99. }
  100. void NewEdit::SetFouceTextRect(CRect rect)
  101. {
  102. m_textrect = rect;
  103. }
  104. CRect NewEdit::GetFouceTextRect()
  105. {
  106. return m_textrect;
  107. }