在win32 API程序中,设备上下文是什么?它如何工作? [英] In win32 API program ,the device context is what?how it works?

查看:197
本文介绍了在win32 API程序中,设备上下文是什么?它如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

就像这个函数一样,注释处的问题:

Just like as this function,the question at the annotate:

LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM IParam){
	HDC hdc; //what's the hdc,how it works?
	PAINTSTRUCT ps;
	RECT rect;
	switch(message){
	case WM_CREATE:
		PlaySound(TEXT("hellowin,wav"),NULL,SND_FILENAME|SND_ASYNC);
		return 0;
	case WM_PAINT:
		hdc = BeginPaint(hwnd,&ps);
		GetClientRect(hwnd,&rect);
		DrawText(hdc,TEXT("Hello,Windows 98!"),-1,&rect,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
		EndPaint(hwnd,&ps);
		return 0;
	case WM_DESTROY:
		PostQuitMessage(0);
		return 0;
	}
	return DefWindowProc(hwnd,message,wParam,IParam);
}

推荐答案

设备上下文概念来自Windows的GDI(图形设备接口). GDI的目标是创建独立于计算机上安装的硬件的绘图工具,以简化开发人员绘制屏幕和对象的任务.设备上下文有点抽象,但是您可以将其视为绘图的平台(以及绘图工具).

以下是有关此主题的更多信息:
http://msdn.microsoft.com/en-us/library/dd162467%28v = VS.85%29.aspx [ ^ ]
http://www.functionx.com/win32/Lesson09.htm [ http://www.codingconvention.com/tutorials/Win32-Drawing [ http://www.winprog.org/tutorial/bitmaps.html [
The device context idea comes from Windows'' GDI (graphics device interface). The goal of GDI is to create a drawing tool independent of the hardware installed on the computer, to simplify a developers task of drawing screens and objects. A device context is somewhat abstract, but you can think of it as your platform for drawing (along with the tools for drawing).

Here''s some more information on the subject:
http://msdn.microsoft.com/en-us/library/dd162467%28v=VS.85%29.aspx[^]
http://www.functionx.com/win32/Lesson09.htm[^]
http://www.codingconvention.com/tutorials/Win32-Drawing[^]
http://www.winprog.org/tutorial/bitmaps.html[^]


我可能有一些信息可以帮助您你.这是我在codeproject上写的几篇文章:

初学者WIN32 Paint指南 [中间体WIN32 Paint指南 [ Win32内存DC指南 [
I might have some information that could help you. Here are a few articles I wrote here at codeproject:

Guide to WIN32 Paint for beginners[^]
Guide to WIN32 Paint for Intermediates[^]
Guide to Win32 Memory DC[^]

With the shameless plug out of the way, here is a brief description.

The HDC is a handle to a Device Context similar to the HWND is a handle to a window. Let''s draw a parallel between the two:

Window: An abstraction to represent something that can receive messages from the system, may have a size and location on the screen, may contain other windows, has behaviors and so on. You get access to all of this functionality through the APIs and the HWND for the window.
There are all types of windows: overlapped, dialogs, child windows, buttons, scrollbars, tool windows etc. You have a general set of functions that allow you to interact with these windows no matter what type of window they are. Then there are some special functions that only apply to windows of a particular type, such as a button with the click message.

Device Context: An abstraction to represent something that can create a visual representation. As Albert indicated GDI hides all of the details about accessing display hardware so the developer can write with one set of APIs to create visual output.
A device context can represent Window displays, bitmaps, printers, pen plot printers (which dont support raster bitmaps), or anything else that could relate to visual representations.

The links I listed above should help you get started. It definitely is a foreign concept until you get the hang of it. more detail than should go in a quick answer.

Ask more questions if this doesn''t clear things up for you.


这篇关于在win32 API程序中,设备上下文是什么?它如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆