SendMessage会跳过不执行....
#include <Windows.h>#define CellSize 15#define Width 20#define Height 30LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, LPSTR szCmdLine, int iCmdShow){ static TCHAR szAppName[] = TEXT("Tetris"); WNDCLASS wndclass; HWND hwnd; MSG msg; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); wndclass.hCursor = LoadCursor(hInstance, IDC_ARROW); wndclass.hIcon = LoadIcon(hInstance, IDI_APPLICATION); wndclass.hInstance = hInstance; wndclass.lpfnWndProc = WndProc; wndclass.lpszClassName = szAppName; wndclass.lpszMenuName = NULL; wndclass.style = CS_HREDRAW | CS_VREDRAW; if(!RegisterClass(&wndclass)) { MessageBox(NULL, TEXT("The programe requires Windows NT!"), szAppName, MB_ICONERROR); return 0; } hwnd = CreateWindow(szAppName, TEXT("Tetris Game"), WS_OVERLAPPEDWINDOW, (GetSystemMetrics(SM_CXSCREEN) - Width * CellSize) / 2, (GetSystemMetrics(SM_CYSCREEN) - Height * CellSize) / 2, Width * CellSize, Height * CellSize, NULL, NULL, hInstance, NULL); ShowWindow(hwnd, iCmdShow); UpdateWindow(hwnd); 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 i; //HPEN hPen; switch(message) { case WM_CREATE: i = 0; return 0; case WM_KEYDOWN: switch(wParam) { case VK_RIGHT: i++; break; } SendMessage(hwnd, WM_PAINT, 0, 0); //SendMessage会跳过不执行 return 0; case WM_PAINT: hdc = BeginPaint(hwnd, &ps); GetClientRect(hwnd, &rect); TextOut(hdc, i, 0 , TEXT("abc"), lstrlen(TEXT("abc"))); EndPaint(hwnd, &ps); return 0; case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hwnd, message, wParam, lParam);}