原文:Direct2D 第2篇 绘制椭圆

#include <windows.h>
#include <d2d1.h>
#include <d2d1helper.h>
#include <dwrite.h>
#pragma comment(lib, "dwrite.lib")
#pragma comment(lib, "d2d1.lib") HINSTANCE g_hinst;
HWND g_hwnd; ID2D1Factory * g_factory;
ID2D1HwndRenderTarget * g_render_target;
ID2D1SolidColorBrush * g_brush; void OnSize(LPARAM lparam)
{
if(g_render_target)
g_render_target->Resize(D2D1::SizeU(LOWORD(lparam),HIWORD(lparam)));
} bool AppInit()
{
D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &g_factory); RECT rc;
GetClientRect(g_hwnd, &rc); g_factory->CreateHwndRenderTarget(
D2D1::RenderTargetProperties(),
D2D1::HwndRenderTargetProperties(g_hwnd, D2D1::SizeU(rc.right - rc.left, rc.bottom - rc.top) ),
&g_render_target); g_render_target->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::ForestGreen), &g_brush); return true;
} void OnPaint()
{
if(!g_render_target)
return; g_render_target->BeginDraw(); // Clear Background
g_render_target->Clear(D2D1::ColorF(0.63, 0.84, 0.00)); // Draw Ellipse
D2D1_SIZE_F size = g_render_target->GetSize();
D2D1_ELLIPSE ellipse; ellipse.point = D2D1::Point2F(size.width/2.0, size.height/2.0);
ellipse.radiusX = 200;
ellipse.radiusY =100;
g_render_target->FillEllipse(&ellipse, g_brush);//绘制图形 g_render_target->EndDraw();
} void OnDestroy()
{
g_brush->Release();
g_render_target->Release();
g_factory->Release();
} LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
switch(msg)
{
case WM_PAINT:
OnPaint();
break; case WM_SIZE:
OnSize(lparam);
break; case WM_DESTROY:
OnDestroy();
PostQuitMessage(0);
break; default:
return DefWindowProc(hwnd, msg, wparam, lparam);
}
return 0;
} int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
MSG msg; memset(&wc,0,sizeof(wc));
wc.cbSize = sizeof(WNDCLASSEX);
wc.lpfnWndProc = WndProc;
wc.hInstance = hinst;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszClassName = "WindowClass";
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Window Registration Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
return 0;
} g_hinst = hinst; g_hwnd = CreateWindowEx(WS_EX_CLIENTEDGE,"WindowClass","Direct2D Demo",WS_VISIBLE|WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
640,
480,
NULL, NULL, hinst, NULL); if(g_hwnd == NULL)
{
MessageBox(NULL, "Window Creation Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
return 0;
} if(!AppInit())
{
MessageBox(NULL, "Application Initialisation Failed !","Error",MB_ICONEXCLAMATION|MB_OK);
return 0;
} while(GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
} return msg.wParam;
}

Direct2D 第2篇 绘制椭圆的更多相关文章

  1. Direct2D 第6篇 绘制多种风格的线条

    原文:Direct2D 第6篇 绘制多种风格的线条 上图是使用Direct2D绘制的线条,Direct2D在效率上比GDI/GDI+要快几倍,GDI/GDI+绘图是出了名的"慢", ...

  2. Direct2D 第5篇 绘制图像

    原文:Direct2D 第5篇 绘制图像 我加载的图像是一张透明底PNG图像,背景使用渐变的绿色画刷 #include <windows.h> #include <d2d1.h> ...

  3. Direct2D 第3篇 绘制文字

    原文:Direct2D 第3篇 绘制文字 #include <windows.h> #include <d2d1.h> #include <d2d1helper.h> ...

  4. 如何使用canvas绘制椭圆,扩展非chrome浏览器中的ellipse方法

    这篇博文主要针对浏览器中绘制椭圆的方法扩展.在网上搜索了很多,发现他们绘制椭圆的方式都有缺陷.其中有压缩法,计算法,贝塞尔曲线法等多种方式.但是都不能很好的绘制出椭圆.所有我就对这个绘制椭圆的方式进行 ...

  5. asp.net GDI+ 绘制椭圆 ,弧线,扇形

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

  6. HTML5 Canvas中绘制椭圆的几种方法

    1.canvas自带的绘制椭圆的方法 ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise)是后来 ...

  7. CAD参数绘制椭圆(com接口)

    在CAD设计时,需要绘制椭圆,用户可以设置椭圆的基本属性. 主要用到函数说明: _DMxDrawX::DrawEllipse 绘制椭圆.详细说明如下: 参数 说明 DOUBLE dCenterX 椭圆 ...

  8. CAD参数绘制椭圆(网页版)

    在CAD设计时,需要绘制椭圆,用户可以设置椭圆的基本属性. 主要用到函数说明: _DMxDrawX::DrawEllipse 绘制椭圆.详细说明如下: 参数 说明 DOUBLE dCenterX 椭圆 ...

  9. Direct2D 第4篇 渐变画刷

    原文:Direct2D 第4篇 渐变画刷 #include <windows.h> #include <d2d1.h> #include <d2d1helper.h> ...

随机推荐

  1. jquery移除元素某个属性

    removeAttr() 方法从被选元素中移除属性. 例如:$("p").removeAttr("style");

  2. Node中js获取异步操作的结果

    js中要获取异步操作的结果必须使用回调函数 回调函数也被称为高阶函数,简单来说就是,函数作为一个参数传到另一个主函数里面,当那一个主函数执行完之后,再执行传进去的作为参数的函数 function fn ...

  3. hadoop2.x 完全分布式详细集群搭建(图文:4台机器)

    在准备之前说一下本次搭建的各节点角色,进程. nameNode 进程:NameNode dataNode  进程:DataNode resourceManager :ResourceManager n ...

  4. js日期格式化Date

    使用Date类进行日期格式化. 1 输入“yyyy-MM-dd hh:mm:ss”格式的String字符串,返回字符串 做一个简单判定,在当日显示为几点几分,同年为月日,不同年显示年月 functio ...

  5. tensorflow/models 下面的data_augment_options的random_image_scale

    这个random_image_scale应该是改变整个图片的大小,而不是“box”图片的大小

  6. Ionic跳转到外网地址

    1.安装插件 https://github.com/apache/cordova-plugin-inappbrowser 执行命令:cordova plugin add org.apache.cord ...

  7. 如何设置td中溢出内容的隐藏显示

    <style type="text/css"> table { table-layout:fixed; } td { overflow:hidden; word-bre ...

  8. springboot核心技术(二)-----自动配置原理、日志

    自动配置原理 配置文件能配置的属性参照 1.自动配置原理: 1).SpringBoot启动的时候加载主配置类,开启了自动配置功能 @EnableAutoConfiguration 2).@Enable ...

  9. CentOS安装Eclipse luna

    1  解压 Eclipse luna到/opt tar -zxvf eclipse-java-luna-SR1-linux-gtk-x86_64.tar.gz -C /opt 2  创建软链接 ln ...

  10. 左神算法书籍《程序员代码面试指南》——1_10最大值减去最小值小于或等于num的子数组数量

    [题目]给定数组arr和整数num,共返回有多少个子数组满足如下情况:max(arr[i.j]) - min(arr[i.j]) <= num max(arfi.j])表示子数组ar[ij]中的 ...