43 return SelectObject(
GetHDC(),
object);
46 HBRUSH SetBrush(HBRUSH brush)
48 return reinterpret_cast<HBRUSH
>(
Select(brush));
53 return reinterpret_cast<HPEN
>(
Select(pen));
56 HFONT SetFont(HFONT font)
58 return reinterpret_cast<HFONT
>(
Select(font));
61 HRGN SetRegion(HRGN region)
63 return reinterpret_cast<HRGN
>(
Select(region));
66 bool BitBlt(
int x,
int y,
int width,
int height, HDC sourceDC,
int srcX,
int srcY, DWORD rasterOp = SRCCOPY)
68 return ::BitBlt(
GetHDC(), x, y, width, height,
73 bool BitBlt(
const RECT& rect, HDC sourceDC,
const POINT& sourcePoint, DWORD rasterOp = SRCCOPY)
75 return ::BitBlt(
GetHDC(), rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
76 sourceDC, sourcePoint.x, sourcePoint.y,
85 bool StretchBlt(
int x,
int y,
int width,
int height, HDC sourceDC,
int srcX,
int srcY,
int srcWidth,
int srcHeight, DWORD rasterOp = SRCCOPY)
87 return ::StretchBlt(
GetHDC(), x, y, width, height,
88 sourceDC, srcX, srcY, srcWidth, srcHeight,
92 bool StretchBlt(
const RECT& rect, HDC sourceDC,
const RECT& sourceRect, DWORD rasterOp = SRCCOPY)
94 return ::StretchBlt(
GetHDC(), rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
95 sourceDC, sourceRect.left, sourceRect.top, sourceRect.right - sourceRect.left, sourceRect.bottom - sourceRect.top,
99 void FillRect(
const RECT& r, HBRUSH brush)
101 ::FillRect(
GetHDC(), &r, brush);
104 void FillRegion(HRGN region, HBRUSH brush)
106 ::FillRgn(
GetHDC(), region, brush);
114 SetBkMode(
GetHDC(), OPAQUE);
122 SetBkMode(
GetHDC(), TRANSPARENT);
125 void SetTextColor(COLORREF color)
127 ::SetTextColor(
GetHDC(), color);
140 void DrawText(
const tstring& text, RECT& boundingRect, UINT format = DT_LEFT|DT_TOP)
145 void DrawText(
const tstring& text,
int x,
int y)
147 Rect r(x, y, 1000000, 1000000);
155 Size GetTextSize(
const tstring& text, UINT format = DT_LEFT|DT_TOP, LONG maxWidth = 1000000)
158 Rect r(0, 0, maxWidth, 0);
159 DrawText(text, r, format | DT_CALCRECT);
170 DC(HDC pDC = 0) :
dc(pDC) {}
174 void operator=(HDC pDC) {
dc = pDC; }
175 operator HDC() {
return dc; }
186 PaintDC(HWND pHwnd) : hwnd(pHwnd)
188 dc = BeginPaint(hwnd, &ps);
197 ZeroMemory(&rhs.ps,
sizeof(rhs.ps));
206 operator HDC() {
return dc; }
208 PaintDC(
const PaintDC& rhs) {}
221 ClientDC(HWND win) : window(win) { dc = GetDC(window); }
229 ~
ClientDC() { ReleaseDC(window, dc); }
233 operator HDC() {
return dc; }
235 ClientDC(
const ClientDC& rhs) {}
252 MemoryDC(HDC other, HBITMAP bitmap) { Init(other, bitmap); }
256 attachedBitmap = rhs.attachedBitmap;
258 rhs.attachedBitmap = 0;
260 ~
MemoryDC() {
if(dc) { RestoreDC(dc, -1); DeleteDC(dc); } }
264 operator HDC() {
return dc; }
266 HBITMAP GetBitmap() {
return attachedBitmap; }
269 void Init(HDC other, HBITMAP bitmap);
272 HBITMAP attachedBitmap;
275 inline void MemoryDC::Init(HDC other, HBITMAP bitmap)
277 attachedBitmap = bitmap;
279 dc = CreateCompatibleDC(other);
284 SelectObject(dc, bitmap);
virtual HDC GetHDC()
Definition: DC.h:204
int SetStretchBltMode(int mode)
Definition: DC.h:83
virtual HDC GetHDC()
Definition: DC.h:262
Size GetTextSize(const tstring &text, UINT format=DT_LEFT|DT_TOP, LONG maxWidth=1000000)
Definition: DC.h:155
Wraps SaveDC in an object oriented way.
Definition: DC.h:13
void SetBkModeTransparent()
Definition: DC.h:120
A paint device context can only be called inside the WM_PAINT message handler.
Definition: DC.h:183
void DrawText(const tstring &text, RECT &boundingRect, UINT format=DT_LEFT|DT_TOP)
Definition: DC.h:140
MemoryDC(HBITMAP bitmap)
Definition: DC.h:250
MemoryDC(HDC other, HBITMAP bitmap)
Definition: DC.h:252
Interface for device context functions.
Definition: DC.h:26
Memory device contexts attach themselves to a bitmap.
Definition: DC.h:246
Unmanaged device context, to allow the user to call IDC functions on arbitrary DCs.
Definition: DC.h:167
Windows SIZE structure with constructor.
Definition: Rect.h:79
void SetBkModeOpaque()
Definition: DC.h:112
HDC dc
Definition: DC.h:177
virtual HDC GetHDC()
Definition: DC.h:172
void SetBkColor(COLORREF color)
Definition: DC.h:132
virtual HDC GetHDC()
Definition: DC.h:231
Windows RECT structure with constructor.
Definition: Rect.h:108
A client device context allows drawing to the client area of a window.
Definition: DC.h:218
HGDIOBJ Select(HGDIOBJ object)
Definition: DC.h:41