#include#include using namespace Gdiplus; #pragma comment(lib, "Gdiplus.lib") LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); VOID AddExample(HDC hdc); 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("GDIPlus Test"); RegisterClass(&wndClass); hWnd = CreateWindow( TEXT("GDIPlus Test"), // window class name TEXT("GDIPlus Test"), // 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 ShowWindow(hWnd, iCmdShow); UpdateWindow(hWnd); while(GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } GdiplusShutdown(gdiplusToken); return msg.wParam; } // WinMain LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; switch(message) { case WM_PAINT: hdc = BeginPaint(hWnd, &ps); AddExample(hdc); EndPaint(hWnd, &ps); return 0; case WM_DESTROY: PostQuitMessage(0); return 0; default: return DefWindowProc(hWnd, message, wParam, lParam); } } // WndProc VOID AddExample(HDC hdc) { Graphics graphics(hdc); Pen pen(Color(255, 0, 0, 255)); PenGreenPen(Color(255, 123, 255, 0), 10); GreenPen.SetAlignment(PenAlignmentInset); // 直线 graphics.DrawLine(&GreenPen, 50, 80, 50, 300); graphics.DrawLine(&pen, 50, 80, 50, 300); // 文字 SolidBrush brush(Color(255, 0, 0, 255)); FontFamily fontFamily(L"Times New Roman"); Font font(&fontFamily, 24, FontStyleRegular, UnitPixel); PointF pointF(10.0f, 20.0f); graphics.DrawString(L"Hello World!", -1, &font, pointF, &brush); // 矩形 pen.SetWidth(5); graphics.DrawRectangle(&pen, 20, 20, 300, 200); graphics.DrawRectangle(&GreenPen, 20, 20, 300, 200); // 带标志的直线 pen.SetEndCap(LineCapArrowAnchor); pen.SetStartCap(LineCapRoundAnchor); graphics.DrawLine(&pen, 100, 100, 300, 100); // Joining lines GraphicsPath path; Pen penJoin(Color(255, 0, 0, 255), 8); path.StartFigure(); path.AddLine(Point(50, 200), Point(100, 200)); path.AddLine(Point(100, 200), Point(100, 250)); penJoin.SetLineJoin(LineJoinMiter); // LineJoin: Bevel, Round, MiterClipped graphics.DrawPath(&penJoin, &path); // 虚线 pen.SetDashStyle(DashStyleDash); // DashStyle: Solid, Dot, DashDot, DashDotDot, Custom pen.SetWidth(1); graphics.DrawRectangle(&pen, 300, 200, 400, 500); REAL dashValues[4] = {5, 2, 15, 4}; pen.SetDashPattern(dashValues, 4); pen.SetWidth(5); graphics.DrawLine(&pen, Point(250, 60), Point(300, 220)); //线条填充 Image image(L"Logo1.gif"); TextureBrush tBrush(&image); Pen texturedPen(&tBrush, 30); graphics.DrawImage(&image, 310, 300, image.GetWidth(), image.GetHeight()); graphics.DrawEllipse(&texturedPen, 210, 20, 200, 100); ////////////////////////////////////////////////////////////////////////// // GraphicsPath.AddArc(); path.CloseFigure(); path.StartFigure(); path.AddArc(100, 200, 100, 100, 0.0, 360.0); path.AddArc(200, 300, 100, 100, 0.0, 360.0); path.CloseFigure(); graphics.DrawPath(&pen, &path); // GraphicsPath.AddBezier(); pen.SetDashStyle(DashStyleSolid); pen.SetStartCap(LineCapNoAnchor); pen.SetEndCap(LineCapNoAnchor); pen.SetWidth(1); path.AddBezier(Point(300,30), Point(400, 80), Point(420, 300), Point(460,460)); path.CloseFigure(); graphics.DrawPath(&pen, &path); // GraphicsPath.AddBeziers() Point pts[] = {Point(50,50), Point(60,20), Point(70,100), Point(80,50), Point(120,40), Point(150,80), Point(170,30)}; path.AddBeziers(pts, 7); path.CloseFigure(); graphics.DrawPath(&pen, &path); PointF ptsf[] = {PointF(150.0f,50.0f), PointF(160.0f,20.0f), PointF(170.0f,100.0f), PointF(180.0f,50.0f), PointF(220.0f,40.0f), PointF(250.0f,80.0f), PointF(270.0f,30.0f)}; path.AddBeziers(ptsf, 7); path.CloseFigure(); graphics.DrawPath(&pen, &path); // GraphicsPath.AddClosedCurve(); PointF ptscf[] = {PointF(450.0f,150.0f), PointF(460.0f,120.0f), PointF(470.0f,100.0f), PointF(480.0f,150.0f)}; path.AddClosedCurve(ptscf, 4, 1.4f); path.CloseFigure(); graphics.DrawPath(&pen, &path); // GraphicsPath.AddCurve(); PointF ptc[] = {PointF(450.0f, 50.0f), PointF(470.0f, 80.0f), PointF(400.0f, 100.0f), PointF(430.0f, 40.0f), PointF(450.0f, 90.0f), PointF(480.0f, 30.0f), PointF(410.0f, 120.0f), PointF(440.0f, 80.0f)}; path.AddCurve( ptc, 8, // There are eight points in the array. 2, // Start at the point with index 2. 4, // Four segments. End at the point with index 6. 1.0f); path.CloseFigure(); graphics.DrawPath(&pen, &path); //GraphicsPath.AddPie(); path.AddPie(300.0f, 300.0f, 400.0f, 400.0f, 0.0f, 270.0f); path.CloseFigure(); graphics.DrawPath(&pen, &path); }
欢迎光临 黑色海岸线论坛 (http://bbs.thysea.com/) | Powered by Discuz! 7.2 |