• 大小: 19.01MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-07-09
  • 语言: C/C++
  • 标签: 不规则  透明  GDI+  

资源简介

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\GdiPlusbase.h
     文件       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个文件信息

评论

共有 条评论