资源简介
VS2010工程编译的,使用GDI+绘图实现了不规则,透明效果按钮的重绘。
代码片段和文件信息
// PngButton.cpp : implementation file
//
#include “stdafx.h“
#include “PngButton.h“
#include “resource.h“
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPngButton
CPngButton::CPngButton()
{
m_bTracked=false;
m_bMenuOn = FALSE;
m_nImgPart = 0;
m_pImage = NULL;
m_nState = CTRL_NOFOCUS;
m_nBtnType = BTN_TYPE_NORMAL;
}
CPngButton::~CPngButton()
{
if(m_pImage == NULL)
{
delete m_pImage;
m_pImage = NULL;
}
}
void CPngButton::Init(UINT nImg int nPartNum UINT nBtnType)
{
m_pImage = ImageFromResource(AfxGetResourceHandle() nImg L“PNG“);
m_nBtnType = nBtnType;
m_nImgPart = nPartNum;
if (m_pImage == NULL)
return;
CRect rcButton;
if (m_nImgPart == BTN_IMG_1)
rcButton = CRect(0 0 m_pImage->GetWidth() m_pImage->GetHeight());
else if(m_nImgPart == BTN_IMG_3)
rcButton = CRect(0 0 m_pImage->GetWidth()/3 m_pImage->GetHeight());
else if (m_nImgPart == BTN_IMG_4)
rcButton = CRect(0 0 m_pImage->GetWidth()/4 m_pImage->GetHeight());
else
return;
SetWindowPos(NULL 0 0 rcButton.Width() rcButton.Height() SWP_NOACTIVATE|SWP_NOMOVE);
}
BEGIN_MESSAGE_MAP(CPngButton CButton)
//{{AFX_MSG_MAP(CPngButton)
ON_WM_ERASEBKGND()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_PAINT()
ON_MESSAGE(WM_MOUSEHOVEROnMouseHOver)
ON_MESSAGE(WM_MOUSELEAVEonmouseleave)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPngButton message handlers
void CPngButton::OnPaint()
{
CButton::OnPaint();
}
void CPngButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
if (!IsWindowEnabled())
m_nState = CTRL_DISABLE;
CDC dc;
dc.Attach(lpDrawItemStruct->hDC);
ShowImage(&dc m_pImage m_nState);
}
bool CPngButton::ShowImage(CDC* pDC Image* pImage UINT nState)
{
bool bSuc = false;
if(pImage!=NULL)
{
CRect rcButton;
if (m_nImgPart == BTN_IMG_1)
rcButton = CRect(0 0 m_pImage->GetWidth() m_pImage->GetHeight());
else if(m_nImgPart == BTN_IMG_3)
{
if (nState == CTRL_NOFOCUS)
rcButton = CRect(0 0 m_pImage->GetWidth()/3 m_pImage->GetHeight());
else if(nState == CTRL_FOCUS)
rcButton = CRect(m_pImage->GetWidth()/3 0 m_pImage->GetWidth()/3 * 2 m_pImage->GetHeight());
else if (nState == CTRL_SELECTED)
rcButton = CRect(m_pImage->GetWidth()/3 * 2 0 m_pImage->GetWidth() m_pImage->GetHeight());
else
return false;
}
else if (m_nImgPart == BTN_IMG_4)
{
if (nState == CTRL_NOFOCUS)
rcButton = CRect(0 0 m_pImage->GetWidth()/4 m_pImage->GetHeight());
else if(nState == CTRL_FOCUS)
rcButton = CRect(m_pImage->GetWidth()/4 0 m_pImage->GetWidth()/4 * 2 m_pImage->GetHeight());
else if (nState == CTRL_SELECTED)
rcButton = CRe
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2014-04-17 10:58 TestingBed\
目录 0 2014-04-17 10:56 TestingBed\Debug\
目录 0 2014-04-17 09:22 TestingBed\ipch\
目录 0 2014-04-17 09:22 TestingBed\ipch\testingbed-86053d70\
目录 0 2014-04-17 10:04 TestingBed\TestingBed\
文件 63852544 2014-04-17 10:58 TestingBed\TestingBed.sdf
文件 897 2014-04-14 15:36 TestingBed\TestingBed.sln
文件 20992 2014-04-17 10:58 TestingBed\TestingBed.suo
目录 0 2014-04-17 10:56 TestingBed\TestingBed\Debug\
文件 1976 2014-04-17 10:56 TestingBed\TestingBed\Debug\TestingBed.Build.CppClean.log
文件 431 2014-04-17 10:56 TestingBed\TestingBed\Debug\TestingBed.log
目录 0 2014-04-15 10:52 TestingBed\TestingBed\Includes\
文件 3434 2000-12-15 16:58 TestingBed\TestingBed\Includes\GdiPlus.h
文件 857 2000-11-12 23:18 TestingBed\TestingBed\Includes\GdiPlusba
文件 22329 2000-11-12 23:18 TestingBed\TestingBed\Includes\GdiPlusBitmap.h
文件 30802 2001-01-17 16:41 TestingBed\TestingBed\Includes\GdiPlusBrush.h
文件 1773 2000-11-12 23:18 TestingBed\TestingBed\Includes\GdiPlusCachedBitmap.h
文件 4328 2000-11-12 23:18 TestingBed\TestingBed\Includes\GdiPlusColor.h
文件 1750 2000-11-12 23:18 TestingBed\TestingBed\Includes\GdiPlusColorMatrix.h
文件 55921 2001-01-12 15:16 TestingBed\TestingBed\Includes\GdiPlusEnums.h
文件 87463 2001-01-12 15:16 TestingBed\TestingBed\Includes\GdiPlusFlat.h
文件 5981 2000-12-15 16:58 TestingBed\TestingBed\Includes\GdiPlusFont.h
文件 3401 2000-12-04 15:00 TestingBed\TestingBed\Includes\GdiPlusFontCollection.h
文件 6071 2000-11-12 23:18 TestingBed\TestingBed\Includes\GdiPlusFontFamily.h
文件 2725 2000-11-12 23:18 TestingBed\TestingBed\Includes\GdiPlusGpStubs.h
文件 93877 2001-01-17 16:41 TestingBed\TestingBed\Includes\GdiPlusGraphics.h
文件 22175 2001-01-17 16:41 TestingBed\TestingBed\Includes\GdiPlusHeaders.h
文件 13780 2001-01-17 16:41 TestingBed\TestingBed\Includes\GdiPlusimageAttributes.h
文件 1593 2000-11-12 23:18 TestingBed\TestingBed\Includes\GdiPlusImageCodec.h
文件 24268 2000-12-04 15:00 TestingBed\TestingBed\Includes\GdiPlusImaging.h
文件 3171 2000-11-12 23:18 TestingBed\TestingBed\Includes\GdiPlusInit.h
............此处省略37个文件信息
相关资源
- 异形窗体的win32 API实现
- VC++ GDI+ gdiplus应用集
- MFC 自适应不规则按钮类
- png格式透明MFC自绘按钮
- VC使用GDI+将BMP图像转换为JPG格式
- 高效 C++ 屏幕找图 屏幕搜索 透明找
- gdi+绘制带滚动效果的进度条
- C++ 高效 屏幕找图 函数源码 终极版
- GDI+SDK
- c++写的OpenGL程序透明金字塔有加上光
- MFC GDI+练手学习
- MFC BUTTON按钮控件,设置按钮透明,按
- VC6使用GDI+
- (源码)百分百仿360安全卫士界面和
- mfc做的一个非常漂亮的登陆界面透明
- C++异形窗口+WEB控件+关闭按钮 完美实
- MFC GDI+缩放图片
- MFC不规则窗体.zip
- 精通GDI+编程
- C++实战源码-文本背景的透明处理
- C++实战源码-半透明显示窗体
- C++实战源码-绘制不规则图形
- MFC透明按钮
- MFC透明窗口
- 很经典的,透明窗体
- GDI+抽奖大转盘(c++)
- gdi+绘制png透明按钮
- MFC GDI+ 用png图片做的异形窗口,渐显
- mfc浮动窗口--类似迅雷半透明的浮动窗
- MFC实现不规则形状窗口
评论
共有 条评论