自制static

来源:互联网 发布:2016中国出境旅游数据 编辑:程序博客网 时间:2024/04/26 17:29
    1. 自制按钮
    2. void CTestButton::PreSubclassWindow()
      {
       CButton::PreSubclassWindow();
       ModifyStyle(0 ,BS_OWNERDRAW);
      }
      void CTestButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
      {
       //UINT uStyle = DFCS_BUTTONPUSH;
       //ASSERT(lpDrawItemStruct->CtlType == ODT_BUTTON);
       CClientDC dc(this);
       CRect rect;
       GetClientRect(&rect);
       CPen pen(PS_SOLID,2,RGB(255,0,0));
       CPen* pOldPen=dc.SelectObject(&pen);
       CPoint point;
       point.x=5;
       point.y=5;
       dc.RoundRect(rect,point);
       CRgn rgn;
       rgn.CreateRoundRectRgn(rect.left,rect.top,rect.right,rect.bottom,5,5);
       CBrush brush;
       CBitmap bitmap;
       bitmap.LoadBitmap(IDB_BITMAP1);
       if(lpDrawItemStruct->itemState & ODS_SELECTED)
       {
         brush.CreateSolidBrush(RGB(0,255,255));
       }
       else
       {
           brush.CreateSolidBrush(RGB(255,255,255));
        //brush.CreatePatternBrush(&bitmap);
       }
       dc.FillRgn(&rgn,&brush);
       dc.SelectObject(pOldPen);
       ReleaseDC(&dc);
      }
  1. 自绘static
  2. #if !defined(AFX_DIRECTNCSTATIC_H__61EAD734_379A_4CA6_AB60_A7B1DA0A2610__INCLUDED_)
  3. #define AFX_DIRECTNCSTATIC_H__61EAD734_379A_4CA6_AB60_A7B1DA0A2610__INCLUDED_
  4. #if _MSC_VER > 1000
  5. #pragma once
  6. #endif // _MSC_VER > 1000
  7. // DirectNCStatic.h : header file
  8. //
  9. #include "ViewFunction.h"
  10. #include "DirectNCHIDlg.h"
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CDirectNCStatic window
  13. class CDirectNCStatic : public CStatic
  14. {
  15. // Construction
  16. public:
  17.     CDirectNCStatic();
  18.     //zhu.x.b add 2007-4-27
  19.     HVDOC m_hvDoc;
  20.     //end add
  21. // Attributes
  22. public:
  23.     
  24. protected:
  25.     COLORREF m_ForeColor;
  26.     COLORREF m_BackColor;
  27.     CBrush m_BkBrush;
  28. // Operations
  29. public:
  30.     void SetForeColor(COLORREF color);
  31.     void SetBkColor(COLORREF color);    
  32. // Overrides
  33.     // ClassWizard generated virtual function overrides
  34.     //{{AFX_VIRTUAL(CDirectNCStatic)
  35.     //}}AFX_VIRTUAL
  36. // Implementation
  37. public:
  38.     virtual ~CDirectNCStatic();
  39.     // Generated message map functions
  40. protected:
  41.     //{{AFX_MSG(CDirectNCStatic)
  42.     afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);
  43.     afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
  44.     afx_msg BOOL OnEraseBkgnd(CDC* pDC);
  45.     //}}AFX_MSG
  46.     DECLARE_MESSAGE_MAP()
  47. };
  48. /////////////////////////////////////////////////////////////////////////////
  49. //{{AFX_INSERT_LOCATION}}
  50. // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  51. #endif // !defined(AFX_DIRECTNCSTATIC_H__61EAD734_379A_4CA6_AB60_A7B1DA0A2610__INCLUDED_)
  52. 、、、、、、、、、、、、、、、、、、、、、、
  53. // DirectNCStatic.cpp : implementation file
  54. //
  55. /*
  56.     File Name   :   DirectNCStatic.cpp  
  57.     Description :   All Static controls used in DirectNC's parameter setting dialog
  58.                     It's a control inheritted from CStatic
  59.     Programmer  :   chen.y
  60.     Make Date   :   2005.02.03
  61.     Change      :   zhu.x.b 2007-5-8 modified @V090-UI-01:can't show preview when open file
  62. */
  63. #include "stdafx.h"
  64. #include "DirectNCHI.h"
  65. #include "DirectNCStatic.h"
  66. #include "CDirTreeDlgDlg.h"
  67. #ifdef _DEBUG
  68. #define new DEBUG_NEW
  69. #undef THIS_FILE
  70. static char THIS_FILE[] = __FILE__;
  71. #endif
  72. /////////////////////////////////////////////////////////////////////////////
  73. // CDirectNCStatic
  74. CDirectNCStatic::CDirectNCStatic()
  75. {
  76.     m_ForeColor = GetSysColor( COLOR_BTNTEXT ); //ÎÄ×ÖÑÕÉ«
  77.     m_BackColor = GetSysColor( COLOR_BTNFACE ); //±³¾°É«
  78.     m_BkBrush.CreateSolidBrush(m_BackColor); //±³¾°Ë¢
  79.     m_hvDoc = 0;
  80. }
  81. CDirectNCStatic::~CDirectNCStatic()
  82. {
  83. }
  84. BEGIN_MESSAGE_MAP(CDirectNCStatic, CStatic)
  85.     //{{AFX_MSG_MAP(CDirectNCStatic)
  86.     ON_WM_CTLCOLOR_REFLECT()
  87.     ON_WM_LBUTTONDOWN()
  88.     ON_WM_ERASEBKGND()
  89.     //}}AFX_MSG_MAP
  90. END_MESSAGE_MAP()
  91. /////////////////////////////////////////////////////////////////////////////
  92. // CDirectNCStatic message handlers
  93. HBRUSH CDirectNCStatic::CtlColor(CDC* pDC, UINT nCtlColor) 
  94. {
  95.     // TODO: Change any attributes of the DC here
  96.     pDC->SetTextColor( m_ForeColor );
  97.     pDC->SetBkColor( m_BackColor );
  98.     return (HBRUSH)m_BkBrush.GetSafeHandle();
  99.     // TODO: Return a non-NULL brush if the parent's handler should not be called
  100. //  return NULL;
  101. }
  102. /*
  103. Description :   set text color
  104. Parameters  :   color /[in]/ text color
  105. Return Value:   
  106. */
  107. void CDirectNCStatic::SetForeColor(COLORREF color)
  108. {
  109.     m_ForeColor = color;
  110. }
  111. /*
  112. Description :   set background color
  113. Parameters  :   color /[in]/ background color
  114. Return Value:   
  115. */
  116. void CDirectNCStatic::SetBkColor(COLORREF color)
  117. {
  118.     m_BackColor = color;
  119.     m_BkBrush.Detach();
  120.     m_BkBrush.CreateSolidBrush( m_BackColor );
  121. }
  122. void CDirectNCStatic::OnLButtonDown(UINT nFlags, CPoint point) 
  123. {
  124.     // TODO: Add your message handler code here and/or call default
  125.     
  126.     CStatic::OnLButtonDown(nFlags, point);
  127.     PostMessage (WM_NCLBUTTONDOWN , HTCAPTION , MAKELPARAM(point.x, point. y)); 
  128. }
  129. BOOL CDirectNCStatic::OnEraseBkgnd(CDC* pDC) 
  130. {
  131.     // TODO: Add your message handler code here and/or call default
  132. //  HWND hWnd;
  133.     //zhu.x.b add 2007-4-28
  134.     //if atom doc is not null,render it
  135.     if(m_hvDoc)
  136.     {
  137.         ViewPreviewRender(m_hvDoc, TRUE);
  138.         return TRUE;
  139.     }
  140.     else
  141.     {
  142.         return CStatic::OnEraseBkgnd(pDC);
  143.     }
  144.     //end add
  145. }

 

 
原创粉丝点击