VC++ 左边方块发射子弹打右边 简称坦克打箱子
记录下。。现在用电脑多了不喜欢写字了
[code]#include<windows.h>
//窗口类名和窗口标题
TCHAR szWindowClass[]="演示程序";
TCHAR szWindowTitle[]="主窗口标题";
int x = 0;
int y = 100;
int x3=270,x2;
int y3=170,y2;
bool isFire = FALSE;
//窗口过程函数
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg,
WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
switch(msg)
{
//窗口创建消息
case WM_Create:
//创建一个定时器
SetTimer(hWnd,1,50,NULL);
break;
case WM_TIMER:
y3 += 2;
if (y3> 480)
{
y3 = 0;
}
x2 += 8;
if (x2 > 512)
{
isFire = false;
}
InvalidateRect(hWnd,NULL,true);
break;
//绘制消息响应
case WM_PAINT:
{
HDC hdc = BeginPaint(hWnd,&ps);
//图像图形绘制
//绘制一个矩形
HBRUSH hBrushNew,hBrushOld;
hBrushNew=CreateSolidBrush(0x0000ff); //实体刷子
hBrushOld=(HBRUSH)SelectObject(hdc,hBrushNew);
Rectangle(hdc,x,y,x+40,y+50);
if (isFire)
{
Rectangle(hdc,x2,y2,x2+20,y2+10);
}
hBrushNew=CreateSolidBrush(0xff0000); //实体刷子
hBrushOld=(HBRUSH)SelectObject(hdc,hBrushNew);
Rectangle(hdc,x3,y3,x3+60,y3+30);
SelectObject(hdc,hBrushOld);
DeleteObject(hBrushNew);
EndPaint(hWnd,&ps);
}
break;
//按键消息响应
case WM_KEYDOWN:
switch(wParam) {
case VK_LEFT:
//MessageBox(hWnd,"向左","",MB_OK);
x -= 5;
//InvalidateRect(hWnd,NULL,true);
break;
case VK_RIGHT:
x += 5;
//InvalidateRect(hWnd,NULL,true);
break;
case VK_UP:
y -=5;
break;
case VK_DOWN:
y += 5;
break;
}
InvalidateRect(hWnd,NULL,true);
break;
//键盘消息响应
case WM_LBUTTONDOWN:
if (isFire == false)
{
x2 = x +20;
y2 = y +25;
}
isFire = true;
InvalidateRect(hWnd,NULL,true);
break;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default: //默认的消息处理函数
return DefWindowProc(hWnd,msg,wParam,lParam);
}
}
int WINAPI WinMain( HINSTANCE hInstance,HINSTANCE,LPTSTR lpCmdLine,int nCmdShow)
{
//1.初始化窗口类
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 = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = NULL;
//2. 注册窗口类
RegisterClassEx(&wcex);
//3.创建主窗口
HWND hWnd = CreateWindowEx(0,szWindowClass,
szWindowTitle, WS_OVERLAPPEDWINDOW,300, 400, 512, 480,
HWND_DESKTOP, NULL, hInstance, NULL);
if (!hWnd) return FALSE;
//4.显示并更新主窗口
ShowWindow(hWnd,nCmdShow);
UpdateWindow(hWnd);
//5.进入消息循环
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
//程序退出
}[/code]
C++没学好,现在又来搞VC++ 简直就是悲剧
补充:软件开发 , Vc ,