The TDC Class

Header File

dc.h

Description

TDC is the root class for GDI DC wrappers. Each TDC object inherits a Handle from TGdiBase and casts that Handle to an HDC using the HDC operator. Win API functions that take an HDC argument can therefore be called by a corresponding TDC member function without this explicit handle argument. DC objects can be created directly with TDC constructors, or via the constructors of specialized subclasses (such as TWindowDC, TMemoryDC, TMetaFileDC, TDibDC, and TPrintDC) to get specific behavior. DC objects can be constructed with an already existing and borrowed HDC handle or from scratch by supplying device driver information, as with ::CreateDC. The class TCreateDC takes over much of the creation and deletion work from TDC.

TDC has four handles as protected data members: OrgBrush, OrgPen, OrgFont, and OrgPalette. These handles keep track of the stock GDI objects selected into each DC. As new GDI objects are selected with SelectObject or SelectPalette, these data members store the previous objects. The latter can be restored individually with RestoreBrush, RestorePen, and so on, or they can all be restored with RestoreObjects. When a TDC object is destroyed (via ~ TDC::TDC), all the originally selected objects are restored. The data member TDC::ShouldDelete controls the deletion of the TDC object.

Public Constructors and Destructor

TDC(HDC handle);
virtual ~TDC();

Public Member Functions

bool AngleArc(int x, int y, uint32 radius, float startAngle, float sweepAngle);
bool AngleArc(const TPoint& center, uint32 radius, float startAngle, float sweepAngle);
bool Arc(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4);
bool Arc(const TRect& r, const TPoint& start, const TPoint& end);
bool BeginPath();
bool BitBlt(int dstX, int dstY, int w, int h, const TDC& srcDC, int srcX, int srcY, uint32 rop=SRCCOPY);
bool BitBlt(const TRect& dst, const TDC& srcDC, const TPoint& src, uint32 rop=SRCCOPY);
bool Chord(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4);
bool Chord(const TRect& r, const TPoint& start, const TPoint& end);
bool CloseFigure();

bool DPtoLP(TPoint* points, int count = 1) const;
bool DrawFocusRect(int x1, int x2, int y1, int y2);
bool DrawFocusRect(const TRect& rect);
bool DrawIcon(int x, int y, const TIcon& icon);
bool DrawIcon(const TPoint& point, const TIcon& icon);
virtual bool DrawText(const char far* string, int count, const TRect& r, uint16 format = 0);
bool Ellipse(int x1, int y1, int x2, int y2);
bool Ellipse(const TPoint& p1, const TPoint& p2);
bool Ellipse(const TPoint& point, const TSize& size);
bool Ellipse(const TRect& rect);
bool EndPath();
int EnumFontFamilies(const char far* family, FONTENUMPROC proc, void far* data) const;

int EnumFonts(const char far* faceName, OLDFONTENUMPROC callback, void far* data) const;
int EnumMetaFile(const TMetaFilePict& metaFile, MFENUMPROC callback, void* data) const;
int EnumObjects(uint objectType, GOBJENUMPROC proc, void far* data) const;
int ExcludeClipRect(const TRect& rect);
int ExcludeUpdateRgn(HWND wnd);
bool ExtFloodFill(const TPoint& point, TColor color, uint16 fillType);
virtual bool ExtTextOut(int x, int y, uint16 options, const TRect* r, const char far* string, int count, const int far* dx = 0);
bool ExtTextOut(const TPoint& p, uint16 options, const TRect* r, const char far* string, int count, const int far* dx = 0);

bool FillPath();
bool FillRect(int x1, int y1, int x2, int y2, const TBrush& brush);
bool FillRect(const TRect& rect, const TBrush& brush);
bool FillRgn(const TRegion& region, const TBrush& brush);
bool FlattenPath();
bool FloodFill(const TPoint& point, TColor color);
bool FrameRect(int x1, int x2, int y1, int y2, const TBrush& brush);
bool FrameRect(const TRect& rect, const TBrush& brush);
bool FrameRgn(const TRegion& region, const TBrush& brush, const TPoint& p);
bool GetAspectRatioFilter(TSize& size) const;
TColor GetBkColor() const;
int GetBkMode() const;

bool GetBoundsRect(TRect& bounds, uint16 flags) const;
bool GetBrushOrg(TPoint& point) const;
bool GetCharABCWidths(uint firstChar, uint lastChar, ABC* abc);
bool GetCharWidth(uint firstChar, uint lastChar, int* buffer);
int GetClipBox(TRect& rect) const;
TRect GetClipBox() const;
bool GetClipRgn(TRegion& region) const;
HANDLE GetCurrentObject(uint objectType) const;
bool GetCurrentPosition(TPoint& point) const;
bool GetDCOrg(TPoint& point) const;
virtual int GetDeviceCaps(int index) const;
bool GetDIBits(const TBitmap& bitmap, uint16 startScan, uint16 numScans, void HUGE* bits, const BITMAPINFO far& info, uint16 usage)

bool GetDIBits(const TBitmap& bitmap, TDib& dib);
uint32 GetFontData(uint32 table, uint32 offset, void* buffer, long data);
uint32 GetGlyphOutline(uint chr, uint format, GLYPHMETRICS far& gm, uint32 buffSize, void far* buffer, const MAT2 far& mat2);
int GetKerningPairs(int pairs, KERNINGPAIR far* krnPair);
int GetMapMode() const;
TColor GetNearestColor(TColor Color) const;
uint32 GetOutlineTextMetrics(uint data, OUTLINETEXTMETRIC far& otm);
uint16 GetOutlineTextMetrics(uint data, OUTLINETEXTMETRIC far& otm);
TColor GetPixel(int x, int y) const;

TColor GetPixel(const TPoint& point) const;
int GetPolyFillMode() const;
int GetROP2() const;
int GetStretchBltMode() const;
uint GetSystemPaletteEntries(int start, int num, PALETTEENTRY far* entries) const;
uint GetSystemPaletteUse() const;
bool GetTabbedTextExtent(const char far* string, int stringLen, int numPositions, const int far* positions, TSize& size) const;
TSize GetTabbedTextExtent(const char far* string, int stringLen, int numPositions, const int far* positions) const;
uint GetTextAlign() const;
int GetTextCharacterExtra() const;
TColor GetTextColor() const;
bool GetTextExtent(const char far* string, int stringLen, TSize& size);

TSize GetTextExtent(const char far* string, int stringLen);
int GetTextFace(int count, char far* facename) const;
bool GetTextMetrics(TEXTMETRIC far& metrics) const;
bool GetViewportExt(TSize& extent) const;
TSize GetViewportExt() const;
bool GetViewportOrg(TPoint& point) const;
TPoint GetViewportOrg() const;
bool GetWindowExt(TSize& extent) const;
TSize GetWindowExt() const;
bool GetWindowOrg(TPoint& point) const;
TPoint GetWindowOrg() const;

virtual bool GrayString(const TBrush& brush, GRAYSTRINGPROC outputFunc, const char far* string, int count, const TRect& r);

operator HDC() const{return Handle;}
int IntersectClipRect(const TRect& rect);
bool InvertRect(int x1, int x2, int y1, int y2);
bool InvertRect(const TRect& rect);
bool InvertRgn(const TRegion& region);
bool LineTo(int x, int y);
bool LineTo(const TPoint& point);
bool LPtoDP(TPoint* points, int count = 1) const;
bool MaskBlt(const TRect& dst, const TDC& srcDC, const TPoint& src, const TBitmap& maskBm, const TPoint& maskPos, uint32 rop);
bool ModifyWorldTransform(XFORM far& xform, uint32 mode);
bool MoveTo(int x, int y);
bool MoveTo(const TPoint& point);
bool MoveTo(const TPoint& point, TPoint& oldPoint);

int OffsetClipRgn(const TPoint& delta);
virtual bool OffsetViewportOrg(const TPoint& delta, TPoint* oldOrg = 0);
bool OffsetWindowOrg(const TPoint& delta, TPoint* oldOrg = 0);
void OWLFastWindowFrame(TBrush& brush, TRect& rect, int xWidth, int yWidth);
bool PaintRgn(const TRegion& region);
bool PatBlt(int x, int y, int w, int h, uint32 rop=PATCOPY);
bool PatBlt(const TRect& dst, uint32 rop=PATCOPY);
HRGN PathToRegion();
bool Pie(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4);
bool Pie(const TRect& rect, const TPoint& start, const TPoint& end);
bool PlayMetaFile(const TMetaFilePict& metaFile);

void PlayMetaFileRecord(HANDLETABLE far& Handletable, METARECORD far& metaRecord, int count);
bool PlgBlt(const TPoint& dst, const TDC& srcDC, const TRect& src, const TBitmap& maskBm, const TPoint& maskPos, uint32 rop=SRCCOPY);
bool PolyBezier(const TPoint* points, int count);
bool PolyBezierTo(const TPoint* points, int count);
bool PolyDraw(const TPoint* points, uint8* types, int count);
bool Polygon(const TPoint* points, int count);
bool Polyline(const TPoint* points, int count);
bool PolylineTo(const TPoint* points, int count);
bool PolyPolygon(const TPoint* points, const int* PolyCounts, int count);
bool PolyPolyline(const TPoint* points, const int* PolyCounts, int count);
bool PtVisible(const TPoint& point) const;

int RealizePalette();
bool Rectangle(int x1, int y1, int x2, int y2);
bool Rectangle(const TPoint& p1, const TPoint& p2);
bool Rectangle(const TPoint& point, const TSize& s);
bool Rectangle(const TRect& rect);
bool RectVisible(const TRect& rect) const;
virtual bool ResetDC(DEVMODE far& devMode);
void RestoreBrush();
virtual bool RestoreDC(int savedDC = -1);
virtual void RestoreFont();
void RestoreObjects();
void RestorePalette();
void RestorePen();
void RestoreTextBrush();
bool RoundRect(int x1, int y1, int x2, int y2, int x3, int y3);
bool RoundRect(const TPoint& p1, const TPoint& p2, const TPoint& rad);

bool RoundRect(const TPoint& p, const TSize& s, const TPoint& rad);
bool RoundRect(const TRect& rect, const TPoint& rad);
virtual int SaveDC() const;
virtual bool ScaleViewportExt(int xNum, int xDenom, int yNum, int yDenom, TSize* oldExtent = 0);
virtual bool ScaleWindowExt(int xNum, int xDenom, int yNum, int yDenom, TSize* oldExtent = 0);
bool ScrollDC(int x, int y, const TRect& scroll, const TRect& clip, TRegion& updateRgn, TRect& updateRect);
bool ScrollDC(const TPoint& delta, const TRect& scroll, const TRect& clip, TRegion& updateRgn, TRect& updateRect);
bool SelectClipPath(int mode);
int SelectClipRgn(const TRegion& region);
void SelectObject(const TBrush& brush);
void SelectObject(const TPen& pen);

virtual void SelectObject(const TFont& font);
void SelectObject(const TPalette& palette, bool forceBackground = false);
virtual void SelectStockObject(int index);
virtual TColor SetBkColor(TColor color);
int SetBkMode(int mode);
uint SetBoundsRect(TRect& bounds, uint flags);
bool SetBrushOrg(const TPoint& origin, TPoint* oldOrg = 0);
bool SetDIBits(TBitmap& bitmap, uint16 startScan, uint16 numScans, const void HUGE* bits, const BITMAPINFO far& Info, uint16 usage);
bool SetDIBits(TBitmap& Bitmap, const TDib& dib);
bool SetDIBitsToDevice(const TRect& dst, const TPoint& src, uint16 startScan, uint16 numScans, const void HUGE* bits, const BITMAPINFO far& bitsInfo, uint16 usage);

bool SetDIBitsToDevice(const TRect& dst, const TPoint& src, const TDib& dib);
virtual int SetMapMode(int mode);
uint32 SetMapperFlags(uint32 flag);
bool SetMiterLimit(float newLimit, float* oldLimit = 0);
TColor SetPixel(int x, int y, TColor color);
TColor SetPixel(const TPoint& p, TColor color);
int SetPolyFillMode(int mode);
int SetROP2(int mode);
int SetStretchBltMode(int mode);
int SetSystemPaletteUse(int usage);
uint SetTextAlign(uint flags);
int SetTextCharacterExtra(int extra);

virtual TColor SetTextColor(TColor color);
bool SetTextJustification(int breakExtra, int breakCount);
virtual bool SetViewportExt(const TSize& extent, TSize* oldExtent = 0);
virtual bool SetViewportOrg(const TPoint& origin, TPoint* oldOrg = 0);
virtual bool SetWindowExt(const TSize& extent, TSize* oldExtent = 0);
bool SetWindowOrg(const TPoint& origin, TPoint* oldOrg = 0);
bool SetWorldTransform(XFORM far& xform);
bool StretchBlt(int dstX, int dstY, int dstW, int dstH, const TDC& srcDC, int srcX, int srcY, int srcW, int srcH, uint32 rop=SRCCOPY);

bool StretchBlt(const TRect& dst, const TDC& srcDC, const TRect& src, uint32 rop=SRCCOPY);
bool StretchDIBits(const TRect& dst, const TRect& src, const void HUGE* bits, const BITMAPINFO far& bitsInfo, uint16 usage, uint32 rop=SRCCOPY);
bool StretchDIBits(const TRect& dst, const TRect& src, const TDib& dib, uint32 rop=SRCCOPY);
bool StrokeAndFillPath();
bool StrokePath();
bool TabbedTextOut(const TPoint& p, const char far* string, int count, int numPositions, const int far* positions, int tabOrigin);
virtual bool TabbedTextOut(const TPoint& p, const char far* string, int count, int numPositions, const int far* positions, int tabOrigin, TSize& size);
virtual bool TextOut(int x, int y, const char far* string, int count = -1);

bool TextOut(const TPoint& p, const char far* string, int count = -1);
bool TextRect(int x1, int y1, int x2, int y2);
bool TextRect(const TRect& rect);
bool TextRect(int x1, int y1, int x2, int y2, TColor color);
bool TextRect(const TRect rect, TColor color);
void UpdateColors();
bool WidenPath();

Protected Constructor
TDC();
TDC
(HDC handle, TAutoDelete AutoDelete);

Protected Data Members

TGDIBase::Handle;
HBRUSH OrgBrush;
HFONT OrgFont;
HPALETTE OrgPalette;
HPEN OrgPen;
HBRUSH OrgTextBrush;
TGdiBase::ShouldDelete;

Protected Member Functions

TGdiBase::CheckValid(uint resId=IDS_GDIFAILURE)
static void CheckValid(HANDLE handle, uint resId=IDS_GDIFAILURE)
virtual HDC GetAttributeHDC() const;
HDC GetHDC() const;
void Init();