- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
绘制简单矩形(国外英文资料)
绘制简单矩形(国外英文资料)
Draw simple rectangles
To draw a rectangle with GDI, you can process the WM_PAINT message, as shown in the code below.
Switch (message)
{
Case WM_PAINT:
{
PAINTSTRUCT ps;
BeginPaint (hWnd, ps);
Obtain the size of the drawing / / area.
RECT rc;
GetClientRect (
Hwnd,
rc
);
The original object / / Save
HGDIOBJ original = NULL;
Original = SelectObject
Ps.hdc,
GetStockObject (DC_PEN)
);
A pen. / / Create
HPEN blackPen = CreatePen (PS_SOLID, 3, 0);
The pen. / / Select
SelectObject (ps.hdc, blackPen);
A rectangle. / / Draw
Rectangle (
Ps.hdc,
Rc.left + 100,
Rc.top + 100,
Rc.right - 100,
Rc.bottom - 100);
DeleteObject (blackPen);
The original object / / Restore
SelectObject (ps.hdc, original);
EndPaint (hWnd, ps);
}
Return 0;
For handling other messages. / / Code
The code for drawing the rectangle with Direct2D is similar: it creates drawing resources, illustrates the shapes to be drawn, draws the shapes, and then releases the drawing resources. The following sections describe each of these steps in detail.
Step 1: include the Direct2D header file
In addition to the header files required by the Win32 application, the d2d1.h header file is included.
Step 2: create ID2D1Factory
All the Direct2D samples have to do some of the tasks first, and one of them is to create ID2D1Factory
ID2D1Factory* pD2DFactory = NULL;
HRESULT HR = D2D1CreateFactory
D2D1_FACTORY_TYPE_SINGLE_THREADED,
pD2DFactory
);
The ID2D1Factory interface is the starting point for using Direct2D; ID2D1Factory can be used to create Direct2D resources.
When you build a factory, you can specify whether it is multithreaded or single threaded. For more information about multithreaded factories, see the notes on the ID2D1Factory reference page This example creates a single threaded factory.
In general, the application should create a factory and keep it in the life cycle of the application.
Step 3: create ID2D1HwndRenderTarget
When you create a factory, use it to create a renderer target.
Obtain the siz
文档评论(0)