vc++七彩气球
时间: 2023-08-24 10:03:50 浏览: 88
如果你想在VC++中实现七彩气球,你可以使用GDI+来绘制图形。下面是一个简单的例子,可以在窗体上绘制一个七彩气球:
```cpp
#include <windows.h>
#include <gdiplus.h>
#pragma comment(lib, "gdiplus.lib")
using namespace Gdiplus;
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
WNDCLASS wc = { 0 };
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.lpszClassName = L"WindowClass";
RegisterClass(&wc);
HWND hwnd = CreateWindow(L"WindowClass", L"七彩气球", WS_OVERLAPPEDWINDOW, 100, 100, 500, 500, NULL, NULL, hInstance, NULL);
if (hwnd == NULL)
return 0;
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
MSG msg = { 0 };
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
GdiplusShutdown(gdiplusToken);
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
Graphics graphics(hdc);
SolidBrush brush(Color::Red);
graphics.FillEllipse(&brush, 200, 200, 100, 100);
brush.SetColor(Color::Orange);
graphics.FillEllipse(&brush, 220, 220, 60, 60);
brush.SetColor(Color::Yellow);
graphics.FillEllipse(&brush, 240, 240, 20, 20);
brush.SetColor(Color::Green);
graphics.FillEllipse(&brush, 244, 244, 12, 12);
brush.SetColor(Color::Blue);
graphics.FillEllipse(&brush, 248, 248, 6, 6);
brush.SetColor(Color::Purple);
graphics.FillEllipse(&brush, 250, 250, 2, 2);
EndPaint(hwnd, &ps);
break;
}
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
```
这个例子使用了GDI+中的Graphics类和SolidBrush类来绘制七个不同颜色的圆形,从而形成了一个七彩气球的效果。
阅读全文