2.0版
把corona.smf,SkinMagicLibMD6.lib,SkinMagicLib.h考入程序文件夹中.
在stdafx.h中添加代码
#include "SkinMagicLib.h"
//#pragma comment(lib, "SkinMagicLibMD6Trial.lib")
#pragma comment(lib, "SkinMagicLibMD6.lib")
/* 当在Project/Setting/General中选择"Use MFC in a Static Library"时,
需要以下两条语句:
*/
#pragma comment(linker, "/FORCE:MULTIPLE")
#pragma comment(linker, "/OPT:NOREF")
在主文件添加头文件
#define COMPILE_MULTIMON_STUBS
#include "multimon.h"
在BOOL CMDIDemoApp::InitInstance()开头添加
VERIFY( 1 == InitSkinMagicLib( AfxGetInstanceHandle(), _T("Demo") ,
NULL,
NULL ) );
VERIFY( 1 == LoadSkinFile( _T("corona.smf") ) );
在尾部 pMainFrame->ShowWindow(m_nCmdShow);
pMainFrame->UpdateWindow();
之前添加
VERIFY( 1 == SetWindowSkin( m_pMainWnd->m_hWnd , _T("MainFrame") ));
SetControlTooltip( pMainFrame->m_wndToolBar.m_hWnd , _T("ToolBar") );
VERIFY( 1 == SetDialogSkin( _T("Dialog") ) );
之后就编译成功了,继续为子窗口重载WM_CREATE或WM_INITDIALOG
在其中添加代码SetWindowSkin( m_hWnd , _T("MainFrame") );
2.2版
1、下载SkinMagic Toolkit,复制SkinMagicTrial.dll、SkinMagicTrial.lib、SkinMagicLib.h以及皮肤文件corona.smf至项目的目录下。(这样比较简单J,可以在这下载。)
2、在stdafx.h中加入头文件和库的引用,如下:
#i nclude "SkinMagicLib.h"
#pragma comment(lib, "SkinMagicTrial.lib")
l 使用SkinMagic
1、 初始化SkinMagic库:
int __stdcall InitSkinMagicLib( HINSTANCE hInstance,
LPCTSTR lpApplication ,
LPCTSTR lpReserved1,
LPCTSTR lpReserved2 );
在 CxxxApp::InitInstance()中加入初始化SkinMagic库的代码:
VERIFY( 1 == InitSkinMagicLib(AfxGetInstanceHandle(), NULL, NULL, NULL));
2、调入皮肤文件:
皮肤的调用有两种方法,一是直接从皮肤文件中调用,另一种方法是从资源文件中调用,分别说明如下:
1) 从皮肤文件中调用皮肤:
int __stdcall LoadSkinFile( LPCTSTR lpSkinFile );
2)从资源文件中调用皮肤:
int __stdcall LoadSkinFromResource(HMODULE hModule,
LPCTSTR lpSkinName ,
LPCTSTR lpType);
现在CxxxApp::InitInstance()中的代码如下:
BOOL CxxxApp::InitInstance()
{
VERIFY( 1 == InitSkinMagicLib(AfxGetInstanceHandle(), NULL, NULL, NULL));
VERIFY( 1 == LoadSkinFile("corona.smf"));
AfxEnableControlContainer();
//…..下略
}
3、将皮肤应用到程序上
int __stdcall SetWindowSkin( HWND hWnd , LPCTSTR lpSkinName );
int __stdcall SetDialogSkin( LPCTSTR szSkinName );
1)对话框程序代码位置:
BOOL CxxxApp::InitInstance()
{
//...上略
m_pMainWnd = &dlg;
VERIFY( 1 == SetWindowSkin( m_pMainWnd->m_hWnd , "MainFrame" ));
VERIFY( 1 == SetDialogSkin( "Dialog" ) );
int nResponse = dlg.DoModal();
//…下略
}
2)文档视图程序代码的位置
BOOL CxxxApp::InitInstance()
{
//…上略
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
VERIFY( 1 == SetWindowSkin( m_pMainWnd->m_hWnd , "MainFrame" ));
VERIFY( 1 == SetDialogSkin( "Dialog" ) );
return TRUE;
}
4、释放SkinMagic资源
void __stdcall ExitSkinMagicLib();
重载应用程序的ExitInstance()函数,添加如下代码:
int CxxxApp::ExitInstance()
{
ExitSkinMagicLib();
return CWinApp::ExitInstance();
}