InfoTopicBar.cpp
上传用户:maryhy001
上传日期:2007-05-02
资源大小:2317k
文件大小:3k
- // InfoTopicBar.cpp : implementation file
- //
- #include "stdafx.h"
- #include "InfoTopicBar.h"
- // CInfoTopicBar
- CInfoTopicBar::CInfoTopicBar()
- {
- m_exData = 0;
- m_hHandCursor = NULL;
- m_lpsText = "Tip Info Bar Class";
- m_crfontcolor = RGB(255, 255, 255);
- m_crbackcolor = GetSysColor(COLOR_3DSHADOW);
- }
- CInfoTopicBar::~CInfoTopicBar(){}
- BEGIN_MESSAGE_MAP(CInfoTopicBar, CStatic)
- //{{AFX_MSG_MAP(CInfoTopicBar)
- ON_WM_PAINT()
- ON_WM_SETCURSOR()
- ON_CONTROL_REFLECT(STN_CLICKED, OnClicked)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CInfoTopicBar message handlers
- void CInfoTopicBar::OnPaint()
- {
- CPaintDC dc(this); // device context for painting
-
- CRect rc;
- CDC memdc;
- int noldbkmode;
- CBitmap membmp, *poldbmp;
- CFont *poldfont;
- COLORREF croldfont;
- this->GetClientRect(&rc);
- memdc.CreateCompatibleDC(&dc);
- membmp.CreateCompatibleBitmap(&dc, rc.Width(), rc.Height());
-
- //fill the client rect.
- poldbmp = (CBitmap*)memdc.SelectObject(&membmp);
- memdc.FillSolidRect(&rc, m_crbackcolor);
-
- //select the text font.
- poldfont = (CFont*)memdc.SelectObject(&m_fnfont);
- croldfont = memdc.SetTextColor(m_crfontcolor);
- noldbkmode = memdc.SetBkMode(TRANSPARENT);
- rc.DeflateRect(2, 0);
- memdc.DrawText(m_lpsText, rc, DT_SINGLELINE | DT_VCENTER | DT_LEFT | DT_PATH_ELLIPSIS);
- //display on this.
- dc.BitBlt(0, 0, rc.Width(), rc.Height(), &memdc, 0, 0, SRCCOPY);
-
- //restore the prior setting.
- memdc.SetBkMode(noldbkmode);
- memdc.SetTextColor(croldfont);
- memdc.SelectObject(poldfont);
- memdc.SelectObject(poldbmp);
- }
- void CInfoTopicBar::PreSubclassWindow()
- {
- //we want to get mouse clicks via STN_CLICKED.
- DWORD dwStyle = this->GetStyle();
- ::SetWindowLong(this->GetSafeHwnd(), GWL_STYLE, dwStyle | SS_NOTIFY);
-
- // Add your specialized code here and/or call the base class
- m_fnfont.CreateFont(15, 0, 0, 0, FW_BOLD, 0, 0, 0,
- DEFAULT_CHARSET, OUT_CHARACTER_PRECIS, CLIP_CHARACTER_PRECIS,
- DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Tahoma");
- this->m_hHandCursor = GetSysHandCursor();
-
- CStatic::PreSubclassWindow();
- }
- void CInfoTopicBar::SetBackColor(COLORREF crcolor)
- {
- this->m_crbackcolor = crcolor;
- }
- void CInfoTopicBar::SetFontColor(COLORREF crcolor)
- {
- this->m_crfontcolor = crcolor;
- }
- BOOL CInfoTopicBar::SetFont(HFONT hfont)
- {
- m_fnfont.DeleteObject();
- return m_fnfont.Attach(hfont);
- }
- void CInfoTopicBar::SetText(LPCTSTR lpszText)
- {
- this->m_lpsText = lpszText;
- Invalidate();
- }
- void CInfoTopicBar::GetText(CString strText)
- {
- strText = this->m_lpsText;
- }
- BOOL CInfoTopicBar::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
- {
- if(this->m_hHandCursor)
- {
- ::SetCursor(this->m_hHandCursor);
- return TRUE;
- }
- return FALSE;
- }
- void CInfoTopicBar::OnClicked()
- {
- CWnd *parWnd = this->GetParent();
- ASSERT(NULL != parWnd);
- parWnd->SendMessage(UWM_STATICCLICKED, (WPARAM)GetSafeHwnd(), 0);
- }