在好例子网,分享、交流、成长!
您当前所在位置:首页C/C++ 开发实例桌面应用界面/GUI → MFC GDIPlus封装的CGdipButton界面,支持很多绚丽效果

MFC GDIPlus封装的CGdipButton界面,支持很多绚丽效果

桌面应用界面/GUI

下载此实例
  • 开发语言:C/C++
  • 实例大小:7.44M
  • 下载次数:9
  • 浏览次数:100
  • 发布时间:2018-04-16
  • 实例类别:桌面应用界面/GUI
  • 发 布 人:kilyc_123456
  • 所需积分:2
 相关标签: VC++ GDIPlus CGdipButton MFC c++ 界面UI

实例介绍

【实例简介】

MFC GDIPlus封装的CGdipButton界面,支持很多绚丽效果,程序完成可运行,希望大家下载

【实例截图】

from clipboard

【核心代码】

HBRUSH CGdipButton::CtlColor(CDC* pScreenDC, UINT nCtlColor) 
{
if(!m_bHaveBitmaps)
{
if(!m_pStdImage)
{
return NULL; // Load the standard image with LoadStdImage()
}

CBitmap bmp, *pOldBitmap;

CRect rect;
GetClientRect(rect);

// do everything with mem dc
CMemDC pDC(pScreenDC, rect);

Gdiplus::Graphics graphics(pDC->m_hDC);

// background
if (m_dcBk.m_hDC == NULL)
{

CRect rect1;
CClientDC clDC(GetParent());
GetWindowRect(rect1);
GetParent()->ScreenToClient(rect1);

m_dcBk.CreateCompatibleDC(&clDC);
bmp.CreateCompatibleBitmap(&clDC, rect.Width(), rect.Height());
pOldBitmap = m_dcBk.SelectObject(&bmp);
m_dcBk.BitBlt(0, 0, rect.Width(), rect.Height(), &clDC, rect1.left, rect1.top, SRCCOPY);
bmp.DeleteObject();
}

// standard image
if (m_dcStd.m_hDC == NULL)
{
PaintBk(pDC);

graphics.DrawImage(*m_pStdImage, 0, 0);

m_dcStd.CreateCompatibleDC(pDC);
bmp.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());
pOldBitmap = m_dcStd.SelectObject(&bmp);
m_dcStd.BitBlt(0, 0, rect.Width(), rect.Height(), pDC, 0, 0, SRCCOPY);
bmp.DeleteObject();

// standard image pressed
if (m_dcStdP.m_hDC == NULL)
{
PaintBk(pDC);

graphics.DrawImage(*m_pStdImage, 1, 1); // 点击图像偏移的像素

m_dcStdP.CreateCompatibleDC(pDC);
bmp.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());
pOldBitmap = m_dcStdP.SelectObject(&bmp);
m_dcStdP.BitBlt(0, 0, rect.Width(), rect.Height(), pDC, 0, 0, SRCCOPY);
bmp.DeleteObject();
}

// standard image hot
if(m_dcStdH.m_hDC == NULL)
{
PaintBk(pDC);

ColorMatrix HotMat = { 1.05f, 0.00f, 0.00f, 0.00f, 0.00f,
0.00f, 1.05f, 0.00f, 0.00f, 0.00f,
0.00f, 0.00f, 1.05f, 0.00f, 0.00f,
0.00f, 0.00f, 0.00f, 1.00f, 0.00f,
0.05f, 0.05f, 0.05f, 0.00f, 1.00f
};

ImageAttributes ia;
ia.SetColorMatrix(&HotMat);

float width = (float)m_pStdImage->m_pBitmap->GetWidth();
float height = (float)m_pStdImage->m_pBitmap->GetHeight();

RectF grect; grect.X=0, grect.Y=0; grect.Width = width; grect.Height = height;

graphics.DrawImage(*m_pStdImage, grect, 0, 0, width, height, UnitPixel, &ia);

m_dcStdH.CreateCompatibleDC(pDC);
bmp.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());
pOldBitmap = m_dcStdH.SelectObject(&bmp);

m_dcStdH.BitBlt(0, 0, rect.Width(), rect.Height(), pDC, 0, 0, SRCCOPY);
bmp.DeleteObject();
}

// grayscale image
if(m_dcGS.m_hDC == NULL)
{
PaintBk(pDC);

ColorMatrix GrayMat = { 0.30f, 0.30f, 0.30f, 0.00f, 0.00f,
0.59f, 0.59f, 0.59f, 0.00f, 0.00f,
0.11f, 0.11f, 0.11f, 0.00f, 0.00f,
0.00f, 0.00f, 0.00f, 1.00f, 0.00f,
0.00f, 0.00f, 0.00f, 0.00f, 1.00f };

ImageAttributes ia;
ia.SetColorMatrix(&GrayMat);

float width = (float)m_pStdImage->m_pBitmap->GetWidth();
float height = (float)m_pStdImage->m_pBitmap->GetHeight();

RectF grect; grect.X=0, grect.Y=0; grect.Width = width; grect.Height = height;

graphics.DrawImage(*m_pStdImage, grect, 0, 0, width, height, UnitPixel, &ia);

m_dcGS.CreateCompatibleDC(pDC);
bmp.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());
pOldBitmap = m_dcGS.SelectObject(&bmp);
m_dcGS.BitBlt(0, 0, rect.Width(), rect.Height(), pDC, 0, 0, SRCCOPY);
bmp.DeleteObject();
}
}

// alternate image
if( (m_dcAlt.m_hDC == NULL) && m_bHaveAltImage )
{
PaintBk(pDC);

graphics.DrawImage(*m_pAltImage, 0, 0);

m_dcAlt.CreateCompatibleDC(pDC);
bmp.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());
pOldBitmap = m_dcAlt.SelectObject(&bmp);
m_dcAlt.BitBlt(0, 0, rect.Width(), rect.Height(), pDC, 0, 0, SRCCOPY);
bmp.DeleteObject();

// alternate image pressed
if( (m_dcAltP.m_hDC == NULL) && m_bHaveAltImage )
{
PaintBk(pDC);

graphics.DrawImage(*m_pAltImage, 1, 1);

m_dcAltP.CreateCompatibleDC(pDC);
bmp.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());
pOldBitmap = m_dcAltP.SelectObject(&bmp);
m_dcAltP.BitBlt(0, 0, rect.Width(), rect.Height(), pDC, 0, 0, SRCCOPY);
bmp.DeleteObject();
}

// alternate image hot
if(m_dcAltH.m_hDC == NULL)
{
PaintBk(pDC);

ColorMatrix HotMat = { 1.05f, 0.00f, 0.00f, 0.00f, 0.00f,
0.00f, 1.05f, 0.00f, 0.00f, 0.00f,
0.00f, 0.00f, 1.05f, 0.00f, 0.00f,
0.00f, 0.00f, 0.00f, 1.00f, 0.00f,
0.05f, 0.05f, 0.05f, 0.00f, 1.00f };

ImageAttributes ia;
ia.SetColorMatrix(&HotMat);

float width = (float)m_pStdImage->m_pBitmap->GetWidth();
float height = (float)m_pStdImage->m_pBitmap->GetHeight();

RectF grect; grect.X=0, grect.Y=0; grect.Width = width; grect.Height = height;

graphics.DrawImage(*m_pAltImage, grect, 0, 0, width, height, UnitPixel, &ia);

m_dcAltH.CreateCompatibleDC(pDC);
bmp.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());
pOldBitmap = m_dcAltH.SelectObject(&bmp);

m_dcAltH.BitBlt(0, 0, rect.Width(), rect.Height(), pDC, 0, 0, SRCCOPY);
bmp.DeleteObject();
}
}

if(m_pCurBtn == NULL)
{
m_pCurBtn = &m_dcStd;
}

m_bHaveBitmaps = TRUE;
}

return NULL;
}

实例下载地址

MFC GDIPlus封装的CGdipButton界面,支持很多绚丽效果

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
;
报警
var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");document.write(unescape("%3Cspan id='cnzz_stat_icon_4847253'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s13.cnzz.com/stat.php%3Fid%3D4847253' type='text/javascript'%3E%3C/script%3E"));