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

CAD

开发平台:

Visual C++

  1. // NewEditWrite.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "CAD2006.h"
  5. #include "NewEditWrite.h"
  6. #include "CAD2006View.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. static int index = -1;
  13. static bool bln = false;
  14. /////////////////////////////////////////////////////////////////////////////
  15. // NewEditWrite
  16. NewEditWrite::NewEditWrite()
  17. {
  18. }
  19. NewEditWrite::~NewEditWrite()
  20. {
  21. }
  22. BEGIN_MESSAGE_MAP(NewEditWrite, CEdit)
  23. //{{AFX_MSG_MAP(NewEditWrite)
  24. ON_CONTROL_REFLECT(EN_CHANGE, OnChange)
  25. ON_CONTROL_REFLECT(EN_SETFOCUS, OnSetfocus)
  26. ON_WM_KEYDOWN()
  27. //}}AFX_MSG_MAP
  28. END_MESSAGE_MAP()
  29. /////////////////////////////////////////////////////////////////////////////
  30. // NewEditWrite message handlers
  31. void NewEditWrite::OnChange() 
  32. {
  33. // TODO: Add your control notification handler code here
  34. CString text;
  35. NewListBox * m_listbox = (NewListBox *)::AfxGetApp()->m_pMainWnd;
  36. this->GetWindowText(text);
  37. index = text.Find("::");
  38. if( bln )
  39. {
  40. // CMainFrame *m_frame = (CMainFrame *)::AfxGetApp()->m_pMainWnd;
  41. // select = m_list->SelectString(-1,(LPCTSTR)text.operator [](index + 2));
  42. TCHAR a = text.operator [](index + 2);
  43. m_listbox->Find(&"121345");
  44. }
  45. if( index != -1 )
  46. {
  47. CPoint m_point;
  48. int i = text.Find("::");
  49. m_point = this->PosFromChar(i+1);
  50. ::AfxGetApp()->m_pMainWnd->ClientToScreen(&m_point);
  51. CRect rect;
  52. rect.left = m_point.x;
  53. rect.top = m_point.y-20;
  54. rect.right = m_point.x+250;
  55. rect.bottom = m_point.y+40;
  56. m_listbox->Draw(rect);
  57. bln = true;
  58. }
  59. }
  60. void NewEditWrite::OnSetfocus() 
  61. {
  62. // TODO: Add your control notification handler code here
  63. bln= false;
  64. CPoint m_point = this->PosFromChar(' ');
  65. ::AfxGetApp()->m_pMainWnd->ClientToScreen(&m_point);
  66. }
  67. void NewEditWrite::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
  68. {
  69. // TODO: Add your message handler code here and/or call default
  70. if( nChar == 13 )
  71. {
  72. NewListBox * m_listbox = (NewListBox *)::AfxGetApp()->m_pMainWnd;
  73. CString text;
  74. this->GetWindowText(text);
  75. text.MakeLower();
  76. int line = text.Find(&"line(");
  77. int rect = text.Find(&"rect(");
  78. int circle = text.Find(&"circle(");
  79. if( line != -1 )
  80. {
  81. CString temp1;
  82. CString temp4;
  83. CString x;
  84. CString y;
  85. CString x1;
  86. CString y1;
  87. CPoint pointbegin;
  88. CPoint pointend;
  89. ::AfxExtractSubString(temp1,text.operator LPCTSTR(),0,',');
  90. ::AfxExtractSubString(y,text.operator LPCTSTR(),1,',');
  91. ::AfxExtractSubString(x1,text.operator LPCTSTR(),2,',');
  92. ::AfxExtractSubString(temp4,text.operator LPCTSTR(),3,',');
  93. AfxExtractSubString(x,temp1.operator LPCTSTR(),1,'(');
  94. AfxExtractSubString(y1,temp4.operator LPCTSTR(),0,')');
  95. pointbegin.x = atoi(x.operator LPCTSTR());
  96. pointbegin.y = atoi(y.operator LPCTSTR());
  97. pointend.x = atoi(x1.operator LPCTSTR());
  98. pointend.y = atoi(y1.operator LPCTSTR());
  99. //::AfxGetApp()->GetMainWnd()->ScreenToClient(&pointbegin);
  100. //::AfxGetApp()->GetMainWnd()->ScreenToClient(&pointend);
  101. ::AfxGetApp()->m_pMainWnd->GetDC()->MoveTo(pointbegin);
  102. ::AfxGetApp()->m_pMainWnd->GetDC()->LineTo(pointend);
  103. SetWindowText("");
  104. this->SetFocus();
  105. }
  106. else if( rect != -1 )
  107. {
  108. CString temp1;
  109. CString temp4;
  110. CString x;
  111. CString y;
  112. CString x1;
  113. CString y1;
  114. CPoint pointbegin;
  115. CPoint pointend;
  116. ::AfxExtractSubString(temp1,text.operator LPCTSTR(),0,',');
  117. ::AfxExtractSubString(y,text.operator LPCTSTR(),1,',');
  118. ::AfxExtractSubString(x1,text.operator LPCTSTR(),2,',');
  119. ::AfxExtractSubString(temp4,text.operator LPCTSTR(),3,',');
  120. AfxExtractSubString(x,temp1.operator LPCTSTR(),1,'(');
  121. AfxExtractSubString(y1,temp4.operator LPCTSTR(),0,')');
  122. pointbegin.x = atoi(x.operator LPCTSTR());
  123. pointbegin.y = atoi(y.operator LPCTSTR());
  124. pointend.x = atoi(x1.operator LPCTSTR());
  125. pointend.y = atoi(y1.operator LPCTSTR());
  126. //::AfxGetApp()->GetMainWnd()->ScreenToClient(&pointbegin);
  127. //::AfxGetApp()->GetMainWnd()->ScreenToClient(&pointend);
  128. ::AfxGetApp()->m_pMainWnd->GetDC()->Rectangle(pointbegin.x,pointbegin.y,pointend.x,pointend.y);
  129. SetWindowText("");
  130. }
  131. else if( circle != -1 )
  132. {
  133. CString temp1;
  134. CString temp4;
  135. CString x;
  136. CString y;
  137. CString x1;
  138. CString y1;
  139. CPoint pointbegin;
  140. CPoint pointend;
  141. ::AfxExtractSubString(temp1,text.operator LPCTSTR(),0,',');
  142. ::AfxExtractSubString(y,text.operator LPCTSTR(),1,',');
  143. ::AfxExtractSubString(x1,text.operator LPCTSTR(),2,',');
  144. ::AfxExtractSubString(temp4,text.operator LPCTSTR(),3,',');
  145. AfxExtractSubString(x,temp1.operator LPCTSTR(),1,'(');
  146. AfxExtractSubString(y1,temp4.operator LPCTSTR(),0,')');
  147. pointbegin.x = atoi(x.operator LPCTSTR());
  148. pointbegin.y = atoi(y.operator LPCTSTR());
  149. pointend.x = atoi(x1.operator LPCTSTR());
  150. pointend.y = atoi(y1.operator LPCTSTR());
  151. //::AfxGetApp()->GetMainWnd()->ScreenToClient(&pointbegin);
  152. //::AfxGetApp()->GetMainWnd()->ScreenToClient(&pointend);
  153. ::AfxGetApp()->m_pMainWnd->GetDC()->Ellipse(pointbegin.x,pointbegin.y,pointend.x,pointend.y);
  154. SetWindowText("");
  155. }
  156. else if( !text.IsEmpty() )
  157. {
  158. ::AfxMessageBox("语法错误,请重新输入!");
  159. SetWindowText("");
  160. SetFocus();
  161. }
  162. }
  163. CEdit::OnKeyDown(nChar, nRepCnt, nFlags);
  164. }