VC6.0添加皮肤并修改按钮图片

使用VC6.0开发的基于对话框的程序,添加black.she皮肤,并将在按钮上贴图,需要的文件如下:

black.she   SkinH.dll    SkinH.h   SkinH.lib

上述文件下载地址:http://download.csdn.net/detail/jinshelangjun_/4906411

具体操作如下,将SkinH.h和SkinH.lib拷贝到工程目录下,将black.she和SkinH.dll拷贝到Debug和Release目录下,将SkinH.h添加到工程中。

在CXXApp.cpp中添加下面的代码:

#include "SkinH.h"
#pragma comment(lib, "SkinH.lib")

在BOOL CXXApp::InitInstance()中添加皮肤代码:

BOOL CDellApp::InitInstance()
{
AfxEnableControlContainer();

 

/******添加皮肤的代码*************/

char Path[200]={0};
GetModuleFileName(NULL,Path,200);
*strrchr(Path,'\\')=0;
CString str="\\black.she";
strcat(Path,str);
SkinH_AttachEx(Path,NULL);

// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.

#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif

CXXDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();

// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}

代码添加完成,编译工程,界面如下:

接下来用图片对按钮进行修改:选中要修改的按钮,右键属性中选择Owner draw,如下图所示:

在CXXDlg中定义一个private属性:

private:
CBitmapButton m_button1;

然后,将按钮单击之前的图片和按钮单击之后的图片添加到程序中,

在BOOL CXXDlg::OnInitDialog()中添加如下代码:

m_button1.LoadBitmaps(IDB_BITMAP1, IDB_BITMAP2); //IDB_BITMAP1:点击按钮之前显示的图片;IDB_BITMAP2:点击按钮之后显示的图片
m_button1.SubclassDlgItem(IDC_SCREENSAVE, this);
m_button1.SizeToContent();

编译程序,按钮设置成功。

posted on 2012-12-19 16:37  金蛇郎君的世界  阅读(544)  评论(0编辑  收藏  举报

导航