
TDC provides one conversion operator HDC, that lets you return the,
Device-context
handle to the device context of your particular TDC or TDC-derived object.
operators
This operator is most often invoked implicitly When you use a TDC object.
where you would normally use an HDC, such as in a function call or the
like, the compiler tries to find a way to cast the object to the required type.
Thus it uses the HDC conversion operator even though it is not explicitly
called.
For example, suppose you want to create a device context in memory that is
compatible with the device associated with a TDC object. Y u can use theo
CreateCompatibleDC Windows API function to create the new device context
from your existing TDC object:
HDC GetCompatDC(TDC& dc, TWindow& window)
{
HDC compatDC;
if(!(compatDC = CreateCompatibleDC(dc)))
{
window.MessageBox("Couldn’t create compatible device context!", "Failure",
MB_OK | MB_ICONEXCLAMATION);
return NULL;
}
else return compatDC;
}
Notice that CreateCompatibleDC takes a single parameter an HDC. Thus the,
function parameter dc is implicitly cast to an HDC in the
CreateCompatibleDC call.
The functions in this section are used to access information about the
Device-context
device context itself. They are equivalent to the Windows API functions of
functions
the same names.
Y u can save and restore a device context much like normal using theo
functions SaveDC and RestoreDC. The following code sample shows how
these functions might be used. Notice that RestoreDC’ single parameters
uses a default value instead of specifying the
int parameter:
void
TMyDC::SomeFunc(TDC& dc, int x1, int y1, int x2, int y2)
{
dc.SaveDC();
dc.SetMapMode(MM_LOENGLISH);
.
.
.
dc.Rectangle(x1, -y1, x2, -y2);
292
OWL P ogrammer’ Guider s