//游戏循环 while( msg.message!=WM_QUIT ) { if( PeekMessage( &msg, NULL, 0,0 ,PM_REMOVE) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); } else { tNow = GetTickCount(); if(tNow-tPre >= 100) //当此次循环运行与上次绘图时间相差0.1秒时再进行重绘操作 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 = “canvas”; wcex.hIconSm = NULL; return RegisterClassEx(&wcex); } //****初始化函数************************************* // 从文件加载位图 BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { char filename[20] = “”; int i; hInst = hInstance; hWnd = CreateWindow(“canvas”, “动画演示” , WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); if (!hWnd) { return FALSE; } MoveWindow(hWnd,10,10,600,450,true); ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); hdc = GetDC(hWnd); mdc = CreateCompatibleDC(hdc); //载入各个人物位图 for(i=0;i<7;i++) { sprintf(filename,“man%d.bmp”,i); man[i] = (HBITMAP)LoadImage (NULL,filename,IMAGE_BITMAP,640,480,LR_LOADFROMFILE); } num = 0; frame = 0; MyPaint(hdc); return TRUE; } |