SkinEdit.cpp 3.9 KB

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