游戏编程中的人工智能技术【1】

1。 HelloWorld------------------------------------------------------------------------------------

#include <windows.h> int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { MessageBox(NULL, " Hello World!", " MsgBox", 0); return 0; }2。HelloWorld(窗口)--------------------------------------------------------#include <windows.h> #include " defines.h" char* g_szApplicationName = " Hello World!"; char* g_szWindowClassName = " MyWindowClass"; LRESULT CALLBACK WindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { return DefWindowProc (hwnd, msg, wParam, lParam); } //-------------------------------- WinMain ------------------------------- // // The entry point of the windows program //------------------------------------------------------------------------ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow) { //handle to our window HWND hWnd; //our window class structure WNDCLASSEX winclass; // first fill in the window class stucture winclass.cbSize = sizeof(WNDCLASSEX); winclass.style = CS_HREDRAW | CS_VREDRAW; winclass.lpfnWndProc = WindowProc; winclass.cbClsExtra = 0; winclass.cbWndExtra = 0; winclass.hInstance = hInstance; winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); winclass.hCursor = LoadCursor(NULL, IDC_ARROW); winclass.hbrBackground = (HBRUSH)GetStockObject (WHITE_BRUSH); winclass.lpszMenuName = NULL; winclass.lpszClassName = g_szWindowClassName; winclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION); //register the window class if (!RegisterClassEx(&winclass)) { MessageBox(NULL, " Class Registration Failed!", " Error", 0); //exit the application return 0; } //create the window and assign its ID to hwnd hWnd = CreateWindowEx (NULL, // extended style g_szWindowClassName, // window class name g_szApplicationName, // window caption WS_OVERLAPPEDWINDOW, // window style 0, // initial x position 0, // initial y position WINDOW_WIDTH, // initial x size WINDOW_HEIGHT, // initial y size NULL, // parent window handle NULL, // window menu handle hInstance, // program instance handle NULL); // creation parameters //make sure the window creation has gone OK if(!hWnd) { MessageBox(NULL, " CreateWindowEx Failed!", " Error!", 0); } //make the window visible ShowWindow (hWnd, iCmdShow); UpdateWindow(hWnd); UnregisterClass( g_szWindowClassName, winclass.hInstance ); return 0; } 3。Helloworld(windows消息循环,使窗口驻留)-------------------------------#include <windows.h> #include " defines.h" //--------------------------------- Globals ------------------------------ // //------------------------------------------------------------------------ char* g_szApplicationName = " HelloWorld3"; char* g_szWindowClassName = " MyWindowClass"; //---------------------------- WindowProc --------------------------------- // // This is the callback function which handles all the windows messages //------------------------------------------------------------------------- LRESULT CALLBACK WindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { //A WM_CREATE msg is sent when your application window is first //created case WM_CREATE: { PlaySound(" window_open.wav", NULL, SND_FILENAME | SND_ASYNC); } break; case WM_PAINT: { PAINTSTRUCT ps; BeginPaint (hwnd, &ps); //**this is where we do any drawing to the screen** EndPaint (hwnd, &ps); } break; case WM_DESTROY: { // kill the application, this sends a WM_QUIT message PostQuitMessage (0); } break; } //end switch //this is where all the messages not specifically handled by our //winproc are sent to be processed return DefWindowProc (hwnd, msg, wParam, lParam); } //-------------------------------- WinMain ------------------------------- // // The entry point of the windows program //------------------------------------------------------------------------ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow) { //handle to our window HWND hWnd; //our window class structure WNDCLASSEX winclass; // first fill in the window class stucture winclass.cbSize = sizeof(WNDCLASSEX); winclass.style = CS_HREDRAW | CS_VREDRAW; winclass.lpfnWndProc = WindowProc; winclass.cbClsExtra = 0; winclass.cbWndExtra = 0; winclass.hInstance = hInstance; winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); winclass.hCursor = LoadCursor(NULL, IDC_ARROW); winclass.hbrBackground = (HBRUSH)GetStockObject (WHITE_BRUSH); winclass.lpszMenuName = NULL; winclass.lpszClassName = g_szWindowClassName; winclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION); //register the window class if (!RegisterClassEx(&winclass)) { MessageBox(NULL, " Registration Failed!", " Error", 0); //exit the application return 0; } //create the window and assign its ID to hwnd hWnd = CreateWindowEx (NULL, // extended style g_szWindowClassName, // window class name g_szApplicationName, // window caption WS_OVERLAPPEDWINDOW, // window style 0, // initial x position 0, // initial y position WINDOW_WIDTH, // initial x size WINDOW_HEIGHT, // initial y size NULL, // parent window handle NULL, // window menu handle hInstance, // program instance handle NULL); // creation parameters //make sure the window creation has gone OK if(!hWnd) { MessageBox(NULL, " CreateWindowEx Failed!", " Error!", 0); } //make the window visible ShowWindow (hWnd, iCmdShow); UpdateWindow (hWnd); //this will hold any windows messages MSG msg; //entry point of our message handler while (GetMessage (&msg, NULL, 0, 0)) { TranslateMessage (&msg); DispatchMessage (&msg); } return msg.wParam; } 出自:游戏编程中的人工智能技术

你可能感兴趣的:(游戏,技术,职场,人工智能,休闲)