Skip to content

Instantly share code, notes, and snippets.

@hirosof
Created December 5, 2012 15:32
Show Gist options
  • Select an option

  • Save hirosof/4216587 to your computer and use it in GitHub Desktop.

Select an option

Save hirosof/4216587 to your computer and use it in GitHub Desktop.
#include <Windows.h>
#ifndef __CHSIMAGEBUTTON_H__
#define __CHSIMAGEBUTTON_H__
//イメージボタンデータ構造体
struct CHSImageButtonData{
//ウィンドウハンドル
HWND hWnd;
//ID
int ObjID;
//位置
struct
{
int x; //X座標
int y; //Y座標
}Position;
//サイズ
struct
{
int Width; //横(X)サイズ
int Height; //縦(Y)サイズ
}Size;
//ビットマップリージョンハンドル
struct
{
HRGN hNormal; //通常
HRGN hDisabled; //無効時
HRGN hOnMouseOver; //マウスオーバー時
HRGN hOnMouseClick; //マウスクリック時
}BitmapRegionHandles;
};
//イメージボタンデータ構造体のポインタ型の定義
typedef CHSImageButtonData *LPCHSImageButtonData;
//コールバック関数呼び出し理由
enum CHSImageButtonCallbackReason{
CHSIBCR_ONMOUSEOVER = 0, //ボタンの上をマウスポインタが移動中である
CHSIBCR_ONMOUSEOUT, //ボタン上からマウスポインタが去って行った
CHSIBCR_ONMOUSECLICK //ボタンがクリックされた
};
//コールバック関数呼び出しデータ
struct CHSImageButtonCallbackData {
//ウィンドウハンドル
HWND hWnd;
//親ウィンドウのハンドル
HWND hParentWnd;
//ID
int ObjID;
//呼び出し理由
CHSImageButtonCallbackReason Reason;
};
typedef CHSImageButtonCallbackData *LPCHSImageButtonCallbackData;
typedef void (__stdcall *LPCHSIBCALLBACK)(LPCHSImageButtonCallbackData);
enum CHSImageButtonStateForImageData{
CHSIBSDID_NORMAL = 0,
CHSIBSDID_ONMOUSEOVER,
CHSIBSDID_ONCLICK,
CHSIBSDID_DISABLED
};
#define CHSIB_ORGINITMSG (WM_APP + 0x000F)
//イメージボタンクラス
class CHSImageButton{
private:
HINSTANCE hInst;
ATOM aWindowClass;
LPCHSImageButtonData lpData;
LPCHSIBCALLBACK callback;
COLORREF TransColor;
int NumberOfDataSpace;
int NumberOfButton;
public:
CHSImageButton(HINSTANCE hInst , LPCHSIBCALLBACK callback ,int class_id = 0);
~CHSImageButton();
static LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
LPCHSImageButtonData AllocDataSpace(int *idx);
void SetTransparentColor(COLORREF color = RGB(0,0,255));
int Create(HWND hwnd, int x,int y,int width,int height, TCHAR *lpszButtonImageBitmapFilePath);
int Create(HWND hwnd, int x,int y,int width,int height, int BitmapResourceID);
int Create(HWND hwnd, int x,int y,int width,int height, HBITMAP hButtonImage);
HRGN CreateBitmapRegion(HBITMAP);
int SetBitmapImage(HWND hButton , int BitmapResourceID , CHSImageButtonStateForImageData type);
int SetBitmapImage(int idButton , int BitmapResourceID , CHSImageButtonStateForImageData type);
int SetBitmapImageFile(HWND hButton , TCHAR *lpszButtonImageBitmapFilePath , CHSImageButtonStateForImageData type);
int SetBitmapImageFile(int idButton , TCHAR *lpszButtonImageBitmapFilePath , CHSImageButtonStateForImageData type);
int SetBitmapImageHandle(HWND hButton , HBITMAP hButtonImage , CHSImageButtonStateForImageData type);
int SetBitmapImageHandle(int idButton , HBITMAP hButtonImage , CHSImageButtonStateForImageData type);
HWND GetHandle(int idButton);
int GetID(HWND hButton);
int Destroy(HWND hButton);
int Destroy(int idButton);
void AllDestroy(void);
LPCHSIBCALLBACK SetCallback(LPCHSIBCALLBACK);
LPCHSIBCALLBACK GetCallback(void);
};
#endif // !__CHSIMAGEBUTTON_H__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment