WM_PAINT

Hi, see:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
HDC handleDeviceContext; 
    PAINTSTRUCT PaintSt;
	RECT aRect;

	switch(msg)
    {

		case WM_PAINT:

			handleDeviceContext = BeginPaint(hwnd, &PaintSt);
			
			GetClientRect(hwnd, &aRect);
			
			SetBkMode(handleDeviceContext, TRANSPARENT); 
			
			DrawText(handleDeviceContext, TEXT("It's a blizzard!"), -1, &aRect, DT_SINGLELINE|DT_CENTER| DT_VCENTER); 

			DrawText(handleDeviceContext, TEXT("It's a blizzard!!"), -1, &aRect, DT_SINGLELINE|DT_LEFT| DT_VCENTER); 
			
			EndPaint(hwnd, &PaintSt); 

			break;


Obviously "HDC handleDeviceContext;" makes a variable of the HDC type, What exactly am i passing to the handleDevliceContext variable by passing the return value of the BeginPaint() function?

Thanks.
closed account (z05DSL3A)
TpOreilly wrote:
What exactly am i passing to the handleDevliceContext variable by passing the return value of the BeginPaint() function?

I am assuming you are asking 'what is stored in the variable handleDevliceContext?'
If you look at the typedef for a HGDIOBJ* you would be forgiven for thinking that it is a pointer, it is not. Basically a Handle is an encoded number, in the case of a Handle to a GDI Object encoded in the number would be a bit to say if this a stock object, 7 bits to say what type of object it is (pen, brush, etc.) and a say 12 bits for an index for the object itself.


* HGDIOBJ is the most generic GDI object type.
When i put "HDC handleDeviceContext;" im creating a handle with a name of handleDeviceContext arnt i?

And when i put handleDeviceContext = BeginPaint(hwnd, &PaintSt); I am giving handleDeviceContext the return value of BeginPaint() arnt it?

So i'm asking what is beginpaint() actually passing to to handleDeviceContext, so what is actually stored in the handleDeviceContext variable?

Thanks

When i put "HDC handleDeviceContext;" im creating a handle variable and with name of handleDeviceContext arnt i.

When i put "handleDeviceContext = BeginPaint(hwnd, &PaintSt);" im assigning the return value of beginpaint() to the handleDeviceContext variable arnt i.

So im asking what is actually stored in the handleDeviceContext handle variable. Is the function creating a DC and then giving the variable handleDeviceContext the handle to this DC?
closed account (z05DSL3A)
When i put "HDC handleDeviceContext;" im creating a handle variable and with name of handleDeviceContext arnt i.
Your are creating a variable named handleDeviceContext that is of type handle to a Device Context. This variable can store the HDC that is returned from BeginPaint().

So im asking what is actually stored in the handleDeviceContext handle variable. Is the function creating a DC and then giving the variable handleDeviceContext the handle to this DC?
Yes, BeginPaint() creates a DC that is stored away inside windows and returns a HDC so that you can refer to that DC with other functions. You assign it to the variable so that you don't loose it.
Thanks
I understand that the BeginPaint() function creates and provides a handle to a DC, but this function also "prepares the specified window for painting", im just wondering, what preparations does it do?

Cheers
?
The BeginPaint is an internal Windows OS function - I would imagine only certain privileged
people (microsoft programmers, and maybe some authors especially close to Microsoft) would
know the exact details.

Other non-priviledged programmers like you and I will get a Display Context handle and a PAINTSTRUCT variable with some data about the painting requirements.
Fair enough :)
Topic archived. No new replies allowed.