赞
踩
- // yidongtupian.cpp : 定义应用程序的入口点。
- //
-
- #include "stdafx.h"
- #include "yidongtupian.h"
-
- #include "windows.h"
- #include <stdio.h>
-
- #define MAX_LOADSTRING 100
-
- HINSTANCE hInst;
- HBITMAP girl[4],bg;
- HDC hdc,mdc,bufdc;
- HWND hWnd;
- DWORD tPre,tNow;
- int num,dir,x,y;
- ATOM MyRegisterClass(HINSTANCE hInstance);
- BOOL InitInstance(HINSTANCE, int);
- LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
- void MyPaint(HDC hdc);
-
- int APIENTRY WinMain(HINSTANCE hInstance,
- HINSTANCE hPrevInstance,
- LPSTR lpCmdLine,
- int nCmdShow)
- {
- MSG msg;
- MyRegisterClass(hInstance);
- if (!InitInstance (hInstance, nCmdShow))
- {
- return FALSE;
- }
- GetMessage(&msg,NULL,NULL,NULL);
- while( msg.message!=WM_QUIT )
- {
- if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- else
- {
- tNow=GetTickCount();
- if (tNow-tPre>=40)
- {
- MyPaint(hdc);
- }
- }
- }
- return msg.wParam;
- }
- ATOM MyRegisterClass(HINSTANCE hInstance)
- {
- WNDCLASSEX wcex;
- wcex.cbSize=sizeof(WNDCLASSEX);
- wcex.style= CS_HREDRAW | CS_VREDRAW;
- wcex.lpfnWndProc= (WNDPROC)WndProc;
- wcex.cbClsExtra=0;
- wcex.cbWndExtra=0;
- wcex.hInstance=hInstance;
- wcex.hIcon=NULL;
- wcex.hCursor=NULL;
- wcex.hCursor=LoadCursor(NULL,IDC_ARROW);
- wcex.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);
- wcex.lpszMenuName=NULL;
- wcex.lpszClassName=TEXT("canvas");
- wcex.hIconSm=NULL;
- return RegisterClassEx(&wcex);
- }
- BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
- {
- HBITMAP bmp;
- hInst=hInstance;
- hWnd=CreateWindow(TEXT("canvas"),TEXT("绘图窗口"),WS_OVERLAPPEDWINDOW,CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
- if (!hWnd)
- {
- return FALSE;
- }
- MoveWindow(hWnd,10,10,640,480,true);
- ShowWindow(hWnd, nCmdShow);
- UpdateWindow(hWnd);
- hdc = GetDC(hWnd);
- mdc = CreateCompatibleDC(hdc);
- bufdc = CreateCompatibleDC(hdc);
- bmp = CreateCompatibleBitmap(hdc,640,480);
- SelectObject(mdc,bmp);
- x = 300;
- y = 260;
- dir = 0;
- num = 0;
- girl[0] =(HBITMAP)LoadImage(NULL,TEXT("C:/Users/dell/Desktop/新建文件夹/girl0.bmp"),IMAGE_BITMAP,59,59,LR_LOADFROMFILE);
- girl[1] =(HBITMAP)LoadImage(NULL,TEXT("C:/Users/dell/Desktop/新建文件夹/girl1.bmp"),IMAGE_BITMAP,59,59,LR_LOADFROMFILE);
- girl[2] =(HBITMAP)LoadImage(NULL,TEXT("C:/Users/dell/Desktop/新建文件夹/girl2.bmp"),IMAGE_BITMAP,59,59,LR_LOADFROMFILE);
- girl[3] =(HBITMAP)LoadImage(NULL,TEXT("C:/Users/dell/Desktop/新建文件夹/girl3.bmp"),IMAGE_BITMAP,59,59,LR_LOADFROMFILE);
- bg =(HBITMAP)LoadImage(NULL,TEXT("C:/Users/dell/Desktop/新建文件夹/bg.bmp"),IMAGE_BITMAP,640,480,LR_LOADFROMFILE);
- MyPaint(hdc);
- return TRUE;
- }
- void MyPaint(HDC hdc)
- {
- int w,h;
- SelectObject(bufdc,bg);
- BitBlt(mdc,0,0,640,480,bufdc,0,0,SRCCOPY);
- SelectObject(bufdc,girl[dir]);
- switch(dir)
- {
- case 0:
- w = 55;
- h = 74;
- break;
- case 1:
- w = 53;
- h = 77;
- break;
- case 2:
- w = 60;
- h = 74;
- break;
- case 3:
- w = 60;
- h = 74;
- break;
- }
- BitBlt(mdc,x,y,w,h,bufdc,num*w,h,SRCAND);
- BitBlt(mdc,x,y,w,h,bufdc,num*w,0,SRCPAINT);
- BitBlt(hdc,0,0,640,480,mdc,0,0,SRCCOPY);
- tPre=GetTickCount();
- num++;
- if (num==8)
- {
- num=0;
- }
- }
- LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,LPARAM lParam)
- {
- switch(message)
- {
- case WM_KEYDOWN:
- switch (wParam)
- {
- case VK_ESCAPE:
- PostQuitMessage( 0 );
- break;
- case VK_UP:
- switch(dir)
- {
- case 0:
- y -= 1;
- break;
- case 1:
- x -= 1;
- y -= 1;
- break;
- case 2:
- x += 1;
- y -= 1;
- break;
- case 3:
- x += 1;
- y -= 1;
- break;
- }
- if(y < 0)
- y = 0;
- dir = 0;
- break;
- case VK_DOWN:
- switch(dir)
- {
- case 0:
- x += 1;
- y += 1;
- break;
- case 1:
- y += 1;
- break;
- case 2:
- x += 1;
- y += 1;
- break;
- case 3:
- x += 1;
- y += 1;
- break;
- }
- if(y > 375)
- y = 375;
- dir = 1;
- break;
- case VK_LEFT:
- switch(dir)
- {
- case 0:
- x -= 1;
- break;
- case 1:
- x -= 1;
- y += 1;
- break;
- case 2:
- x -= 1;
- break;
- case 3:
- x -= 1;
- break;
- }
- if(x < 0)
- x = 0;
- dir = 2;
- break;
- case VK_RIGHT:
- switch(dir)
- {
- case 0:
- x += 1;
- break;
- case 1:
- x += 1;
- y += 1;
- break;
- case 2:
- x += 1;
- break;
- case 3:
- x += 1;
- break;
- }
- if(x > 575)
- x = 575;
- dir = 3;
- break;
- }
- break;
- case WM_DESTROY:
- int i;
- DeleteDC(mdc);
- DeleteDC(bufdc);
- for (i=0;i<4;i++)
- {
- DeleteObject(girl[i]);
- }
- DeleteObject(bg);
- ReleaseDC(hWnd,hdc);
- PostQuitMessage(0);
- break;
- default:
- return DefWindowProc(hWnd,message,wParam,lParam);
-
- }
- return 0;
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。