資源簡介
自繪按鈕,加載bmp圖片,可以實現創建不規則的按鈕(效果是)
代碼片段和文件信息
/*******************************************************************************
*?File?Name?:????BmpButton.cpp
*?Created???:????2008-5-13
*?Author????:????huzb
*?Model?????:????
*?Description????可加載4張bmp圖片,并根據圖片創建不規則按鈕的按鈕類
*?----------------------------------------------------------------------------?*
*?Revision?History
*?No????Date????????Revised?by??????Description
*?--????----????????----------??????-----------
*******************************************************************************/
#include?“stdafx.h“
#include?“BmpButton.h“
#ifdef?_DEBUG
#define?new?DEBUG_NEW
#undef?THIS_FILE
static?char?THIS_FILE[]?=?__FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
//?CBmpButton
CBmpButton::CBmpButton()
{
m_iMouseType?=?0;
m_szText?=?CSize(?0?0?);
}
CBmpButton::~CBmpButton()
{
m_bmpNormal.Deleteobject();
m_bmpHot.Deleteobject();
m_bmpFocus.Deleteobject();
m_bmpDisable.Deleteobject();
m_TextFont.Deleteobject();
}
BEGIN_MESSAGE_MAP(CBmpButton?CButton)
//{{AFX_MSG_MAP(CBmpButton)
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_MESSAGE(?WM_MOUSELEAVE??onmouseleave?)
ON_WM_PAINT()
ON_WM_ERASEBKGND()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
//?CBmpButton?message?handlers
//?設置按鈕圖片(正常狀態下,鼠標移上,鼠標按下,按鈕不可用4種狀態)
void?CBmpButton::SetTheBitmap(?UINT?iNormalID?UINT?iHotID?UINT?iFocusID?UINT?iDisableID?)
{
if(?iNormalID?<=?0?||?iHotID?<=?0?||?iFocusID?<=?0?||?iDisableID?<=?0?)
{
return;
}
if(?m_bmpNormal.m_hobject?)
{
m_bmpNormal.Deleteobject();
}
if(?m_bmpHot.m_hobject?)
{
m_bmpHot.Deleteobject();
}
if(?m_bmpFocus.m_hobject?)
{
m_bmpFocus.Deleteobject();
}
if(?m_bmpDisable.m_hobject?)
{
m_bmpDisable.Deleteobject();
}
m_bmpNormal.LoadBitmap(?iNormalID?);
m_bmpHot.LoadBitmap(?iHotID?);
m_bmpFocus.LoadBitmap(?iFocusID?);
m_bmpDisable.LoadBitmap(?iDisableID?);
}
//?設置字體大小(因按鈕的大小不一,所以提供了該函數,可以根據實際需要,設置字體的大小)
void?CBmpButton::SetFontSize(?int?iSize?)
{
int?iFontSize?=?iSize;
if(?iFontSize?<=?0?)
{
iFontSize?=?16;
}
if(?m_TextFont.m_hobject?)
{
m_TextFont.Deleteobject();
}
m_TextFont.CreateFont(
iFontSize
0
0
0
400
FALSE
FALSE
0
ANSI_CHARSET
OUT_DEFAULT_PRECIS
CLIP_DEFAULT_PRECIS
DEFAULT_QUALITY
DEFAULT_PITCH?|?FF_ROMAN
“黑體“
);
}
//?鼠標移動到按鈕上
void?CBmpButton::onmousemove(UINT?nFlags?CPoint?point)?
{
CButton::onmousemove(nFlags?point);
if(?1?!=?m_iMouseType?)
{
m_iMouseType?=?1;
Invalidate(?FALSE?);
}
//?發送鼠標離開按鈕的消息
TRACKMOUSEEVENT?event?;
event.cbSize?=?sizeof(?event?);
event.dwFlags?=?TME_LEAVE?;
event.dwHoverTime?=?0?;
event.hwndTrack?=?GetSafeHwnd()?;
VERIFY(?_TrackMouseEvent(?&event?)?)?;
}
//?鼠標按下
void?CBmpButton::OnLButtonDown(UINT?nFlags?CPoint?point)?
{
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????32256??2008-05-13?19:16??CBmpButton使用.doc
?????文件?????212152??2008-05-13?19:09??ButtonTest\ButtonTest.aps
?????文件???????5885??2008-05-13?19:09??ButtonTest\ButtonTest.rc
?????文件????????913??2008-05-13?18:25??ButtonTest\Resource.h
?????文件???????2389??2008-05-13?18:37??ButtonTest\BmpButton.h
?????文件???????7935??2008-05-13?18:37??ButtonTest\BmpButton.cpp
?????文件???????1562??2008-05-13?16:07??ButtonTest\ButtonTestDlg.h
?????文件???????1336??2008-05-13?19:19??ButtonTest\ButtonTest.clw
?????文件???????3651??2008-05-13?10:00??ButtonTest\ReadMe.txt
?????文件???????1368??2008-05-13?10:00??ButtonTest\ButtonTest.h
?????文件???????2119??2008-05-13?10:00??ButtonTest\ButtonTest.cpp
?????文件??????58368??2008-05-13?19:19??ButtonTest\ButtonTest.ncb
?????文件??????54784??2008-05-13?19:19??ButtonTest\ButtonTest.opt
?????文件???????1054??2008-05-13?10:00??ButtonTest\StdAfx.h
?????文件????????212??2008-05-13?10:00??ButtonTest\StdAfx.cpp
?????文件????????402??2008-05-13?10:00??ButtonTest\res\ButtonTest.rc2
?????文件???????1078??2008-05-13?10:00??ButtonTest\res\ButtonTest.ico
?????文件?????160374??2008-05-13?12:03??ButtonTest\res\DlgBg.bmp
?????文件???????3896??2008-05-13?11:20??ButtonTest\res\01.bmp
?????文件???????3896??2008-05-13?11:20??ButtonTest\res\02.bmp
?????文件???????3896??2008-05-13?11:20??ButtonTest\res\03.bmp
?????文件???????3896??2008-05-13?11:20??ButtonTest\res\04.bmp
?????文件???????5178??2008-05-13?14:37??ButtonTest\ButtonTest.dsp
?????文件???????4870??2008-05-13?19:07??ButtonTest\ButtonTestDlg.cpp
?????文件????????389??2008-05-13?19:19??ButtonTest\ButtonTest.positions
?????文件????????543??2008-05-13?10:00??ButtonTest\ButtonTest.dsw
?????文件????????254??2008-05-13?19:09??ButtonTest\ButtonTest.plg
?????目錄??????????0??2008-05-13?10:00??ButtonTest\res
?????目錄??????????0??2008-05-13?10:00??ButtonTest
-----------?---------??----------?-----??----
............此處省略2個文件信息
- 上一篇:linux掃雷游戲代碼
- 下一篇:AJAX下載
評論
共有 條評論