• 大小: 755KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-25
  • 语言: C/C++
  • 标签: c++代码  小球反弹  

资源简介

在窗口中显示一个小球,该球以45度角反弹直线运动,碰撞后依然45度运行

资源截图

代码片段和文件信息

// experiment3.cpp : Defines the entry point for the application.
//

#include “stdafx.h“
#include “resource.h“

#define MAX_LOADSTRING 100

// Global Variables:
HINSTANCE hInst; // current instance
TCHAR sztitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text

// Foward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE int);
LRESULT CALLBACK WndProc(HWND UINT WPARAM LPARAM);
LRESULT CALLBACK About(HWND UINT WPARAM LPARAM);

int xcenter = 300;
int ycenter = 300;

int xmove = 5; 
int ymove = 5;

int APIENTRY WinMain(HINSTANCE hInstance
                     HINSTANCE hPrevInstance
                     LPSTR     lpCmdLine
                     int       nCmdShow)
{
  // TODO: Place code here.
MSG msg;
HACCEL hAccelTable;

// Initialize global strings
LoadString(hInstance IDS_APP_title sztitle MAX_LOADSTRING);
LoadString(hInstance IDC_EXPERIMENT3 szWindowClass MAX_LOADSTRING);
MyRegisterClass(hInstance);

// Perform application initialization:
if (!InitInstance (hInstance nCmdShow)) 
{
return FALSE;
}

hAccelTable = LoadAccelerators(hInstance (LPCTSTR)IDC_EXPERIMENT3);

  

// Main message loop:
while (GetMessage(&msg NULL 0 0)) 
{
if (!TranslateAccelerator(msg.hwnd hAccelTable &msg)) 
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

return msg.wParam;
}



//
//  FUNCTION: MyRegisterClass()
//
//  PURPOSE: Registers the window class.
//
//  COMMENTS:
//
//    This function and its usage is only necessary if you want this code
//    to be compatible with Win32 systems prior to the ‘RegisterClassEx‘
//    function that was added to Windows 95. It is important to call this function
//    so that the application will get ‘well formed‘ small icons associated
//    with it.
//
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 = LoadIcon(hInstance (LPCTSTR)IDI_EXPERIMENT3);
wcex.hCursor = LoadCursor(NULL IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = (LPCSTR)IDC_EXPERIMENT3;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance (LPCTSTR)IDI_SMALL);

return RegisterClassEx(&wcex);
}

//
//   FUNCTION: InitInstance(HANDLE int)
//
//   PURPOSE: Saves instance handle and creates main window
//
//   COMMENTS:
//
//        In this function we save the instance handle in a global variable and
//        create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance int nCmdShow)
{
   HWND hWnd;

   hInst = hInstance; // Store instance handle in 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件     159843  2012-03-28 09:13  experiment3\experiment3\Debug\experiment3.exe

     文件     195224  2012-03-28 09:13  experiment3\experiment3\Debug\experiment3.ilk

     文件       9295  2012-03-28 09:13  experiment3\experiment3\Debug\experiment3.obj

     文件    1951796  2012-03-27 23:22  experiment3\experiment3\Debug\experiment3.pch

     文件     459776  2012-03-28 09:13  experiment3\experiment3\Debug\experiment3.pdb

     文件       2152  2012-03-27 23:22  experiment3\experiment3\Debug\experiment3.res

     文件      55282  2012-03-27 23:22  experiment3\experiment3\Debug\StdAfx.obj

     文件      91136  2012-03-28 09:13  experiment3\experiment3\Debug\vc60.idb

     文件     176128  2012-03-28 09:13  experiment3\experiment3\Debug\vc60.pdb

     文件       5748  2012-03-27 23:50  experiment3\experiment3\experiment3.cpp

     文件       4556  2012-03-27 22:51  experiment3\experiment3\experiment3.dsp

     文件        530  2012-03-27 22:51  experiment3\experiment3\experiment3.dsw

     文件        341  2012-03-27 22:51  experiment3\experiment3\experiment3.h

     文件       1078  2012-03-27 22:51  experiment3\experiment3\experiment3.ico

     文件      53760  2012-03-28 09:14  experiment3\experiment3\experiment3.opt

     文件        929  2012-03-28 09:13  experiment3\experiment3\experiment3.plg

     文件       3109  2012-03-27 22:51  experiment3\experiment3\experiment3.rc

     文件       2115  2012-03-27 22:51  experiment3\experiment3\ReadMe.txt

     文件        801  2012-03-27 22:51  experiment3\experiment3\resource.h

     文件        318  2012-03-27 22:51  experiment3\experiment3\small.ico

     文件        298  2012-03-27 22:51  experiment3\experiment3\StdAfx.cpp

     文件        936  2012-03-27 22:51  experiment3\experiment3\StdAfx.h

     目录          0  2012-03-28 09:13  experiment3\experiment3\Debug

     目录          0  2012-03-28 09:14  experiment3\experiment3

     目录          0  2012-03-28 09:12  experiment3

     文件      50176  2012-03-28 09:14  experiment3\experiment3\experiment3.ncb

----------- ---------  ---------- -----  ----

              3225327                    26


评论

共有 条评论