| CODE |
#include <windows.h> LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { static TCHAR szAppName[] = TEXT ("GAMEWIN"); static TCHAR szSecAppName[] = TEXT ("STATD"); HWND hwnd; HWND hwnds; MSG msg; WNDCLASS wndclass; HWND hMenu; wndclass.style = CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc = WndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance; wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION); wndclass.hCursor = LoadCursor (NULL, IDC_ARROW); wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH); wndclass.lpszMenuName = szAppName; wndclass.lpszClassName = szAppName; if (!RegisterClass (&wndclass)) { MessageBox (NULL, TEXT ("This program requires Windows NT!"), szAppName, MB_ICONERROR); return 0; } hwnd = CreateWindow (szAppName, // window class name TEXT ("The Game"), // window caption WS_OVERLAPPEDWINDOW, // window style CW_USEDEFAULT, // initial x position CW_USEDEFAULT, // initial y position CW_USEDEFAULT, // initial x size CW_USEDEFAULT, // initial y size NULL, // parent window handle NULL, // window menu handle hInstance, // program instance handle NULL); // creation parameters hwnds = CreateWindow ( szSecAppName, TEXT("STATS"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 150, 480, hwnd, NULL, NULL, NULL); ShowWindow (hwnd, iCmdShow); UpdateWindow (hwnd); ShowWindow(hwnds,iCmdShow); UpdateWindow(hwnds); while (GetMessage (&msg, NULL, 0, 0)) { TranslateMessage (&msg); DispatchMessage (&msg); } return msg.wParam; } LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; RECT rect; static int xx=100; static int yy=100; switch (message) { case WM_CREATE: return 0; break; case WM_KEYDOWN: switch (wParam) { case VK_UP: yy-=3; InvalidateRect(hwnd, NULL, true); break; case VK_DOWN: yy+=3; InvalidateRect(hwnd, NULL, true); break; case VK_LEFT: xx-=3; InvalidateRect(hwnd, NULL, true); break; case VK_RIGHT: xx+=3; InvalidateRect(hwnd, NULL, true); break; case VK_ESCAPE: PostQuitMessage (0); break; return 0; } case WM_PAINT: hdc = BeginPaint (hwnd, &ps); MoveToEx(hdc, xx, yy, NULL); LineTo(hdc, xx+5, yy); MoveToEx(hdc, xx+5, yy, NULL); LineTo(hdc, xx+5, yy+5); MoveToEx(hdc, xx+5, yy+5, NULL); LineTo(hdc, xx, yy+5); MoveToEx(hdc, xx, yy+5, NULL); LineTo(hdc, xx, yy); EndPaint (hwnd, &ps); return 0; case WM_DESTROY: PostQuitMessage (0); return 0; } return DefWindowProc (hwnd, message, wParam, lParam); } |
| CODE |
wndclass.lpszMenuName = szAppName; wndclass.lpszClassName = szAppName; |
| CODE |
#include <windows.h> LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { static TCHAR szAppName[] = TEXT ("GAMEWIN"); // omitted: static TCHAR szSecAppName[] = TEXT ("STATD"); HWND hwnd; HWND hwnds; MSG msg; WNDCLASS wndclass; HWND hMenu; wndclass.style = CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc = WndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance; wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION); wndclass.hCursor = LoadCursor (NULL, IDC_ARROW); wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH); wndclass.lpszMenuName = NULL; // was szAppName; see Joel's message wndclass.lpszClassName = szAppName; if (!RegisterClass (&wndclass)) { MessageBox (NULL, TEXT ("This program requires Windows NT!"), szAppName, MB_ICONERROR); return 0; } hwnd = CreateWindow (szAppName, TEXT ("The Game"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); // creation parameters hwnds = CreateWindow ( szAppName, // was: szSecAppName TEXT("STATS"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 150, 480, hwnd, NULL, NULL, NULL); ShowWindow (hwnd, iCmdShow); UpdateWindow (hwnd); ShowWindow(hwnds,iCmdShow); UpdateWindow(hwnds); while (GetMessage (&msg, NULL, 0, 0)) { TranslateMessage (&msg); DispatchMessage (&msg); } return msg.wParam; } LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; RECT rect; static int xx=100; static int yy=100; switch (message) { case WM_CREATE: return 0; break; case WM_KEYDOWN: switch (wParam) { case VK_UP: yy-=3; InvalidateRect(hwnd, NULL, true); break; case VK_DOWN: yy+=3; InvalidateRect(hwnd, NULL, true); break; case VK_LEFT: xx-=3; InvalidateRect(hwnd, NULL, true); break; case VK_RIGHT: xx+=3; InvalidateRect(hwnd, NULL, true); break; case VK_ESCAPE: PostQuitMessage (0); break; return 0; } case WM_PAINT: hdc = BeginPaint (hwnd, &ps); MoveToEx(hdc, xx, yy, NULL); LineTo(hdc, xx+5, yy); MoveToEx(hdc, xx+5, yy, NULL); LineTo(hdc, xx+5, yy+5); MoveToEx(hdc, xx+5, yy+5, NULL); LineTo(hdc, xx, yy+5); MoveToEx(hdc, xx, yy+5, NULL); LineTo(hdc, xx, yy); EndPaint (hwnd, &ps); return 0; case WM_DESTROY: PostQuitMessage (0); return 0; } return DefWindowProc (hwnd, message, wParam, lParam); } |