#include<windows.h>
#include<windowsx.h>
#include "Globle.h"
#include<stdio.h>
#pragma comment(lib,"msimg32.lib") //获取透明色要用到的库文件
#pragma comment(lib,"winmm.lib") //加载音乐要用到的库文件
struct Mouse
{
int MouseX,MouseY;
};
struct Mouse MouseList[3] ={{0,0}}/*平民难度*/,MouseList2[4]={{0,0}};//英雄难度
HDC LoadBitMapToDC(HINSTANCE hInst,char * fileName) //导入文件
{
HBITMAP hBitMap=(HBITMAP)LoadImage(hInst,fileName,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
HDC hBitMapDC = ::CreateCompatibleDC(NULL);
::SelectObject(hBitMapDC,hBitMap);
::DeleteObject(hBitMap);
return hBitMapDC;
}
HDC LoadBitMapToDC(HINSTANCE hInst,char * fileName,long& width,long& height) //将文件导入到内存中并自动获取宽和高
{
HBITMAP hBitMap=(HBITMAP)LoadImage(hInst,fileName,IMAGE_BITMAP,0,0,LR_LOADFROMFILE | LR_CREATEDIBSECTION);
DIBSECTION dib;
::GetObject(hBitMap,sizeof(dib),&dib);
BITMAPINFOHEADER bm=dib.dsBmih;
width=bm.biWidth;
height=bm.biHeight;
HDC hBitMapDC = ::CreateCompatibleDC(NULL);
::SelectObject(hBitMapDC,hBitMap);
::DeleteObject(hBitMap);
return hBitMapDC;
}
//7、消息处理
long CALLBACK WndProc(HWND hWnd, int message, int wParam, int lParam)
{
switch (message)
{
case WM_KEYDOWN:
{
switch(wParam)
{
case VK_SPACE: time=false;KillTimer(hWnd,1);break; //空格暂停
case VK_RETURN:time = true;SetTimer(hWnd,1,1500,NULL);break; //Enter 继续
case VK_RIGHT :Music++;if(Music==6)Music=1;sprintf(s,"sound//Music%d.wav",Music);sndPlaySound(s,SND_ALIAS |SND_ASYNC);break;// 换背景音乐
case VK_LEFT :Music--;if(Music == 0)Music=5;sprintf(s,"sound//Music%d.wav",Music);sndPlaySound(s,SND_ALIAS |SND_ASYNC);break;// 换背景音乐
case VK_BACK: //返回
{ HDC hDc = GetDC(hWnd);
StretchBlt(hDc,0,0,rect.right-rect.left, rect.bottom-rect.top,G_BitMapBK02DC,0,0, BKWidth,BKHeight,SRCCOPY);
SetBkColor(hDc,RGB(121,41,180));
SetTextColor(hDc,RGB(0,200,250));
TextOut(hDc,380,250,"1---平民难度",strlen("1---平民难度"));
TextOut(hDc,380,280,"2---英雄难度",strlen("2---英雄难度"));
Temp = 0;
MouseList_Score = 0;
MouseList2_Score = 0;
ClickTotal = 0;
ClickTotal2 = 0;
ReleaseDC(hWnd,hDc);
break;}
}
break;
}
case WM_CREATE:
{
G_BitMapBKDC = LoadBitMapToDC(G_hInst,"bmp01.bmp",BKWidth,BKHeight);
G_BitMapbkDC = LoadBitMapToDC(G_hInst,"bmp02.bmp",bkWidth,bkHeight);
G_BitMapMouseDC = LoadBitMapToDC(G_hInst,"bmp03.bmp",MouseWidth,MouseHeight);
G_BitMapBK02DC = LoadBitMapToDC(G_hInst,"BK09_01.bmp",bgWidth,bgHeight);
G_BitMapQQDC = LoadBitMapToDC(G_hInst,"QQ.bmp",QQWidth,QQHeight);
G_BitMapPersonDC = LoadBitMapToDC(G_hInst,"Person.bmp",PersonWidth,PersonHeight);
G_BitMapPersonComeOnDC = LoadBitMapToDC(G_hInst,"PersonComeOn.bmp",PersonComeOnWidth,PersonComeOnHeight);
G_BitMapComeOnDC = LoadBitMapToDC(G_hInst,"ComeOn.bmp",ComeOnWidth,ComeOnHeight);
G_BitMapPlaneDC = LoadBitMapToDC(G_hInst,"Plane.bmp",PlaneWidth,PlaneHeight);
GetClientRect(hWnd,&rect); //获取客户端区域
SetTimer(hWnd,1,1500,NULL);
for(int i=0;i<3;i++)
{
MouseList[i].MouseX=200*(i+1);
MouseList[i].MouseY=300;
}
for(i=0;i<4;i++)
{
MouseList2[i].MouseX=200*(i+1);
MouseList2[i].MouseY=300;
}
break;
}
case WM_LBUTTONDOWN:
{
//获取鼠标坐标
int x=GET_X_LPARAM(lParam);
int y=GET_Y_LPARAM(lParam);
HDC hDc = GetDC(hWnd);
if(Temp==1 && time == true) //平民难度
{
ClickTotal++;
if( ClickTotal>15)
{
MessageBox(NULL,"任务失败","提示",MB_OK);
Temp=0;
}
char s[20];
sprintf(s,"Easy_Score:%d",MouseList_Score);
SetTextColor(hDc,RGB(0,200,250));
TextOut(hDc,300,20,s,strlen(s));
sprintf(s,"您共点击了:%d",ClickTotal);TextOut(hDc,300,40,s,strlen(s));
if(x>MouseList[0].MouseX && y>MouseList[0].MouseY-33 && x<MouseList[0].MouseX+MouseWidth && y<MouseList[0].MouseY+MouseHeight-33)
{
Flag1 = false ; Flag2 = true; Flag3 = true;
sndPlaySound("sound//sound2.wav",SND_ASYNC|SND_NOSTOP);
BitBlt(hDc,0,0,bkWidth,bkHeight,G_BitMapBKDC,0,0,SRCCOPY);
MouseList_Score++;
}
else if(x>MouseList[1].MouseX && y>MouseList[1].MouseY-33 && x<MouseList[1].MouseX+MouseWidth && y<MouseList[1].MouseY-33+MouseHeight)
{
Flag2 = false ; Flag1 = true; Flag3 = true; MouseList_Score++; sndPlaySound("sound//sound2.wav",SND_ASYNC|SND_NOSTOP);
BitBlt(hDc,0,0,bkWidth,bkHeight,G_BitMapBKDC,0,0,SRCCOPY);
}
else if(x>MouseList[2].MouseX && y>MouseList[2].MouseY-33 && x<MouseList[2].MouseX+MouseWidth && y<MouseList[2].MouseY-33+MouseHeight)
{
Flag3 = false ; Flag1 = true; Flag2 = true; MouseList_Score++;
BitBlt(hDc,0,0,bkWidth,bkHeight,G_BitMapBKDC,0,0,SRCCOPY);sndPlaySound("sound//sound2.wav",SND_ASYNC|SND_NOSTOP);
}
else
{
sndPlaySound("sound//bob.wav",SND_ASYNC);
}
}
else if(Temp == 0)
{
if(x>70 && x<320 && y>70 && y<100)
{
sndPlaySound("sound//sound2.wav",SND_ASYNC|SND_NOSTOP);
Temp=1;
}
if(x>70 && x<320 && y>150 && y<200)
{
sndPlaySound("sound//sound2.wav",SND_ASYNC|SND_NOSTOP); //加载音乐
Temp = 2;
}
}
else if(Temp == 2 && time == true) //英雄难度
{
ClickTotal2++;
if( ClickTotal2>15)
{
MessageBox(NULL,"任务失败","提示",MB_OK);
Temp =0;
}
char s[20];
sprintf(s,"Hero_Score:%d",MouseList2_Score);
SetTextColor(hDc,RGB(0,200,250));
TextOut(hDc,300,20,s,strlen(s));
sprintf(s,"您共点击了:%d",ClickTotal2);TextOut(hDc,300,40,s,strlen(s));
if(x>MouseList2[0].MouseX && y>MouseList2[0].MouseY-33 && x<MouseList2[0].MouseX+MouseWidth && y<MouseList2[0].MouseY+MouseHeight-33)
{
Flag1 = false ; Flag2 = true; Flag3 = true; Flag4 = true;
BitBlt(hDc,0,0,bkWidth,bkHeight,G_BitMapBKDC,0,0,SRCCOPY);
sndPlaySound("sound//1.wav",SND_ASYNC|SND_ASYNC);
MouseList2_Score++;
}
else if(x>MouseList2[1].MouseX && y>MouseList2[1].MouseY-33 && x<MouseList2[1].MouseX+MouseWidth && y<MouseList2[1].MouseY-33+MouseHeight)
{
Flag2 = false ; Flag1 = true; Flag3 = true; Flag4 = true;
BitBlt(hDc,0,0,bkWidth,bkHeight,G_BitMapBKDC,0,0,SRCCOPY);MouseList2_Score++;
sndPlaySound("sound//1.wav",SND_ASYNC|SND_ASYNC);
}
else if(x>MouseList2[2].MouseX && y>MouseList2[2].MouseY-33 && x<MouseList2[2].MouseX+MouseWidth && y<MouseList2[2].MouseY-33+MouseHeight)
{
Flag3 = false ; Flag1 = true; Flag2 = true; Flag4 = true;
BitBlt(hDc,0,0,bkWidth,bkHeight,G_BitMapBKDC,0,0,SRCCOPY);MouseList2_Score++;
sndPlaySound("sound//1.wav",SND_ASYNC|SND_ASYNC);
}
else if(x>MouseList2[3].MouseX && y>MouseList2[3].MouseY-33 && x<MouseList2[3].MouseX+MouseWidth && y<MouseList2[3].MouseY-33+MouseHeight)
{
Flag3 = true; Flag1 = true; Flag2 = true; Flag4 =false ;
BitBlt(hDc,0,0,bkWidth,bkHeight,G_BitMapBKDC,0,0,SRCCOPY);MouseList2_Score++;
sndPlaySound("sound//1.wav",SND_ASYNC|SND_ASYNC);
}
else
{
sndPlaySound("sound//bob.wav",SND_ASYNC);
}
}
ReleaseDC(hWnd,hDc);
break;
}
case WM_TIMER:
{
HDC hDc = GetDC(hWnd);
StretchBlt(hDc,0,0,rect.right-rect.left, rect.bottom-rect.top,G_BitMapBK02DC,0,0, BKWidth,BKHeight,SRCCOPY);
if(Temp ==2) //英雄难度
{
StretchBlt(hDc,0,0,rect.right-rect.left, rect.bottom-rect.top,G_BitMapBKDC,0,0, BKWidth,BKHeight,SRCCOPY);
Color = ::GetPixel(G_BitMapPlaneDC,0,0);
::TransparentBlt(hDc,PlaneX,20,PlaneWidth,PlaneHeight,G_BitMapPlaneDC,0,0,PlaneWidth,PlaneHeight,Color);
PlaneX-=20;
if(PlaneX == -20)
PlaneX= 850;
Color = ::GetPixel(G_BitMapPersonComeOnDC,0,0);
::TransparentBlt(hDc,500,50,PersonComeOnWidth,PersonComeOnHeight,G_BitMapPersonComeOnDC,0,0,PersonComeOnWidth,PersonComeOnHeight,Color);
if(flag == 1)
{
Color = ::GetPixel(G_BitMapComeOnDC,0,0); //获取透明色
::TransparentBlt(hDc,100,50,ComeOnWidth,ComeOnHeight,G_BitMapComeOnDC,0,0,ComeOnWidth,ComeOnHeight,Color);}
flag = -flag ;
char s[20];
sprintf(s,"Hero_Score:%d",MouseList2_Score);
SetTextColor(hDc,RGB(0,200,250)); //设置文本颜色
TextOut(hDc,300,20,s,strlen(s)); //将文本输出
sprintf(s,"您共点击了:%d",ClickTotal2);TextOut( hDc,300,40,s,strlen(s));
if(Flag1 == true && Flag2 == true && Flag3 == false && Flag4 == true)
{
BitBlt(hDc,MouseList2[0].MouseX,MouseList2[0].MouseY,bkWidth,bkHeight,G_BitMapbkDC,0,0,SRCCOPY);
Sleep(500);
BitBlt(hDc,MouseList2[0].MouseX,MouseList2[0].MouseY-33,MouseWidth,MouseHeight,G_BitMapMouseDC,0,0,SRCCOPY);
BitBlt(hDc,MouseList2[1].MouseX,MouseList2[1].MouseY,bkWidth,bkHeight,G_BitMapbkDC,0,0,SRCCOPY);
Sleep(500);
BitBlt(hDc,MouseList2[1].MouseX,MouseList2[1].MouseY-33,MouseWidth,MouseHeight,G_BitMapMouseDC,0,0,SRCCOPY);
BitBlt(hDc,MouseList2[3].MouseX,MouseList2[3].MouseY,bkWidth,bkHeight,G_BitMapbkDC,0,0,SRCCOPY);
Sleep(500);
BitBlt(hDc,MouseList2[3].MouseX,MouseList2[3].MouseY-33,MouseWidth,MouseHeight,G_BitMapMouseDC,0,0,SRCCOPY);
}
else if(Flag3 == true && Flag2 == true && Flag1 == false && Flag4 == true)
{
BitBlt(hDc,MouseList2[1].MouseX,MouseList2[1].MouseY,bkWidth,bkHeight,G_BitMapbkDC,0,0,SRCCOPY);
Sleep(500);
BitBlt(hDc,MouseList2[1].MouseX,MouseList2[1].MouseY-33,MouseWidth,MouseHeight,G_BitMapMouseDC,0,0,SRCCOPY);
BitBlt(hDc,MouseList2[2].MouseX,MouseList2[2].MouseY,bkWidth,bkHeight,G_BitMapbkDC,0,0,SRCCOPY);
Sleep(500);
BitBlt(hDc,MouseList2[2].MouseX,MouseList2[2].MouseY-33,MouseWidth,MouseHeight,G_BitMapMouseDC,0,0,SRCCOPY);
BitBlt(hDc,MouseList2[3].MouseX,MouseList2[3].MouseY,bkWidth,bkHeight,G_BitMapbkDC,0,0,SRCCOPY);
Sleep(500);
BitBlt(hDc,MouseList2[3].MouseX,MouseList2[3].MouseY-33,MouseWidth,MouseHeight,G_BitMapMouseDC,0,0,SRCCOPY);
}
else if(Flag3 == true && Flag1 == true && Flag2 == false && Flag4 == true)
{
BitBlt(hDc,MouseList2[2].MouseX,MouseList2[2].MouseY,bkWidth,bkHeight,G_BitMapbkDC,0,0,SRCCOPY);
Sleep(500);
BitBlt(hDc,MouseList2[2].MouseX,MouseList2[2].MouseY-33,MouseWidth,MouseHeight,G_BitMapMouseDC,0,0,SRCCOPY);
BitBlt(hDc,MouseList2[0].MouseX,MouseList2[0].MouseY,bkWidth,bkHeight,G_BitMapbkDC,0,0,SRCCOPY);
Sleep(500);
BitBlt(hDc,MouseList2[0].MouseX,MouseList2[0].MouseY-33,MouseWidth,MouseHeight,G_BitMapMouseDC,0,0,SRCCOPY);
BitBlt(hDc,MouseList2[3].MouseX,MouseList2[3].MouseY,bkWidth,bkHeight,G_BitMapbkDC,0,0,SRCCOPY);
Sleep(500);
BitBlt(hDc,MouseList2[3].MouseX,MouseList2[3].MouseY-33,MouseWidth,MouseHeight,G_BitMapMouseDC,0,0,SRCCOPY);
}
else
{
BitBlt(hDc,MouseList2[2].MouseX,MouseList2[2].MouseY,bkWidth,bkHeight,G_BitMapbkDC,0,0,SRCCOPY);
Sleep(500);
BitBlt(hDc,MouseList2[2].MouseX,MouseList2[2].MouseY-33,MouseWidth,MouseHeight,G_BitMapMouseDC,0,0,SRCCOPY);
BitBlt(hDc,MouseList2[0].MouseX,MouseList2[0].MouseY,bkWidth,bkHeight,G_BitMapbkDC,0,0,SRCCOPY);
Sleep(500);
BitBlt(hDc,MouseList2[0].MouseX,MouseList2[0].MouseY-33,MouseWidth,MouseHeight,G_BitMapMouseDC,0,0,SRCCOPY);
BitBlt(hDc,MouseList2[1].MouseX,MouseList2[0].MouseY,bkWidth,bkHeight,G_BitMapbkDC,0,0,SRCCOPY);
Sleep(500);
BitBlt(hDc,MouseList2[1].MouseX,MouseList2[0].MouseY-33,MouseWidth,MouseHeight,G_BitMapMouseDC,0,0,SRCCOPY);
}
if(MouseList2_Score == 10)
{
Color = ::GetPixel(G_BitMapQQDC,0,0);
::TransparentBlt(hDc,400,226,QQWidth,QQHeight,G_BitMapQQDC,0,0,QQWidth,QQHeight,Color);
Sleep(5000);
Temp = 0;
}
}
if(Temp==1) //平民难度
{
StretchBlt(hDc,0,0,rect.right-rect.left, rect.bottom-rect.top,G_BitMapBKDC,0,0, BKWidth,BKHeight,SRCCOPY);
Color = ::GetPixel(G_BitMapPlaneDC,0,0);
::TransparentBlt(hDc,PlaneX,20,PlaneWidth,PlaneHeight,G_BitMapPlaneDC,0,0,PlaneWidth,PlaneHeight,Color);
PlaneX-=20;
if(PlaneX == -20)
PlaneX= 850;
Color = ::GetPixel(G_BitMapPersonComeOnDC,0,0);
::TransparentBlt(hDc,500,50,PersonComeOnWidth,PersonComeOnHeight,G_BitMapPersonComeOnDC,0,0,PersonComeOnWidth,PersonComeOnHeight,Color);
if(flag == 1)
{
Color = ::GetPixel(G_BitMapComeOnDC,0,0);
::TransparentBlt(hDc,100,50,ComeOnWidth,ComeOnHeight,G_BitMapComeOnDC,0,0,ComeOnWidth,ComeOnHeight,Color);}
flag=-flag;
char s[20];
sprintf(s,"Easy_Score:%d",MouseList_Score);
SetTextColor(hDc,RGB(0,200,250));
TextOut(hDc,300,20,s,strlen(s));
sprintf(s,"您共点击了:%d",ClickTotal);TextOut(hDc,300,40,s,strlen(s));
if(Flag1 == true && Flag2 == true && Flag3 == false)
{
BitBlt(hDc,MouseList[0].MouseX,MouseList[0].MouseY,bkWidth,bkHeight,G_BitMapbkDC,0,0,SRCCOPY);
Sleep(500);
BitBlt(hDc,MouseList[0].MouseX,MouseList[0].MouseY-33,MouseWidth,MouseHeight,G_BitMapMouseDC,0,0,SRCCOPY);
BitBlt(hDc,MouseList[1].MouseX,MouseList[1].MouseY,bkWidth,bkHeight,G_BitMapbkDC,0,0,SRCCOPY);
Sleep(500);
BitBlt(hDc,MouseList[1].MouseX,MouseList[1].MouseY-33,MouseWidth,MouseHeight,G_BitMapMouseDC,0,0,SRCCOPY);
}
else if(Flag3 == true && Flag2 == true && Flag1 == false)
{
BitBlt(hDc,MouseList[1].MouseX,MouseList[1].MouseY,bkWidth,bkHeight,G_BitMapbkDC,0,0,SRCCOPY);
Sleep(500);
BitBlt(hDc,MouseList[1].MouseX,MouseList[1].MouseY-33,MouseWidth,MouseHeight,G_BitMapMouseDC,0,0,SRCCOPY);
BitBlt(hDc,MouseList[2].MouseX,MouseList[2].MouseY,bkWidth,bkHeight,G_BitMapbkDC,0,0,SRCCOPY);
Sleep(500);
BitBlt(hDc,MouseList[2].MouseX,MouseList[2].MouseY-33,MouseWidth,MouseHeight,G_BitMapMouseDC,0,0,SRCCOPY);
}
else
{
BitBlt(hDc,MouseList[2].MouseX,MouseList[2].MouseY,bkWidth,bkHeight,G_BitMapbkDC,0,0,SRCCOPY);
Sleep(500);
BitBlt(hDc,MouseList[2].MouseX,MouseList[2].MouseY-33,MouseWidth,MouseHeight,G_BitMapMouseDC,0,0,SRCCOPY);
BitBlt(hDc,MouseList[0].MouseX,MouseList[0].MouseY,bkWidth,bkHeight,G_BitMapbkDC,0,0,SRCCOPY);
Sleep(500);
BitBlt(hDc,MouseList[0].MouseX,MouseList[0].MouseY-33,MouseWidth,MouseHeight,G_BitMapMouseDC,0,0,SRCCOPY);
}
if(MouseList_Score == 10)
{
Color = ::GetPixel(G_BitMapQQDC,0,0);
::TransparentBlt(hDc,400,226,QQWidth,QQHeight,G_BitMapQQDC,0,0,QQWidth,QQHeight,Color);
Sleep(5000);
Temp = 0;
}
}
ReleaseDC(hWnd,hDc);
break;
}
case WM_SIZE:
{
GetClientRect(hWnd,&rect);
break;
}
case WM_DESTROY:
{
DeleteDC(G_BitMapBKDC);
G_BitMapBKDC=NULL;
DeleteDC(G_BitMapbkDC);
G_BitMapbkDC=NULL;
DeleteDC(G_BitMapMouseDC);
G_BitMapMouseDC=NULL;
DeleteDC(G_BitMapPersonDC);
G_BitMapPersonDC=NULL;
DeleteDC(G_BitMapPersonComeOnDC);
G_BitMapPersonComeOnDC=NULL;
DeleteDC(G_BitMapComeOnDC);
G_BitMapComeOnDC=NULL;
DeleteDC(G_BitMapBK02DC);
G_BitMapBK02DC=NULL;
DeleteDC(G_BitMapQQDC);
G_BitMapQQDC=NULL;
KillTimer(hWnd,1);
PostQuitMessage(0);
break;
}
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
int _stdcall WinMain(HINSTANCE hInstance,
HINSTANCE hPrelnstance,
LPSTR lpCmdLine,
int nShowCmd)
{
G_hInst = hInstance;
//1、设置窗体属性
WNDCLASSEX wcex;
// 结构体的大小
wcex.cbSize = sizeof(WNDCLASSEX);
// 窗体类的样式
wcex.style = CS_HREDRAW | CS_VREDRAW;
// *窗体回调函数
wcex.lpfnWndProc = (WNDPROC)WndProc;
// 窗体类额外字节数,通常为0
wcex.cbClsExtra = 0;
// 窗体实例额外字节数,通常为0
wcex.cbWndExtra = 0;
// *应用程序实例句柄
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon( NULL, IDI_APPLICATION ); ; // 窗体大图标
wcex.hCursor = LoadCursor(NULL, IDC_CROSS); // 窗体鼠标光标样式
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); // 窗体背景色
wcex.lpszMenuName = NULL; // 窗体主菜单
// *窗体类名称
wcex.lpszClassName = "FW";
wcex.hIconSm = NULL; // 窗体小图标
//2、注册窗体
RegisterClassEx(&wcex);
//3、创建窗体
HWND hWnd = CreateWindow(
"FW", // *窗体类名称
"Mouse", // 窗体标题名
WS_OVERLAPPEDWINDOW, // 窗体外观样式
CW_USEDEFAULT, // 窗体在屏幕上的水平位置
0, // 窗体在屏幕上的垂直位置
CW_USEDEFAULT, // 窗口的宽度
0, // 窗口的高度
NULL, // 父窗体句柄
NULL, // 窗口菜单句柄
hInstance, // *创建窗体的应用程序实例句柄
NULL); // 创建窗体时的额外信息,通常为NULL
if (NULL == hWnd)
{
return FALSE;
}
//4、显示窗体
ShowWindow(hWnd, nShowCmd);
//5、 更新窗体
UpdateWindow(hWnd);
//6、主消息循环
MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) // 从消息队列中获取消息
{
TranslateMessage(&msg); // 转换消息
DispatchMessage(&msg); // 分发消息给回调函数
}
return msg.wParam;
}