📄 mybutton.cpp
字号:
// MyButton.cpp: implementation of the MyButton class.
//
//////////////////////////////////////////////////////////////////////
#include "Windows.h"
#include "MyButton.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
long int timecount;
HINSTANCE hInst;
LRESULT CALLBACK ButtonProc(HWND,UINT,WPARAM,LPARAM);
extern HWND FuTimeWindow;
MyButton::MyButton(void)
{
}
MyButton::~MyButton(void)
{
}
BOOL MyButton::RegisterMyButton( TCHAR ClassName[] ,HINSTANCE hInstance)
{
WNDCLASS wndclass;
wndclass.style =CS_HREDRAW|CS_VREDRAW,
wndclass.lpfnWndProc =ButtonProc;
wndclass.cbClsExtra =0;
wndclass.cbWndExtra =0;
wndclass.hInstance =hInstance;
wndclass.hIcon =0;
wndclass.hCursor =LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground =CreateSolidBrush(RGB(0xff,0xff,0xff));
wndclass.lpszMenuName =NULL;
wndclass.lpszClassName =ClassName;
if(!RegisterClass(&wndclass))
{
MessageBox(NULL,TEXT("Can not register this button!"),
ClassName,MB_ICONERROR);
return FALSE;
}
return TRUE;
}
BOOL MyButton:: CreateMyButton(HINSTANCE hInstance,HWND hwnd,HWND *Buttonhwnd,TCHAR ClassName[],TCHAR WindowName[],DWORD style,int Left,int Top,int cx,int cy)
{
*Buttonhwnd = CreateWindow(ClassName,
WindowName,
style,
Left,
Top,
cx,
cy,
hwnd,
NULL,
hInstance,
NULL);
return *Buttonhwnd==0? FALSE:TRUE;
}
LRESULT CALLBACK ButtonProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
PAINTSTRUCT ps;
static RECT rect1;
HDC hdc;
HDC hMem;
HDC hMem1;
HDC hMem2;
static HBITMAP hBitmap[8];
BITMAP Bitmap;
static int cxSource;
static int cySource;
static int cx;
static int cy;
static RECT rect;
static int WindowID;
static int LButtonUpNum;
switch(message)
{
case WM_CREATE:
hInst=((LPCREATESTRUCT)lParam)->hInstance;
hBitmap[0]=LoadBitmap(hInst,MAKEINTRESOURCE(159));
hBitmap[1]=LoadBitmap(hInst,MAKEINTRESOURCE(163));
hBitmap[2]=LoadBitmap(hInst,MAKEINTRESOURCE(156));
hBitmap[3]=LoadBitmap(hInst,MAKEINTRESOURCE(158));
hBitmap[4]=LoadBitmap(hInst,MAKEINTRESOURCE(164));
hBitmap[5]=LoadBitmap(hInst,MAKEINTRESOURCE(157));
hBitmap[6]=LoadBitmap(hInst,MAKEINTRESOURCE(165));
hBitmap[7]=LoadBitmap(hInst,MAKEINTRESOURCE(166));
GetObject(hBitmap[0],sizeof(Bitmap),&Bitmap);
cxSource=Bitmap.bmWidth;
cySource=Bitmap.bmHeight;
WindowID++;
SetWindowLong(hwnd,GWL_ID,WindowID);
return 0;
case WM_SIZE:
GetClientRect(hwnd,&rect);
cx=rect.right-rect.left;
cy=rect.bottom-rect.top;
return 0;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
GetWindowRect(hwnd,&rect1);
hMem=CreateCompatibleDC(NULL);
hMem1=CreateCompatibleDC(NULL);
hMem2=CreateCompatibleDC(NULL);
SelectObject(hMem,hBitmap[0]);
SelectObject(hMem1,hBitmap[1]);
if(rect1.left==681)
SelectObject(hMem2,hBitmap[2]);
else
SelectObject(hMem2,hBitmap[7]);
StretchBlt(hMem1,0,0,cx,cy,hMem,rect1.left,rect1.top,cx,cy,SRCPAINT);
BitBlt(hMem1,0,0,cx,cy,hMem2,0,0,SRCAND);
BitBlt(hdc,0,0,cx,cy,hMem1,0,0,SRCCOPY);
DeleteDC(hMem);
DeleteDC(hMem1);
DeleteDC(hMem2);
hBitmap[1]=LoadBitmap(hInst,MAKEINTRESOURCE(163));
EndPaint(hwnd,&ps);
return 0;
case WM_LBUTTONDOWN:
hdc=GetDC(hwnd);
GetWindowRect(hwnd,&rect1);
SetCapture(hwnd);
if(GetWindowLong(hwnd,GWL_ID)==1)
{
hMem=CreateCompatibleDC(NULL);
hMem1=CreateCompatibleDC(NULL);
hMem2=CreateCompatibleDC(NULL);
SelectObject(hMem,hBitmap[0]);
SelectObject(hMem1,hBitmap[1]);
SelectObject(hMem2,hBitmap[4]);
StretchBlt(hMem1,0,0,cx,cy,hMem,rect1.left,rect1.top,cx,cy,SRCPAINT);
BitBlt(hMem1,0,0,cx,cy,hMem2,0,0,SRCAND);
BitBlt(hdc,0,0,cx,cy,hMem1,0,0,SRCCOPY);
DeleteDC(hMem);
DeleteDC(hMem1);
DeleteDC(hMem2);
}
else
{
if(LButtonUpNum%2==0)
{
hMem=CreateCompatibleDC(NULL);
hMem1=CreateCompatibleDC(NULL);
hMem2=CreateCompatibleDC(NULL);
SelectObject(hMem,hBitmap[0]);
SelectObject(hMem1,hBitmap[1]);
SelectObject(hMem2,hBitmap[3]);
StretchBlt(hMem1,0,0,cx,cy,hMem,rect1.left,rect1.top,cx,cy,SRCPAINT);
BitBlt(hMem1,0,0,cx,cy,hMem2,0,0,SRCAND);
BitBlt(hdc,0,0,cx,cy,hMem1,0,0,SRCCOPY);
DeleteDC(hMem);
DeleteDC(hMem1);
DeleteDC(hMem2);
}
else
{
hMem=CreateCompatibleDC(NULL);
hMem1=CreateCompatibleDC(NULL);
hMem2=CreateCompatibleDC(NULL);
SelectObject(hMem,hBitmap[0]);
SelectObject(hMem1,hBitmap[1]);
SelectObject(hMem2,hBitmap[5]);
StretchBlt(hMem1,0,0,cx,cy,hMem,rect1.left,rect1.top,cx,cy,SRCPAINT);
BitBlt(hMem1,0,0,cx,cy,hMem2,0,0,SRCAND);
BitBlt(hdc,0,0,cx,cy,hMem1,0,0,SRCCOPY);
DeleteDC(hMem);
DeleteDC(hMem1);
DeleteDC(hMem2);
}
}
hBitmap[1]=LoadBitmap(hInst,MAKEINTRESOURCE(163));
ReleaseDC(hwnd,hdc);
return 0;
case WM_LBUTTONUP:
hdc=GetDC(hwnd);
GetWindowRect(hwnd,&rect1);
if(GetWindowLong(hwnd,GWL_ID)==1)
SendMessage(GetParent(hwnd),WM_CLOSE,0,0);
else
{
LButtonUpNum++;
if(LButtonUpNum%2==1)
{
hMem=CreateCompatibleDC(NULL);
hMem1=CreateCompatibleDC(NULL);
hMem2=CreateCompatibleDC(NULL);
SelectObject(hMem,hBitmap[0]);
SelectObject(hMem1,hBitmap[1]);
SelectObject(hMem2,hBitmap[6]);
StretchBlt(hMem1,0,0,cx,cy,hMem,rect1.left,rect1.top,cx,cy,SRCPAINT);
BitBlt(hMem1,0,0,cx,cy,hMem2,0,0,SRCAND);
BitBlt(hdc,0,0,cx,cy,hMem1,0,0,SRCCOPY);
DeleteDC(hMem);
DeleteDC(hMem1);
DeleteDC(hMem2);
hBitmap[1]=LoadBitmap(hInst,MAKEINTRESOURCE(163));
ReleaseDC(hwnd,hdc);
SendMessage(FuTimeWindow,WM_COMMAND,0,0);
SendMessage(GetParent(hwnd),WM_TIMER,13,0);
}
else
{
hMem=CreateCompatibleDC(NULL);
hMem1=CreateCompatibleDC(NULL);
hMem2=CreateCompatibleDC(NULL);
SelectObject(hMem,hBitmap[0]);
SelectObject(hMem1,hBitmap[1]);
SelectObject(hMem2,hBitmap[7]);
StretchBlt(hMem1,0,0,cx,cy,hMem,rect1.left,rect1.top,cx,cy,SRCPAINT);
BitBlt(hMem1,0,0,cx,cy,hMem2,0,0,SRCAND);
BitBlt(hdc,0,0,cx,cy,hMem1,0,0,SRCCOPY);
DeleteDC(hMem);
DeleteDC(hMem1);
DeleteDC(hMem2);
hBitmap[1]=LoadBitmap(hInst,MAKEINTRESOURCE(163));
ReleaseDC(hwnd,hdc);
SendMessage(GetParent(hwnd),WM_TIMER,12,0);
SendMessage(FuTimeWindow,WM_COMMAND,1,0);
}
ReleaseCapture();
}
return 0;
}
return DefWindowProc(hwnd,message,wParam,lParam);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -