2 Star 3 Fork 2

int2e / ImageButton

Create your Gitee Account
Explore and code with more than 6 million developers,Free private repositories !:)
Sign up
Clone or download
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.md

CImageButton

MFC/WTL CImageButton 支持[BMP,GIF,JPEG,PNG,TIFF], 支持高DPI

CImageButton是一个支持4种状态图形显示的按钮控件

  • 正常状态
  • 鼠标放上去的悬停状态
  • 鼠标按下去的状态
  • 按钮被禁用的状态

以上4种状态可分别设置为不同的图片, 支持PNG图片透明通道

使用方法

MFC

  • 添加ImageButton.hImageButton.cpp到项目中
  • CxxxDlg类包含头文件 ImageButton.h
  • 用类向导定义CImageButton类型的变量到资源ID
  • OnInitDialog()虚函数中调用btn.SetImages()方法

CxxxDlg.h

#pragma once

#include "ImageButton.h"


// CMFCDemoDlg 对话框
class CMFCDemoDlg : public CDialogEx
{
    // ...

private:
	CImageButton m_btnTest;
};

CxxxDlg.cpp


BOOL CMFCDemoDlg::OnInitDialog()
{
	
    // ....

	// 设置按钮图片
	m_btnTest.SetImages(IDB_PNG1, IDB_PNG2, IDB_PNG3, IDB_PNG4, _T("PNG"));
	// 开启自动大小, 跟随图片宽高
	m_btnTest.AutoSize();

    // ....
}

WTL

  • 添加ImageButton.h项目中
  • CMainDlg类包含头文件 ImageButton.h
  • CMainDlgBEGIN_MSG_MAP(CMainDlg)END_MSG_MAP()之间加REFLECT_NOTIFICATIONS()用来反射WM_DRAWITEM消息, 随后自行加入COMMAND_HANDLER()绑定按钮事件
  • 添加CImageButton类型的成员变量
  • OnInitDialog()函数中调用btn.SubclassWindow()方法与btn.SetImages()方法

CMainDlg.h

#pragma once

#include "ImageButton.h"


class CMainDlg : public CDialogImpl<CMainDlg>, public CUpdateUI<CMainDlg>, public CMessageFilter, public CIdleHandler
{
    // ...
    	BEGIN_MSG_MAP(CMainDlg)
		COMMAND_HANDLER(IDC_BUTTON_TEST, BN_CLICKED, OnBnClickedButtonTest) // 按钮事件
		REFLECT_NOTIFICATIONS() // 反射 WM_MEASUREITEM 和 WM_DRAWITEM 消息
	END_MSG_MAP()

    // ...
private:
	CImageButton m_btnTest;
};

CMainDlg.cpp


LRESULT CMainDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
	// ...

    // 子类化控件
	m_btnTest.SubclassWindow(GetDlgItem(IDC_BUTTON_TEST)); 
	// 设置按钮图片
	m_btnTest.SetImages(IDB_PNG1, IDB_PNG2, IDB_PNG3, IDB_PNG4, _T("PNG"));
	// 开启自动大小, 跟随图片宽高
	m_btnTest.AutoSize();

	// ...
	
	return TRUE;
}

// 按钮事件
LRESULT CMainDlg::OnBnClickedButtonTest(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	MessageBox(_T("Test"), _T(""), MB_OK | MB_ICONINFORMATION);

	return 0;
}

说明

IDB_PNG1, IDB_PNG2, IDB_PNG3, IDB_PNG4 均为资源ID, 如何导入资源请去百度上谷歌一下

Comments ( 0 )

Sign in for post a comment

About

MFC/WTL CImageButton 支持[BMP,GIF,JPEG,PNG,TIFF], 支持高DPI spread retract
C++
Apache-2.0
Cancel

Releases

No release

Gitee Metrics

Contributors

All

Activities

load more
can not load any more
C++
1
https://gitee.com/int2e/ImageButton.git
git@gitee.com:int2e/ImageButton.git
int2e
ImageButton
ImageButton
master

Search