添加类CImgButton,继承自CBitmapButton。选择CImgButton类的property,通过重载DrawItem(不是Message下的WM_DRAWITEM,其响应函数OnDrawItem不会被调用。),实现在bitmap上写入文字的功能。
.h文件代码
#pragma once
#include <afxext.h>
class CImgButton :
public CBitmapButton
{
//DECLARE_DYNAMIC(CImgButton)
public:
CImgButton();
virtual ~CImgButton();
protected:
//DECLARE_MESSAGE_MAP()
public:
public:
COLORREF TextColor;
void SetTextColor(COLORREF crColor);
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
};
.cpp文件代码
#include "stdafx.h"
#include "ImgButton.h"
CImgButton::CImgButton()
{
}
CImgButton::~

通过创建CImgButton类并继承自CBitmapButton,重载DrawItem方法来在按钮的位图上添加文字。详细步骤包括.h和.cpp文件的代码实现,以及在对话框中设置按钮为ownerdraw,加载位图资源,以及对话框的初始化操作。

1万+

被折叠的 条评论
为什么被折叠?



