SkinEdit.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /************************************************************************
  2. * 程序名: 精仿QQ主界面
  3. * 制作人: 李克平, 2011年04月11日
  4. * 版本号: 1.0
  5. ************************************************************************/
  6. // SkinEdit.cpp : 实现文件
  7. //
  8. #include "stdafx.h"
  9. #include "SkinEdit.h"
  10. // CSkinEdit
  11. IMPLEMENT_DYNAMIC(CSkinEdit, CEdit)
  12. CSkinEdit::CSkinEdit()
  13. {
  14. }
  15. CSkinEdit::~CSkinEdit()
  16. {
  17. }
  18. BEGIN_MESSAGE_MAP(CSkinEdit, CEdit)
  19. ON_WM_PAINT()
  20. ON_WM_NCCALCSIZE()
  21. ON_WM_NCLBUTTONDOWN()
  22. ON_WM_MOUSEMOVE()
  23. ON_WM_SETFOCUS()
  24. ON_WM_KILLFOCUS()
  25. ON_WM_NCHITTEST()
  26. END_MESSAGE_MAP()
  27. void CSkinEdit::OnPaint()
  28. {
  29. CPaintDC dc(this); // device context for painting
  30. CRect rcClient;
  31. GetClientRect(&rcClient);
  32. rcClient.left -= 15;
  33. rcClient.right += 33;
  34. rcClient.top -= 5;
  35. rcClient.bottom += 5;
  36. if (m_bmpEdit.m_hObject !=0)
  37. m_bmpEdit.ExtendDraw(&dc,rcClient,m_nX,m_nY);
  38. CRect rc=rcClient;
  39. rc.left = 0;
  40. CString strText;
  41. GetWindowText(strText);
  42. DrawText(&dc,rc,strText);
  43. }
  44. // CSkinEdit 消息处理程序
  45. void CSkinEdit::LoadBitmap(LPCTSTR szImagePath)
  46. {
  47. m_bmpEdit.LoadImage(szImagePath);
  48. }
  49. void CSkinEdit::SetText(CString strText, int nStart,COLORREF cr)
  50. {
  51. m_strText=strText;
  52. m_nTextStart=nStart;
  53. m_crText=cr;
  54. SetWindowText(strText);
  55. }
  56. BOOL CSkinEdit::DrawText(CDC *pDC,CRect rc ,CString strText)
  57. {
  58. CRect r;
  59. CString str;
  60. CRect rcButton;
  61. if (strText.GetLength() )
  62. {
  63. CFont *ofont;
  64. ofont = pDC->SelectObject( GetParent()->GetFont() );
  65. pDC->SetTextColor(m_crText);
  66. pDC->SetBkMode(TRANSPARENT);
  67. pDC->DrawText( strText, rc, DT_SINGLELINE | DT_VCENTER );
  68. pDC->SelectObject(ofont);
  69. }
  70. return TRUE;
  71. }
  72. CRect CSkinEdit::GetRectInParent()
  73. {
  74. CRect rcWindowParent;
  75. GetParent()->GetWindowRect(rcWindowParent);//client
  76. CRect rcWindow;
  77. GetWindowRect(&rcWindow);
  78. CRect rect;
  79. rect.left = rcWindow.left-rcWindowParent.left;
  80. rect.top = rcWindow.top-rcWindowParent.top;
  81. rect.right = rcWindow.right-rcWindowParent.left;
  82. rect.bottom = rcWindow.bottom-rcWindowParent.top;
  83. return rect;
  84. }
  85. void CSkinEdit::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS* lpncsp)
  86. {
  87. // TODO: 在此添加消息处理程序代码和/或调用默认值
  88. lpncsp->rgrc->left += 15;
  89. lpncsp->rgrc->right -= 33;
  90. lpncsp->rgrc->top += 5;
  91. lpncsp->rgrc->bottom -= 5;
  92. CEdit::OnNcCalcSize(bCalcValidRects, lpncsp);
  93. }
  94. void CSkinEdit::OnNcLButtonDown(UINT nHitTest, CPoint point)
  95. {
  96. // TODO: 在此添加消息处理程序代码和/或调用默认值
  97. //POINT pt = {point.x,param.mousept.y};
  98. SetWindowText(_T(""));
  99. RECT rc;
  100. GetWindowRect(&rc);
  101. //rc.left = rc.right - 14;
  102. //rc.right = rc.left + 8;
  103. //if(PtInRect(&rc,point))
  104. //{
  105. // if(m_rm)
  106. // m_rm->Popup(m_hWnd);
  107. //}
  108. CEdit::OnNcLButtonDown(nHitTest, point);
  109. }
  110. void CSkinEdit::OnMouseMove(UINT nFlags, CPoint point)
  111. {
  112. // TODO: 在此添加消息处理程序代码和/或调用默认值
  113. //CRect rect;
  114. //GetWindowRect(&rect);
  115. //if (!rect.PtInRect(point))
  116. //{
  117. // ReleaseCapture();
  118. //}
  119. CEdit::OnMouseMove(nFlags, point);
  120. }
  121. void CSkinEdit::OnSetFocus(CWnd* pOldWnd)
  122. {
  123. CEdit::OnSetFocus(pOldWnd);
  124. CString str;
  125. GetWindowText(str);
  126. if(str == m_strText)
  127. {
  128. SetWindowText(_T(""));
  129. //SetTextColor(RGB(0,0,0));
  130. }
  131. // TODO: 在此处添加消息处理程序代码
  132. }
  133. void CSkinEdit::OnKillFocus(CWnd* pNewWnd)
  134. {
  135. CEdit::OnKillFocus(pNewWnd);
  136. CString str;
  137. GetWindowText(str);
  138. if(str.IsEmpty())
  139. {
  140. SetWindowText(m_strText);
  141. }
  142. // TODO: 在此处添加消息处理程序代码
  143. }
  144. LRESULT CSkinEdit::OnNcHitTest(CPoint point)
  145. {
  146. // TODO: 在此添加消息处理程序代码和/或调用默认值
  147. //LRESULT res = 0;
  148. //if(res != HTCLIENT)
  149. // res = HTCAPTION;
  150. //return res;
  151. return CEdit::OnNcHitTest(point);
  152. }
  153. BOOL CSkinEdit::PreTranslateMessage(MSG* pMsg)
  154. {
  155. // TODO: 在此添加专用代码和/或调用基类
  156. if(pMsg->wParam == WM_LBUTTONDOWN && pMsg->hwnd != m_hWnd)
  157. {
  158. pMsg->wParam = HTCAPTION;
  159. }
  160. //if (pMsg->message == WM_LBUTTONDOWN && pMsg->hwnd == m_hWnd)
  161. //{
  162. // pMsg->message = WM_NCLBUTTONDOWN;
  163. // pMsg->wParam = HTCAPTION;
  164. //}
  165. return CEdit::PreTranslateMessage(pMsg);
  166. }