带爆炸效果的扫雷(源码5)

本文介绍了一种自定义工具栏的设计与实现方法,包括鼠标点击事件处理、按钮状态更新及绘制等功能。通过C++代码实现了工具栏的交互与显示效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

自己画了一个小工具栏,增加了鼠标单击/释放的处理程序。 附: mytool.cpp mytool.h

mytool.h 

#ifndef __MYTOOL_H
#define __MYTOOL_H

enum e_button{
    E_LEVEL,
    E_HELP,
    E_SCORE
}
;

class MYTOOL
{
public:
    MYTOOL();
    
~MYTOOL();
    
void SetPressDown(int x,int y);
    
int GetButtonPress(int x,int y);

    
void Draw();
    
void LoadPic();
    
void SetHINSTANCE(HINSTANCE h);
    
void SetHWND(HWND h);
    
void SetHDC(HDC h);
    
void SetPos(int x,int y);
    
    
private:
    
int iPressDown;
    
int button_num;
    POINT pos;
    HBITMAP hbm_tool;

    HWND hwnd;
    HDC hdc;
    HDC hdcmem;
    HINSTANCE hinstance;
}
;

#endif

mytool.cpp

#include "stdafx.h"
#include 
"resource.h"

#include 
"mytool.h"


MYTOOL::MYTOOL()
{
    pos.x
=0;
    pos.y
=0;
    iPressDown
=-1;

    button_num
=3;
}


MYTOOL::
~MYTOOL()
{
    DeleteObject(hbm_tool);
}


void MYTOOL::Draw()
{
    
//hdc=GetDC(hwnd);

    SelectObject(hdcmem,hbm_tool);
    BitBlt(hdc,pos.x,pos.y,button_num
*32,32,hdcmem,0,0,SRCCOPY);

    
if(iPressDown!=-1)
    
{
        BitBlt(hdc,pos.x
+iPressDown*32,pos.y,32,32,hdcmem,iPressDown*32,32,SRCCOPY);
    }

}


void MYTOOL::LoadPic()
{
    hbm_tool
=LoadBitmap(hinstance,MAKEINTRESOURCE(IDB_TOOL_NUMBER));    

    hdc
=GetDC(hwnd);
    hdcmem
=CreateCompatibleDC(hdc);
    ReleaseDC(hwnd,hdc);
}


void MYTOOL::SetHINSTANCE(HINSTANCE h)
{
    hinstance
=h;

}


void MYTOOL::SetHWND(HWND h)
{
    hwnd
=h;
}


void MYTOOL::SetHDC(HDC h)
{
    hdc
=h;
}


void MYTOOL::SetPressDown(int x,int y)
{
    
int i=0;
    
    
//按钮个数
    for(i=0;i<button_num;i++)
    
{
        
if(x>=pos.x+i*32 && x<=pos.x+i*32+32
            
&& y>=pos.y && y<=pos.y+32)
        
{
            iPressDown
=i;
            
break;
        }

    }
    
}


int MYTOOL::GetButtonPress(int x,int y)
{
    
int i=0;

    
//按钮个数
    for(i=0;i<button_num ;i++)
    
{
        
if(x>=pos.x+i*32 && x<=pos.x+i*32+32
            
&& y>=pos.y && y<=pos.y+32)
        
{
            iPressDown
=-1;
            
return i;
        }

    }

    
return -1;
}


void MYTOOL::SetPos(int x,int y)
{
    pos.x
=x;
    pos.y
=y;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值