DragCaption.cpp
上传用户:rxhxxy
上传日期:2007-01-02
资源大小:72k
文件大小:2k
源码类别:

TreeView控件

开发平台:

Visual C++

  1. #include "StdAfx.h"
  2. #include "DragCaption.h"
  3. #ifdef _DEBUG
  4. #define new DEBUG_NEW
  5. #undef THIS_FILE
  6. static char THIS_FILE[] = __FILE__;
  7. #endif
  8. COLORREF CDragCaption::g_colorUnvisited = RGB(0,0,255);  // blue
  9. COLORREF CDragCaption::g_colorVisited   = RGB(128,0,128);  // purple
  10. IMPLEMENT_DYNAMIC(CDragCaption, CStatic)
  11. BEGIN_MESSAGE_MAP(CDragCaption, CStatic)
  12. ON_WM_NCHITTEST()
  13. ON_WM_LBUTTONDOWN()
  14. ON_WM_CTLCOLOR_REFLECT()
  15. END_MESSAGE_MAP()
  16. ///////////////////
  17. //
  18. CDragCaption::CDragCaption(LPCTSTR lpText, BOOL bDeleteOnDestroy)
  19. {
  20. m_color = g_colorUnvisited; // not visited yet
  21. m_bDeleteOnDestroy = bDeleteOnDestroy; // delete object with window?
  22. }
  23. UINT CDragCaption::OnNcHitTest(CPoint point)
  24. {
  25. return HTCLIENT;
  26. }
  27. HBRUSH CDragCaption::CtlColor(CDC* pDC, UINT nCtlColor)
  28. {
  29. ASSERT(nCtlColor == CTLCOLOR_STATIC);
  30. DWORD dwStyle = GetStyle();
  31. HBRUSH hbr = NULL;
  32. if ((dwStyle & 0xFF) <= SS_RIGHT) {
  33. // this is a text control: set up font and colors
  34. if (!(HFONT)m_font) {
  35. // first time init: create font
  36. LOGFONT lf;
  37. GetFont()->GetObject(sizeof(lf), &lf);
  38. lf.lfUnderline = TRUE;
  39. m_font.CreateFontIndirect(&lf);
  40. }
  41. // use underline font and visited/unvisited colors
  42. pDC->SelectObject(&m_font);
  43. pDC->SetTextColor(m_color);
  44. pDC->SetBkMode(TRANSPARENT);
  45. // return hollow brush to preserve parent background color
  46. hbr = (HBRUSH)::GetStockObject(HOLLOW_BRUSH);
  47. }
  48. return hbr;
  49. }
  50. /////////////////
  51. // Handle mouse click: StartTracking
  52. void CDragCaption::OnLButtonDown(UINT nFlags, CPoint point)
  53. {
  54. StartTracking();
  55. CWnd::OnLButtonDown(nFlags, point);
  56. }
  57. void CDragCaption::PostNcDestroy()
  58. {
  59. if (m_bDeleteOnDestroy)
  60. delete this;
  61. }