123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- /************************************************************************
- * 程序名: 精仿QQ主界面
- * 制作人: 李克平, 2011年04月11日
- * 版本号: 1.0
- ************************************************************************/
- // SkinEdit.cpp : 实现文件
- //
- #include "stdafx.h"
- #include "SkinEdit.h"
- // CSkinEdit
- IMPLEMENT_DYNAMIC(CSkinEdit, CEdit)
- CSkinEdit::CSkinEdit()
- {
- }
- CSkinEdit::~CSkinEdit()
- {
- }
- BEGIN_MESSAGE_MAP(CSkinEdit, CEdit)
- ON_WM_PAINT()
- ON_WM_NCCALCSIZE()
- ON_WM_NCLBUTTONDOWN()
- ON_WM_MOUSEMOVE()
- ON_WM_SETFOCUS()
- ON_WM_KILLFOCUS()
- ON_WM_NCHITTEST()
- END_MESSAGE_MAP()
- void CSkinEdit::OnPaint()
- {
- CPaintDC dc(this); // device context for painting
- CRect rcClient;
- GetClientRect(&rcClient);
- rcClient.left -= 15;
- rcClient.right += 33;
- rcClient.top -= 5;
- rcClient.bottom += 5;
- if (m_bmpEdit.m_hObject !=0)
- m_bmpEdit.ExtendDraw(&dc,rcClient,m_nX,m_nY);
- CRect rc=rcClient;
- rc.left = 0;
- CString strText;
- GetWindowText(strText);
- DrawText(&dc,rc,strText);
- }
- // CSkinEdit 消息处理程序
- void CSkinEdit::LoadBitmap(LPCTSTR szImagePath)
- {
- m_bmpEdit.LoadImage(szImagePath);
- }
- void CSkinEdit::SetText(CString strText, int nStart,COLORREF cr)
- {
- m_strText=strText;
- m_nTextStart=nStart;
- m_crText=cr;
- SetWindowText(strText);
- }
- BOOL CSkinEdit::DrawText(CDC *pDC,CRect rc ,CString strText)
- {
- CRect r;
- CString str;
- CRect rcButton;
- if (strText.GetLength() )
- {
- CFont *ofont;
- ofont = pDC->SelectObject( GetParent()->GetFont() );
- pDC->SetTextColor(m_crText);
- pDC->SetBkMode(TRANSPARENT);
- pDC->DrawText( strText, rc, DT_SINGLELINE | DT_VCENTER );
- pDC->SelectObject(ofont);
- }
- return TRUE;
- }
- CRect CSkinEdit::GetRectInParent()
- {
- CRect rcWindowParent;
- GetParent()->GetWindowRect(rcWindowParent);//client
- CRect rcWindow;
- GetWindowRect(&rcWindow);
- CRect rect;
- rect.left = rcWindow.left-rcWindowParent.left;
- rect.top = rcWindow.top-rcWindowParent.top;
- rect.right = rcWindow.right-rcWindowParent.left;
- rect.bottom = rcWindow.bottom-rcWindowParent.top;
- return rect;
- }
- void CSkinEdit::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS* lpncsp)
- {
- // TODO: 在此添加消息处理程序代码和/或调用默认值
- lpncsp->rgrc->left += 15;
- lpncsp->rgrc->right -= 33;
- lpncsp->rgrc->top += 5;
- lpncsp->rgrc->bottom -= 5;
- CEdit::OnNcCalcSize(bCalcValidRects, lpncsp);
- }
- void CSkinEdit::OnNcLButtonDown(UINT nHitTest, CPoint point)
- {
- // TODO: 在此添加消息处理程序代码和/或调用默认值
- //POINT pt = {point.x,param.mousept.y};
- SetWindowText(_T(""));
- RECT rc;
- GetWindowRect(&rc);
- //rc.left = rc.right - 14;
- //rc.right = rc.left + 8;
- //if(PtInRect(&rc,point))
- //{
- // if(m_rm)
- // m_rm->Popup(m_hWnd);
- //}
- CEdit::OnNcLButtonDown(nHitTest, point);
- }
- void CSkinEdit::OnMouseMove(UINT nFlags, CPoint point)
- {
- // TODO: 在此添加消息处理程序代码和/或调用默认值
- //CRect rect;
- //GetWindowRect(&rect);
- //if (!rect.PtInRect(point))
- //{
- // ReleaseCapture();
- //}
- CEdit::OnMouseMove(nFlags, point);
- }
- void CSkinEdit::OnSetFocus(CWnd* pOldWnd)
- {
- CEdit::OnSetFocus(pOldWnd);
- CString str;
- GetWindowText(str);
- if(str == m_strText)
- {
- SetWindowText(_T(""));
- //SetTextColor(RGB(0,0,0));
- }
- // TODO: 在此处添加消息处理程序代码
- }
- void CSkinEdit::OnKillFocus(CWnd* pNewWnd)
- {
- CEdit::OnKillFocus(pNewWnd);
- CString str;
- GetWindowText(str);
- if(str.IsEmpty())
- {
- SetWindowText(m_strText);
- }
- // TODO: 在此处添加消息处理程序代码
- }
- LRESULT CSkinEdit::OnNcHitTest(CPoint point)
- {
- // TODO: 在此添加消息处理程序代码和/或调用默认值
- //LRESULT res = 0;
- //if(res != HTCLIENT)
- // res = HTCAPTION;
- //return res;
- return CEdit::OnNcHitTest(point);
- }
- BOOL CSkinEdit::PreTranslateMessage(MSG* pMsg)
- {
- // TODO: 在此添加专用代码和/或调用基类
- if(pMsg->wParam == WM_LBUTTONDOWN && pMsg->hwnd != m_hWnd)
- {
- pMsg->wParam = HTCAPTION;
- }
- //if (pMsg->message == WM_LBUTTONDOWN && pMsg->hwnd == m_hWnd)
- //{
- // pMsg->message = WM_NCLBUTTONDOWN;
- // pMsg->wParam = HTCAPTION;
- //}
- return CEdit::PreTranslateMessage(pMsg);
- }
|