支持换肤功能的窗口实例
2010-06-04 20:39:37 来源:WEB开发网三、用法
这些代码的用法很直接。我包含了一个MFC基于窗口的工程,关键代码列在下面。顺便提一下,这些代码在单文档的工程里也测试通过了。
//defines the following member in the dialog class
CSkinButtonResource m_btnres; //skin button resource
CSkinWin m_skinWin; //skin win
BOOL m_bFirst; //first time call
CObList m_wndList; //hold button instance
//In OnInitDialog
m_bFirst = TRUE;
SetSkin( "skin\\neostyle\\theme.ini" );
//SetSkin is a function to change skin
BOOL CSkinTestDlg::SetSkin(CString file)
{
m_skinWin.LoadSkin( file ); //load skin bitmap and parameters
m_btnres.LoadSkin( file );
if ( m_bFirst )
{
//if it''s the first time call, InstallSkin
m_skinWin.InstallSkin( this );
//call EnumChildWindows to subclass all buttons
EnumChildWindows( m_hWnd, EnumChildProc, (LPARAM)this );
m_bFirst = FALSE;
}
//redraw window after change skin
SetWindowPos( 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |SWP_FRAMECHANGED );
return TRUE;
}
//enum child window and take chance to subclass them
#define GetWindowStyle(hwnd) ((DWORD)GetWindowLong(hwnd, GWL_STYLE))
BOOL CALLBACK EnumChildProc( HWND hwnd, // handle to child window
LPARAM lParam // application-defined value
)
{
char classname[200];
CSkinTestDlg *dlg = (CSkinTestDlg *)lParam;
DWORD style;
GetClassName( hwnd, classname, 200 );
style = GetWindowStyle( hwnd );
if ( strcmp( classname, "Button" ) == 0 )
{
style = (UINT)GetWindowLong(hwnd, GWL_STYLE) & 0xff;
if ( style == BS_PUSHBUTTON || style == BS_DEFPUSHBUTTON )
dlg->SubClassButton( hwnd );
}
return TRUE;
}
//subclass push buttons
BOOL CSkinTestDlg::SubClassButton( HWND hwnd )
{
CSkinButton * btn = new CSkinButton();
CWnd* pWnd = CWnd::FromHandlePermanent(hwnd);
if ( pWnd == NULL)
{
btn->SubclassWindow( hwnd );
btn->SetResource( &m_btnres );
return TRUE;
}
return FALSE;
}
//free CSkinButton instances
void CSkinTestDlg::OnDestroy()
{
CDialog::OnDestroy();
// TODO: Add your message handler code here
POSITION pos;
pos = m_wndList.GetHeadPosition();
while( pos )
{
CObject *ob = m_wndList.GetAt(pos);
if ( ob->GetRuntimeClass() == RUNTIME_CLASS(CSkinButton) )
{
delete (CSkinButton*)ob;
}
m_wndList.GetNext(pos);
}
}
四、历史
这是最初版本,我只在Windows XP环境中进行了测试。我希望听到您的评论,谢谢,请自由使用这些代码...
- ››功能强更实用 Win7库变为“计算机”
- ››功能最全!网管必备子网划分计算工具!
- ››支持 Symbian 平台的开发者只有四分之一
- ››支持电骡视频点播 迅雷泛播放体验
- ››支持Win 7 Vista 不开迅雷接管高速下载
- ››支持换肤功能的窗口实例
- ››支持iPhone的免费VPN:VPN98
- ››支持PDF阅读!美图看看新版试用
- ››支持Windows CE和Android 2.1双系统的Viliv Prime...
- ››支持Flash Windows Mobile 手机全功能浏览器
- ››支持 Wi-Fi MOTO 第9款 Android 手机ME508曝光
- ››支持磁力链接 迅雷发力化解BT下载难题
更多精彩
赞助商链接