- 自制按钮
- 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);
}
- 自绘static
- #if !defined(AFX_DIRECTNCSTATIC_H__61EAD734_379A_4CA6_AB60_A7B1DA0A2610__INCLUDED_)
- #define AFX_DIRECTNCSTATIC_H__61EAD734_379A_4CA6_AB60_A7B1DA0A2610__INCLUDED_
- #if _MSC_VER > 1000
- #pragma once
- #endif // _MSC_VER > 1000
- // DirectNCStatic.h : header file
- //
- #include "ViewFunction.h"
- #include "DirectNCHIDlg.h"
- /
- // CDirectNCStatic window
- class CDirectNCStatic : public CStatic
- {
- // Construction
- public:
- CDirectNCStatic();
- //zhu.x.b add 2007-4-27
- HVDOC m_hvDoc;
- //end add
- // Attributes
- public:
- protected:
- COLORREF m_ForeColor;
- COLORREF m_BackColor;
- CBrush m_BkBrush;
- // Operations
- public:
- void SetForeColor(COLORREF color);
- void SetBkColor(COLORREF color);
- // Overrides
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CDirectNCStatic)
- //}}AFX_VIRTUAL
- // Implementation
- public:
- virtual ~CDirectNCStatic();
- // Generated message map functions
- protected:
- //{{AFX_MSG(CDirectNCStatic)
- afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);
- afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
- afx_msg BOOL OnEraseBkgnd(CDC* pDC);
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
- };
- /
- //{{AFX_INSERT_LOCATION}}
- // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
- #endif // !defined(AFX_DIRECTNCSTATIC_H__61EAD734_379A_4CA6_AB60_A7B1DA0A2610__INCLUDED_)
- 、、、、、、、、、、、、、、、、、、、、、、
- // DirectNCStatic.cpp : implementation file
- //
- /*
- File Name : DirectNCStatic.cpp
- Description : All Static controls used in DirectNC's parameter setting dialog
- It's a control inheritted from CStatic
- Programmer : chen.y
- Make Date : 2005.02.03
- Change : zhu.x.b 2007-5-8 modified @V090-UI-01:can't show preview when open file
- */
- #include "stdafx.h"
- #include "DirectNCHI.h"
- #include "DirectNCStatic.h"
- #include "CDirTreeDlgDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /
- // CDirectNCStatic
- CDirectNCStatic::CDirectNCStatic()
- {
- m_ForeColor = GetSysColor( COLOR_BTNTEXT ); //ÎÄ×ÖÑÕÉ«
- m_BackColor = GetSysColor( COLOR_BTNFACE ); //±³¾°É«
- m_BkBrush.CreateSolidBrush(m_BackColor); //±³¾°Ë¢
- m_hvDoc = 0;
- }
- CDirectNCStatic::~CDirectNCStatic()
- {
- }
- BEGIN_MESSAGE_MAP(CDirectNCStatic, CStatic)
- //{{AFX_MSG_MAP(CDirectNCStatic)
- ON_WM_CTLCOLOR_REFLECT()
- ON_WM_LBUTTONDOWN()
- ON_WM_ERASEBKGND()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /
- // CDirectNCStatic message handlers
- HBRUSH CDirectNCStatic::CtlColor(CDC* pDC, UINT nCtlColor)
- {
- // TODO: Change any attributes of the DC here
- pDC->SetTextColor( m_ForeColor );
- pDC->SetBkColor( m_BackColor );
- return (HBRUSH)m_BkBrush.GetSafeHandle();
- // TODO: Return a non-NULL brush if the parent's handler should not be called
- // return NULL;
- }
- /*
- Description : set text color
- Parameters : color /[in]/ text color
- Return Value:
- */
- void CDirectNCStatic::SetForeColor(COLORREF color)
- {
- m_ForeColor = color;
- }
- /*
- Description : set background color
- Parameters : color /[in]/ background color
- Return Value:
- */
- void CDirectNCStatic::SetBkColor(COLORREF color)
- {
- m_BackColor = color;
- m_BkBrush.Detach();
- m_BkBrush.CreateSolidBrush( m_BackColor );
- }
- void CDirectNCStatic::OnLButtonDown(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- CStatic::OnLButtonDown(nFlags, point);
- PostMessage (WM_NCLBUTTONDOWN , HTCAPTION , MAKELPARAM(point.x, point. y));
- }
- BOOL CDirectNCStatic::OnEraseBkgnd(CDC* pDC)
- {
- // TODO: Add your message handler code here and/or call default
- // HWND hWnd;
- //zhu.x.b add 2007-4-28
- //if atom doc is not null,render it
- if(m_hvDoc)
- {
- ViewPreviewRender(m_hvDoc, TRUE);
- return TRUE;
- }
- else
- {
- return CStatic::OnEraseBkgnd(pDC);
- }
- //end add
- }