.h文件
1 #ifndef __UIHEADICON_H__ 2 #define __UIHEADICON_H__ 3 4 5 /* 6 名称:圆形头像控件(派生CButtonUI类) 7 */ 8 9 10 class CHeadUI: public CButtonUI 11 { 12 public: 13 14 CHeadUI(); 15 16 LPCTSTR GetClass() const; 17 LPVOID GetInterface(LPCTSTR pstrName); 18 19 void SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue); 20 21 void PaintBkImage(HDC hDC); 22 23 void SetBkImage(LPCTSTR pStrImage); 24 25 void SetDefaultBkImage(LPCTSTR pStrImage){ m_sDefaultBkImage = pStrImage; } 26 CDuiString GetDefaultBkImage(){ return m_sDefaultBkImage; } 27 void SetAutoPenColor(bool bAuto){ m_bAutoPenColor = bAuto; } 28 bool IsAutoPenColor() { return m_bAutoPenColor; } 29 void SetPenColor(DWORD dwColor){ m_dwPenColor = dwColor; } 30 DWORD GetPenColor(HDC hDC); 31 void SetPenWidth(int nPenWidth){ m_nPenWidth = nPenWidth; } 32 int GetPenWidth(){ return m_nPenWidth; } 33 34 bool IsHeadImageExist(LPCTSTR pStrImage); 35 36 private: 37 38 CDuiString m_sDefaultBkImage; 39 bool m_bAutoPenColor; 40 DWORD m_dwPenColor; 41 int m_nPenWidth; 42 }; 43 44 #endif // __UIHEADICON_H__
.cpp文件
1 #include "StdAfx.h" 2 #include "UIHeadIcon.h" 3 4 CHeadUI::CHeadUI() 5 { 6 m_sDefaultBkImage = _T("Head\100_1.png"); 7 m_bAutoPenColor = false; 8 m_dwPenColor = Color(255, 255, 255, 255).GetValue(); 9 m_nPenWidth = 2; 10 } 11 12 LPCTSTR CHeadUI::GetClass() const 13 { 14 return _T("HeadIconUI"); 15 } 16 17 LPVOID CHeadUI::GetInterface(LPCTSTR pstrName) 18 { 19 if( _tcscmp(pstrName, _T("HeadIcon")) == 0 ) return static_cast<CHeadUI*>(this); 20 return CControlUI::GetInterface(pstrName); 21 } 22 23 void CHeadUI::SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue) 24 { 25 if (_tcscmp(pstrName, _T("defaultbkimage")) == 0) SetDefaultBkImage(pstrValue); 26 else if (_tcscmp(pstrName, _T("bkimage")) == 0) SetBkImage(pstrValue); 27 else if (_tcscmp(pstrName, _T("pencolor")) == 0) { 28 while (*pstrValue > _T('