GDI+绘制简单图形
#include <windows.h>
#include <gdiplus.h>
using namespace Gdiplus;
#pragma comment(lib, "gdiplus.lib")
VOID OnPaint(HDC hdc) {
Graphics graphics(hdc);
Pen pen(Color(255, 0, 0, 255));
FontFamily fontFamily(L"宋体");
Font font(&fontFamily, 12, FontStyleRegular, UnitPixel);
PointF pointF1(30.0f, 60.0f),pointF2(230.0f, 60.0f);
SolidBrush solidBrush(Color(255, 0, 0, 255));
StringFormat stringFormat;
WCHAR testString[] = L"Hello034∠你好";
stringFormat.SetFormatFlags(StringFormatFlagsDirectionVertical);
graphics.SetSmoothingMode(SmoothingModeDefault);
graphics.DrawLine(&pen, 0, 0, 200, 100);
graphics.DrawEllipse(&pen, 10, 10, 190, 90);
graphics.SetTextRenderingHint(TextRenderingHintSystemDefault);
graphics.DrawString(testString, -1, &font, pointF1, &stringFormat, &solidBrush);
graphics.SetSmoothingMode(SmoothingModeHighQuality);
graphics.DrawLine(&pen, 200, 0, 400, 100);
graphics.DrawEllipse(&pen, 210, 10, 190, 90);
graphics.SetTextRenderingHint(TextRenderingHintAntiAlias);
graphics.DrawString(testString, -1, &font, pointF2, &stringFormat, &solidBrush);
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
HDC hdc;
PAINTSTRUCT ps;
switch(message) {
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
OnPaint(hdc);
EndPaint(hWnd, &ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
}
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, PSTR, INT iCmdShow) {
HWND hWnd;
MSG msg;
WNDCLASS wndClass;
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
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("GettingStarted");
RegisterClass(&wndClass);
hWnd = CreateWindow(
TEXT("GettingStarted"), // window class name
TEXT("Getting Started"), // 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 0;
}
GDI+绘制简单图形的更多相关文章
- 学习笔记:HTML5 Canvas绘制简单图形
HTML5 Canvas绘制简单图形 1.添加Canvas标签,添加id供js操作. <canvas id="mycanvas" height="700" ...
- Java入门:绘制简单图形
在上一节,我们学习了如何使用swing和awt工具创建一个空的窗口,本节学习如何绘制简单图形. 基本绘图介绍 Java中绘制基本图形,可以使用Java类库中的Graphics类,此类位于java.aw ...
- CSS绘制简单图形
究竟该用字体图标.图片图标.还是CSS画一个图标?我也不知道.各有千秋吧.本文将介绍如何用css绘制简单的图形,所有测试在chrome58.0完成,如果你不能得到正确结果请到caniuse查一查看看是 ...
- Windows控制台下绘制简单图形
最近接触到一个很有意思的问题,如何在Windows控制台下画图,翻遍了C的头文件也没找到画图的函数,好吧,那就用Windows提供的API函数吧,看来想移植是没戏了.先画一个简单的图,类似心电图那种吧 ...
- shape-自绘制简单图形
shape 可以绘制简单的图形,颜色等.它主要就是应用于selector 的一些状态. 本文内容参考自http://www.cnblogs.com/cyanfei/archive/2012/07/27 ...
- 在高德地图上用svg.js绘制简单图形
这段时间做的一个项目,需要在地图上绘制简单的图形.在学习高德地图JS API的过程中,发现高德地图提供的点.线等API并不能满足我的需求,还好它开放了自定义图层CustomLayer,官方说自定义图层 ...
- 利用 turtle库绘制简单图形
turtle库是python的基础绘图库,这个库被介绍为一个最常用的用来介绍编程知识的方法库,其主要是用于程序设计入门,是标准库之一,利用turtle可以制作很多复杂的绘图. turtle名称含义为“ ...
- Quartz 2D绘制简单图形
在Quartz 2D中,绘图是通过图形上下文进行绘制的,以下绘制几个简单的图形 首先先创建一个QuartzView.swift文件继承自UIView,然后实现drawRect方法: import UI ...
- Golang 绘图基础 -绘制简单图形
前一节讲的是 绘图到不同输出源,请看地址: http://www.cnblogs.com/ghj1976/p/3440856.html 上一节的例子效果是通过设置每一个点的的RGBA属性来实现的,这是 ...
随机推荐
- java获取指定文件夹下的所有文件名
package com.henu.util; import java.io.File; public class TakeFilePathAndName { public static void ma ...
- 图片文字OCR识别-tesseract-ocr
帮助文件:https://github.com/tesseract-ocr/tesseract/blob/master/doc/tesseract.1.asc 下载地址:https://github. ...
- POJ 2488 A Knight's Journey
A Knight's Journey Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 29226 Accepted: 10 ...
- GO语言基础之interface
接口interface 1. 接口是一个或多个方法签名的集合 2. 只要某个类型拥有该接口的所有方法签名,即算实现该接口,无需显示声明实现了哪个接口,这称为 Structural typing 3. ...
- Unity3d---> IEnumerator
Unity3d---> IEnumerator 2013-04-18 10:24 2162人阅读 评论(0) 收藏 举报 Unity3dc# using UnityEngine; using S ...
- Effective C++ 条款27
尽量少做转型动作 尽量少做转型动作有什么目的?非常明显无非就是提高程序的稳定性.提高程序的运行效率. 那么.有哪些转型方式?每种方式都有什么弱点? 这是我们本节学习的重点. C++有四种转型: con ...
- 微信小程序:字体保持大小
小程序和网页差不多,前台用wxml把内容摆好,然后用css调整样式.所以和web一样,必须要能够精确控制每一个元素的大小.在Web中,通过CSS基本达到了像素级的控制.但在小程序中,情况有所不同.下面 ...
- Jmeter-Maven-Plugin高级应用:Log Levels
Log Levels Pages 12 Home Adding additional libraries to the classpath Advanced Configuration Basic C ...
- SqlServer 之 系统视图
一.了解系统视图 1. 系统视图:从名字上看就知道,就是存放一些sqlserver系统的一些信息. 2. 存在位置: 下面截图看看,从截图中你可以看到,不管是“系统数据库”还是“用户数据库”都是有这些 ...
- Failed to fetch URL https://dl-ssl.google.com/android/repository/repository-6.xml, reason: Connection to https://dl-ssl.google.com refused
修改hosts文件.文件在C:\WINDOWS\system32\drivers\etc目录下,Linux用户打开/etc/hosts文件.用记事本打开文件后添加以下内容. #Google主页203. ...