InfoTopicBar.cpp
上传用户:maryhy001
上传日期:2007-05-02
资源大小:2317k
文件大小:3k
源码类别:

网格计算

开发平台:

Visual C++

  1. // InfoTopicBar.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "InfoTopicBar.h"
  5. // CInfoTopicBar
  6. CInfoTopicBar::CInfoTopicBar()
  7. {
  8. m_exData = 0;
  9. m_hHandCursor = NULL;
  10. m_lpsText = "Tip Info Bar Class";
  11. m_crfontcolor = RGB(255, 255, 255);
  12. m_crbackcolor = GetSysColor(COLOR_3DSHADOW);
  13. }
  14. CInfoTopicBar::~CInfoTopicBar(){}
  15. BEGIN_MESSAGE_MAP(CInfoTopicBar, CStatic)
  16. //{{AFX_MSG_MAP(CInfoTopicBar)
  17. ON_WM_PAINT()
  18. ON_WM_SETCURSOR()
  19. ON_CONTROL_REFLECT(STN_CLICKED, OnClicked)
  20. //}}AFX_MSG_MAP
  21. END_MESSAGE_MAP()
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CInfoTopicBar message handlers
  24. void CInfoTopicBar::OnPaint() 
  25. {
  26. CPaintDC dc(this); // device context for painting
  27. CRect rc;
  28. CDC memdc;
  29. int noldbkmode;
  30. CBitmap membmp, *poldbmp;
  31. CFont *poldfont;
  32. COLORREF croldfont;
  33. this->GetClientRect(&rc);
  34. memdc.CreateCompatibleDC(&dc);
  35. membmp.CreateCompatibleBitmap(&dc, rc.Width(), rc.Height());
  36. //fill the client rect.
  37. poldbmp = (CBitmap*)memdc.SelectObject(&membmp);
  38. memdc.FillSolidRect(&rc, m_crbackcolor);
  39. //select the text font.
  40. poldfont = (CFont*)memdc.SelectObject(&m_fnfont);
  41. croldfont = memdc.SetTextColor(m_crfontcolor);
  42. noldbkmode = memdc.SetBkMode(TRANSPARENT);
  43. rc.DeflateRect(2, 0);
  44. memdc.DrawText(m_lpsText, rc, DT_SINGLELINE | DT_VCENTER | DT_LEFT | DT_PATH_ELLIPSIS);
  45. //display on this.
  46. dc.BitBlt(0, 0, rc.Width(), rc.Height(), &memdc, 0, 0, SRCCOPY);
  47. //restore the prior setting.
  48. memdc.SetBkMode(noldbkmode);
  49. memdc.SetTextColor(croldfont);
  50. memdc.SelectObject(poldfont);
  51. memdc.SelectObject(poldbmp);
  52. }
  53. void CInfoTopicBar::PreSubclassWindow() 
  54. {
  55. //we want to get mouse clicks via STN_CLICKED.
  56. DWORD dwStyle = this->GetStyle();
  57. ::SetWindowLong(this->GetSafeHwnd(), GWL_STYLE, dwStyle | SS_NOTIFY);
  58. // Add your specialized code here and/or call the base class
  59. m_fnfont.CreateFont(15, 0, 0, 0, FW_BOLD, 0, 0, 0,
  60. DEFAULT_CHARSET, OUT_CHARACTER_PRECIS, CLIP_CHARACTER_PRECIS,
  61. DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Tahoma");
  62. this->m_hHandCursor = GetSysHandCursor();
  63. CStatic::PreSubclassWindow();
  64. }
  65. void CInfoTopicBar::SetBackColor(COLORREF crcolor)
  66. {
  67. this->m_crbackcolor = crcolor;
  68. }
  69. void CInfoTopicBar::SetFontColor(COLORREF crcolor)
  70. {
  71. this->m_crfontcolor = crcolor;
  72. }
  73. BOOL CInfoTopicBar::SetFont(HFONT hfont)
  74. {
  75. m_fnfont.DeleteObject();
  76. return m_fnfont.Attach(hfont);
  77. }
  78. void CInfoTopicBar::SetText(LPCTSTR lpszText)
  79. {
  80. this->m_lpsText = lpszText;
  81. Invalidate();
  82. }
  83. void CInfoTopicBar::GetText(CString strText)
  84. {
  85. strText = this->m_lpsText;
  86. }
  87. BOOL CInfoTopicBar::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
  88. {
  89. if(this->m_hHandCursor)
  90. {
  91. ::SetCursor(this->m_hHandCursor);
  92. return TRUE;
  93. }
  94. return FALSE;
  95. }
  96. void CInfoTopicBar::OnClicked()
  97. {
  98. CWnd *parWnd = this->GetParent();
  99. ASSERT(NULL != parWnd);
  100. parWnd->SendMessage(UWM_STATICCLICKED, (WPARAM)GetSafeHwnd(), 0);
  101. }