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?
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.
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?
When i put "HDC handleDeviceContext;" im creating a handle variable and with name of handleDeviceContext arnt i.
Your are creating a variable namedhandleDeviceContext 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.
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?
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.