#include #include #include #pragma comment (lib,"Gdiplus.lib") using namespace Gdiplus; VOID OnPaint(HDC hdc, int direction) { Graphics graphics(hdc); Color Orange(255, 255, 165, 0); SolidBrush brush(Orange); Pen pen(&brush); PointF offset(0.0f, 0.0f); SizeF size(20.0f, 20.0f); switch (direction) { case 1 : offset.X = -20.0f; MessageBox(NULL, "1", NULL, MB_OK); break; case 2 : offset.X = 20.0f; MessageBox(NULL, "2", NULL, MB_OK); break; case 3 : offset.Y = -20.0f; MessageBox(NULL, "3", NULL, MB_OK); break; case 4 : offset.Y = 20.0f; MessageBox(NULL, "4", NULL, MB_OK); break; case 0 : MessageBox(NULL, "0", NULL, MB_OK); } RectF snake(offset, size); graphics.DrawEllipse(&pen, snake); } LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, PSTR, INT iCmdShow) { HWND hWnd; MSG msg; WNDCLASS wndClass; GdiplusStartupInput gdiplusStartupInput; ULONG_PTR gdiplusToken; // Initialize GDI+. GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); 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; wndClass.lpszClassName = TEXT("GraphicsWithGDIPlus"); RegisterClass(&wndClass); hWnd = CreateWindow( TEXT("GraphicsWithGDIPlus"), // window class name TEXT("Graphics with GDI+"), // window caption WS_CAPTION|WS_SYSMENU, // window style 100, // initial x position 100, // initial y position 500, // initial x size 500, // initial y size NULL, // parent window handle NULL, // window menu handle hInstance, // program instance handle NULL); // creation parameters ShowWindow(hWnd, iCmdShow); UpdateWindow(hWnd); LRESULT lr; while(GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); lr = DispatchMessage(&msg); if ( lr == 1 ) { RedrawWindow(hWnd, 0, 0, RDW_INVALIDATE); MessageBox(NULL, "rw", NULL, MB_OK); } } GdiplusShutdown(gdiplusToken); return msg.wParam; } // WinMain LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; static int dir = 0; switch(message) { case WM_KEYDOWN : switch ( wParam ) { case VK_LEFT : dir = 1; break; case VK_RIGHT : dir = 2; break; case VK_UP : dir = 3; break; case VK_DOWN : dir = 4; break; } MessageBox(NULL, "key", NULL, MB_OK); return 1; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); OnPaint(hdc, dir); EndPaint(hWnd, &ps); return 0; case WM_DESTROY: PostQuitMessage(0); return 0; default: return DefWindowProc(hWnd, message, wParam, lParam); } } // WndProc