本文中我们将尝试着控制窗口中的小圆跟随者上下左右键的操作来移动,会涉及键盘事件响应,游戏帧数控制等一些类问题,废话少说,先贴上源码:
#include "main2.h"
#include "MENUs.h"
#define WIN32_LEAN_AND_MEAN
#include <stdlib.h>
#include <windows.h>
#include <windowsx.h>
#include <stdio.h>
#include <math.h>
#include <mmsystem.h>
#define WINDOW_CLASS_NAME "MY_CLASS"
#define WINDOW_WIDTH GetSystemMetrics(SM_CXFULLSCREEN)
#define WINDOW_HEIGHT GetSystemMetrics(SM_CYFULLSCREEN)
// 图形的移动距离
int xv = 50;
int yv = 50;
// 图形的开始坐标
int ball_x = WINDOW_WIDTH/2;
int ball_y = WINDOW_HEIGHT/2;
int ball_x_old=WINDOW_WIDTH/2;
int ball_y_old=WINDOW_HEIGHT/2;
HWND hwnd=NULL;
HPEN black_pen=NULL;
HBRUSH black_brush=NULL;
HPEN white_pen=NULL;
HBRUSH green_brush=NULL;
LRESULT CALLBACK WindowProc(HWND hwnd,
UINT msg,
WPARAM wparam,
LPARAM lparam)
{
PAINTSTRUCT ps;//图形绘制结构体
HDC hdc=NULL;//句柄
switch(msg)
{
case WM_CREATE: //窗口创建时
{
return(0);
} break;
case WM_PAINT: //窗口重绘时
{
hdc = BeginPaint(hwnd,&ps); //开始绘制
EndPaint(hwnd,&ps);//结束绘制
return(0);
} br