效果:
步骤:
1. 添加图片资源,一张黑白,一张彩色 如下(放置项目文件夹中res文件夹中):
2. 添加资源到项目中:
源码区:
Irregular_InterfaceDlg.h// Irregular_InterfaceDlg.h: 头文件
//
#pragma once
// CIrregularInterfaceDlg 对话框
class CIrregularInterfaceDlg : public CDialog
{
// 构造
public:
CIrregularInterfaceDlg(CWnd* pParent = nullptr);// 标准构造函数
HRGN BitmapToRegion(HBITMAP hBmp, COLORREF cTransparentColor, COLORREF cTolerance = NULL);//绘图操作区
// 对话框数据
#ifdef AFX_DESIGN_TIME
enum { IDD = IDD_IRREGULAR_INTERFACE_DIALOG };
#endif
protected:
virtual void DoDataExchange(CDataExchange* pDX);// DDX/DDV 支持
// 实现
protected:
HICON m_hIcon;
// 生成的消息映射函数
virtual BOOL OnInitDialog();//初始化UI
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();//绘制窗体
afx_msg HCURSOR OnQueryDragIcon();
DECLARE_MESSAGE_MAP()
public:
afx_msg LRESULT OnNcHitTest(CPoint point);//拖到窗体响应
};
Irregular_InterfaceDlg.cpp// Irregular_InterfaceDlg.cpp: 实现文件
//
#include "pch.h"
#include "framework.h"
#include "Irregular_Interface.h"
#include "Irregular_InterfaceDlg.h"
#include "afxdialogex.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// 用于应用程序“关于”菜单项的 CAboutDlg 对话框
class CAboutDlg : public CDialogEx
{
public:
CAboutDlg();
// 对话框数据
#ifdef AFX_DESIGN_TIME
enum { IDD = IDD_ABOUTBOX };
#endif
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
// 实现
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialogEx(IDD_ABOUTBOX)
{
}
void C