Click here to Skip to main content
15,890,412 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Just like as this function,the question at the annotate:
C++
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);
}
Posted

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[^]
 
Share this answer
 
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900