写了一个小东西,大家看看~~
恩,姐姐的计算机图形学要求写的,不过已经过时了~~~所以只能算是我自己写着玩玩~~其实只是主要拿这个小东西试验一下我VIM的编译脚本而已~
要是不能运行或者有Bug帮忙提一下,谢谢~~~
windmill.rar
(7.7 KB)
想要源代码的提一下,我再上传,等我的VIM+GCC弄好了也会上传那个的。不准备往里面加VC6了,不实用。
#define _WIN32_WINNT 0x0501 #include <Windows.h> #include <assert.h> #include <math.h> #define RAD 100 #define PI 3.14159265359 char *strClassName = "My Class"; HDC hDCMemory; HBRUSH color_brush[4]; void CreateResources() { int i; HDC hDCDisplay; COLORREF colors[] = { RGB(255, 0, 0), RGB(255, 255, 0), RGB(0, 255, 0), RGB(0, 0, 255) }; for (i = 0; i < 4; i++) color_brush[i] = CreateSolidBrush(colors[i]); hDCDisplay = GetDC(NULL); hDCMemory = CreateCompatibleDC(hDCDisplay); SelectObject(hDCMemory, (HGDIOBJ)CreateCompatibleBitmap(hDCDisplay, RAD * 2, RAD * 2)); ReleaseDC(NULL, hDCDisplay); } void ClearResources() { int i; for (i = 0; i < 4; i++) DeleteObject((HGDIOBJ)color_brush[i]); DeleteObject(GetCurrentObject(hDCMemory, OBJ_BITMAP)); DeleteDC(hDCMemory); } void SetClientSize(HWND hWnd, int width, int height) { RECT wndRect, cntRect; GetWindowRect(hWnd, &wndRect); GetClientRect(hWnd, &cntRect); InflateRect(&wndRect, (width - cntRect.right) / 2, (height - cntRect.bottom) / 2); SetWindowPos(hWnd, NULL, 0, 0, wndRect.right - wndRect.left, wndRect.bottom - wndRect.top, SWP_NOZORDER | SWP_NOMOVE); } void DrawWindmill(HDC hdc, double angle) { int i; RECT rect = {0, 0, RAD * 2, RAD * 2}; HGDIOBJ old_pen = SelectObject(hdc, GetStockObject(NULL_PEN)); HGDIOBJ old_brush = GetCurrentObject(hdc, OBJ_BRUSH); FillRect(hdc, &rect, GetStockObject(WHITE_BRUSH)); for (i = 0; i < 4; i++, angle += PI / 2) { SelectObject(hdc, color_brush[i]); Chord(hdc, RAD * (cos(angle) + 1) / 2, RAD * (sin(angle) + 1) / 2, RAD * (cos(angle) + 3) / 2, RAD * (sin(angle) + 3) / 2, RAD * (cos(angle) + 1), RAD * (sin(angle) + 1), RAD, RAD); } SelectObject(hdc, old_brush); SelectObject(hdc, old_pen); } LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { static float angle = 0; HDC hdc; PAINTSTRUCT ps; switch (uMsg) { case WM_ERASEBKGND: return 0; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); DrawWindmill(hDCMemory, angle); BitBlt(hdc, 0, 0, RAD * 2, RAD * 2, hDCMemory, 0, 0, SRCCOPY); EndPaint(hWnd, &ps); break; case WM_LBUTTONDOWN: uMsg = WM_NCLBUTTONDOWN; break; case WM_TIMER: angle += PI / 180; if (angle >= PI * 2) angle = 0; InvalidateRect(hWnd, NULL, TRUE); break; case WM_SIZE: SetClientSize(hWnd, RAD * 2, RAD * 2); break; case WM_CREATE: RegisterHotKey(hWnd, 0x1234, MOD_WIN, VK_F12); CreateResources(); SetTimer(hWnd, 1, 10, NULL); break; case WM_HOTKEY: case WM_DESTROY: UnregisterHotKey(hWnd, 0x1234); ClearResources(); PostQuitMessage(0); break; } return DefWindowProc(hWnd, uMsg, wParam, lParam); } int CALLBACK WinMain(HINSTANCE hInst, HINSTANCE hPreInst, LPSTR strCmdLine, int nCmdShow) { MSG msg; HWND hWnd; WNDCLASS wc = {CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS, WndProc, 0, 0, hInst, LoadIcon(NULL, IDI_APPLICATION), LoadCursor(NULL, IDC_ARROW), (HBRUSH)GetStockObject(WHITE_BRUSH), NULL, strClassName }; RegisterClass(&wc); hWnd = CreateWindowEx(WS_EX_LAYERED | WS_EX_TOPMOST | WS_EX_TRANSPARENT | WS_EX_TOOLWINDOW, strClassName, "My Window", WS_POPUP, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL, hInst, NULL); SetLayeredWindowAttributes(hWnd, RGB(255, 255, 255), 128, LWA_COLORKEY | LWA_ALPHA); ShowWindow(hWnd, nCmdShow); while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } /* cc_flags = -mwindows */ // 这一行是为了VIM自动添加编译选项