📄 gamebutton.cpp
字号:
// GameButton.cpp : implementation file
//
#include "stdafx.h"
#include "Game.h"
#include "GameButton.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CGameButton
CGameButton::CGameButton()
{
m_Model=1;
m_OnMouseUp=0; //没在上面
m_Lbdown=FALSE;
}
CGameButton::~CGameButton()
{
}
BEGIN_MESSAGE_MAP(CGameButton, CButton)
//{{AFX_MSG_MAP(CGameButton)
ON_WM_MOUSEMOVE()
ON_WM_ERASEBKGND()
ON_WM_LBUTTONDOWN()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CGameButton message handlers
void CGameButton::PreSubclassWindow()
{
// TODO: Add your specialized code here and/or call the base class
ModifyStyle(0,BS_OWNERDRAW,0);
CButton::PreSubclassWindow();
}
void CGameButton::OnMouseMove(UINT nFlags, CPoint point)
{
if ( GetCapture() != this )
{
m_OnMouseUp=1;
SetCapture();
}
else
{
m_OnMouseUp=0;
ReleaseCapture();
}
Invalidate();
CButton::OnMouseMove(nFlags, point);
}
BOOL CGameButton::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
return TRUE;
}
void CGameButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CRect rect=lpDrawItemStruct->rcItem;
CDC dc;
dc.Attach(lpDrawItemStruct->hDC);
CDC ds;
ds.CreateCompatibleDC(&dc);
CBitmap bits;
if ( m_Model == 1 ) //单人游戏按钮
{
if ( m_OnMouseUp == 0 ) //鼠标不在按钮上面
{
bits.LoadBitmap(IDB_DRYX);
}
else //鼠标在按钮上面
{
bits.LoadBitmap(IDB_DRYX2);
}
}
if ( m_Model == 2 ) //双人对战按钮
{
if ( m_OnMouseUp == 0 )
{
bits.LoadBitmap(IDB_SRDZ);
}
else
{
bits.LoadBitmap(IDB_SRDZ2);
}
}
if ( m_Model == 3 ) //游戏介绍按钮
{
if ( m_OnMouseUp == 0 )
{
bits.LoadBitmap(IDB_YXJS);
}
else
{
bits.LoadBitmap(IDB_YXJS2);
}
}
if ( m_Model == 4 ) //退出游戏按钮
{
if ( m_OnMouseUp == 0 )
{
bits.LoadBitmap(IDB_TCYX);
}
else
{
bits.LoadBitmap(IDB_TCYX2);
}
}
if ( m_Model == 5 ) //创建游戏按钮
{
if ( m_OnMouseUp == 0 )
{
bits.LoadBitmap(IDB_CJYX);
}
else
{
bits.LoadBitmap(IDB_CJYX2);
}
}
if ( m_Model == 6 ) //加入游戏按钮
{
if ( m_OnMouseUp == 0 )
{
bits.LoadBitmap(IDB_JRYX);
}
else
{
bits.LoadBitmap(IDB_JRYX2);
}
}
ds.SelectObject(&bits);
dc.BitBlt(0,0,rect.Width(),rect.Height(),&ds,0,0,SRCCOPY);
dc.Detach();
}
void CGameButton::OnLButtonDown(UINT nFlags, CPoint point)
{
m_Lbdown = TRUE;
CButton::OnLButtonDown(nFlags, point);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -