网狐添加纯PNG按钮类功能

自助开通VIP,整站资源任意下载
#pragma once
002#include "PngImage.h"
003#include <vector>
004using namespace std;
005enum BUTTON_STATE
006{
007BUTTON_ENABLE = 0,
008BUTTON_HOVER = 1,
009BUTTON_CLICK = 2,
010BUTTON_CHECK = 3,
011BUTTON_DISABLE= 4,
012};               //按钮状态
013// PngButton.h
014class ButtonCallback
015{
016public:
017ButtonCallback(){};
018virtual void callbackId(int id, WPARAM wParam = 0, LPARAM lParam = 0) =NULL;
019};
020
021class PngButton
022{
023public:
024PngButton(ButtonCallback* pbtnCallback);
025virtual ~PngButton();
026public:
027INT GetWidth(){return m_nSliceWidth;};
028INT GetHeight(){return m_nHeight;};
029void SetButtonImage(LPCTSTR pszFileName,int picStateNum =5);
030void SetButtonImage(HINSTANCE hInstance, LPCTSTR pszResourceName,int picStateNum =5);
031void DrawButton(CDC * pDC);
032void OnLButtonUp(UINT nFlags, CPoint point);
033void OnLButtonDown(UINT nFlags, CPoint point);
034void OnMouseHover(WPARAM wparam, LPARAM lparam);
035void OnMouseLeave(WPARAM wparam, LPARAM lparam);
036
037void setButtonPos(int x,int y);
038CPoint getButtonPos(){return m_Point;};
039void setEnable(bool enable =true){m_bEnable = enable;}
040BOOL getEnable(){return m_bEnable;};
041void setVisable(bool visable =true){ m_bVisable = visable;};
042BOOL getVisable(){return m_bVisable;};
043BUTTON_STATE getbuttonState(){return m_buttonState;};
044void setbtnCheck(bool bcheck =false);
045void setBtnID(int id){m_buttonID = id;};
046
047//鼠标移动事件
048bool OnMouseMoveEvent(CPoint ClientPoint);
049//鼠标左键事件
050bool OnLMouseDownEvent(CPoint ClientPoint);
051//鼠标左键事件
052bool OnLMouseUpEvent(CPoint ClientPoint);
053//鼠标左键事件
054bool OnLMouseDoubleEvent(CPoint ClientPoint);
055//鼠标右键事件
056bool OnRMouseDownEvent(CPoint ClientPoint);
057//鼠标右键事件
058bool OnRMouseUpEvent(CPoint ClientPoint);
059//鼠标右键事件
060bool OnRMouseDoubleEvent(CPoint ClientPoint);
061
062private:
063BOOL m_bEnable; // 按钮是否禁用
064BOOL m_bCursorOnButton;  // 鼠标是否在按钮上
065BOOL m_bPress; // 按钮是否被按下
066BOOL m_bChecked; // checkbutton check状态
067
068BOOL m_bVisable;
069int m_nWidth; //图片宽
070int m_nHeight;     //图片高
071int m_statePicNum;
072int m_nSliceWidth; //每一块图片的宽
073CPngImage m_btnImage; //按钮图片
074CRect m_rectButton;           //按钮区域
075CPoint m_Point;
076ButtonCallback* m_pbtnCallback;
077BUTTON_STATE    m_buttonState;
078int m_buttonID;
079
080};
081
082typedef vector<pngbutton *>  VpngBtn;
083typedef vector</pngbutton><pngbutton *>::iterator VpngBtnItem;
084class PngBtnManager
085{
086public:
087PngBtnManager(){};
088~PngBtnManager();
089void addBtn(PngButton* btn);
090void DrawBtn(CDC *pDc);
091
092//鼠标移动事件
093bool OnMouseMoveEvent(CPoint ClientPoint);
094//鼠标左键事件
095bool OnLMouseDownEvent(CPoint ClientPoint);
096//鼠标左键事件
097bool OnLMouseUpEvent(CPoint ClientPoint);
098//鼠标左键事件
099bool OnLMouseDoubleEvent(CPoint ClientPoint);
100//鼠标右键事件
101bool OnRMouseDownEvent(CPoint ClientPoint);
102//鼠标右键事件
103bool OnRMouseUpEvent(CPoint ClientPoint);
104//鼠标右键事件
105bool OnRMouseDoubleEvent(CPoint ClientPoint);
106private:
107VpngBtn  m_pngbtnManager;
108};
109
110可以很方便的添加纯PNG按钮,不需要再用到一个bmp背景啦。按钮图为5张png图片</pngbutton></vector>


转载请说明出处
棋牌资源网 » 网狐添加纯PNG按钮类功能

发表评论

欢迎 访客 发表评论

这里有你所需要的,找专业的人做专业的事!

本站演示 联系客服