15 #define BS_TYPEMASK 0x0000000F
18 #define SS_TYPEMASK 0x0000001FL
65 CTextDrawer(
const SIZE& size, HFONT font, COLORREF textColor, LPCTSTR str, DWORD drawStyle = DT_CENTER | DT_VCENTER,
int margin = 0)
79 CTextDrawer(HFONT font, COLORREF textColor, LPCTSTR str, DWORD drawStyle = DT_CENTER | DT_VCENTER,
int margin = 0)
102 virtual void Draw(HDC dc,
int x = 0,
int y = 0)
const
188 HDC dc = ::GetDC(hWnd);
199 ::ReleaseDC(hWnd, dc);
203 m_size.cy = s.cy + margin;
220 switch ( staticStyle & SS_TYPEMASK )
222 case SS_CENTER: r = DT_CENTER;
break;
223 case SS_LEFT: r = DT_LEFT;
break;
224 case SS_RIGHT: r = DT_RIGHT;
break;
225 case SS_SIMPLE: r = DT_SINGLELINE;
break;
227 if ( (staticStyle & SS_TYPEMASK) != SS_LEFTNOWORDWRAP )
231 if ( (staticStyle & SS_CENTERIMAGE) != 0 )
233 r |= DT_VCENTER | DT_SINGLELINE;
235 if ( (staticStyle & SS_NOPREFIX) != 0 )
240 if ( (staticStyle & SS_WORDELLIPSIS) == SS_WORDELLIPSIS )
242 r |= DT_WORD_ELLIPSIS;
244 else if ( (staticStyle & SS_ENDELLIPSIS) != 0 )
246 r |= DT_END_ELLIPSIS;
248 else if ( (staticStyle & SS_PATHELLIPSIS) != 0 )
250 r |= DT_PATH_ELLIPSIS;
264 bool isPushButton =
false;
265 if ( (buttonStyle & BS_TYPEMASK) <= BS_DEFPUSHBUTTON || (buttonStyle & BS_PUSHLIKE) != 0 )
269 switch ( buttonStyle & 0x0300 )
271 case BS_LEFT: r |= DT_LEFT;
break;
272 case BS_RIGHT: r |= DT_RIGHT;
break;
273 case BS_CENTER: r |= DT_CENTER;
break;
275 r |= (isPushButton ? DT_CENTER : DT_LEFT);
279 switch ( buttonStyle & 0x0C00 )
281 case BS_TOP: r |= DT_TOP;
break;
282 case BS_BOTTOM: r |= DT_BOTTOM;
break;
284 case BS_VCENTER: r |= DT_VCENTER;
break;
286 if ( (buttonStyle & BS_MULTILINE) == 0 )
307 static bool CalcTextSize(SIZE& _size, HDC dc, UINT drawStyle, LPCTSTR str)
309 RECT rc = { 0, 0, _size.cx, _size.cy };
310 int r = ::DrawText(dc, str, -1, &rc, (drawStyle & 0xFFFFFFF0) | DT_CALCRECT);
312 _size.cy = rc.bottom;
325 static bool CalcTextRect(RECT& _rect, HDC dc, DWORD drawStyle, LPCTSTR str)
327 SIZE sz = { _rect.right - _rect.left, _rect.bottom - _rect.top };
328 if ( !
CalcTextSize(sz, dc, drawStyle, str) ) {
return false; }
329 RECT rc = { 0, 0, sz.cx, sz.cy };
330 int cx = (_rect.right - _rect.left) - sz.cx;
331 int cy = (_rect.bottom - _rect.top) - sz.cy;
332 if ( (drawStyle & DT_CENTER) != 0 )
336 else if ( (drawStyle & DT_RIGHT) == 0 )
340 if ( (drawStyle & DT_VCENTER) != 0 )
344 else if ( (drawStyle & DT_BOTTOM) == 0 )
348 ::OffsetRect(&rc, cx + _rect.left, cy + _rect.top);
366 static bool DrawTextRect(RECT& _rect, HDC dc, DWORD drawStyle,
const POINT& offset, COLORREF color1, COLORREF color2, LPCTSTR str)
372 drawStyle &= ~DT_VCENTER;
374 if ( color1 == CLR_INVALID )
377 ::DrawState(dc, NULL, &ms_DrawStateProc,
378 reinterpret_cast<LPARAM
>(str),
379 static_cast<WPARAM
>(drawStyle),
380 rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, DST_COMPLEX | DSS_DISABLED);
384 return DrawTextRect(dc, _rect, drawStyle, po, ::GetSysColor(COLOR_GRAYTEXT), ::GetSysColor(COLOR_3DHILIGHT), str);
387 if ( color1 == CLR_AUTOSELECT )
391 if ( color2 == CLR_INVALID )
394 ::DrawText(dc, str, -1, &rc, drawStyle);
400 ::OffsetRect(&rc, offset.x, offset.y);
401 ::DrawText(dc, str, -1, &rc, drawStyle);
404 ::DrawText(dc, str, -1, &rc, drawStyle);
423 static bool DrawTextRect(HDC dc,
const RECT& rect, DWORD drawStyle,
const POINT& offset, COLORREF color1, COLORREF color2, LPCTSTR str)
426 return DrawTextRect(rc, dc, drawStyle, offset, color1, color2, str);
440 static bool DrawTextRect(RECT& _rect, HDC dc, DWORD drawStyle, COLORREF color, LPCTSTR str)
443 return DrawTextRect(_rect, dc, drawStyle, po, color, CLR_INVALID, str);
457 static bool DrawTextRect(HDC dc,
const RECT& rect, DWORD drawStyle, COLORREF color, LPCTSTR str)
461 return DrawTextRect(rc, dc, drawStyle, po, color, CLR_INVALID, str);
477 static bool ModifyText(
CSimpleStr& _str,
const SIZE& size, HDC dc, LPCTSTR lpsz, UINT drawStyle = DT_END_ELLIPSIS | DT_NOPREFIX)
482 RECT rc = { 0, 0, size.cx, size.cy };
483 int r = ::DrawTextEx(dc, work, -1, &rc, (drawStyle & 0xFFFFFFF0) | DT_MODIFYSTRING | DT_CALCRECT, NULL);
501 static bool ModifyText(
CSimpleStr& _str, HWND hWnd, LPCTSTR lpsz, UINT drawStyle = DT_END_ELLIPSIS | DT_NOPREFIX)
503 HDC dc = ::GetDC(hWnd);
507 HFONT hFont =
reinterpret_cast<HFONT
>(::SendMessage(hWnd, WM_GETFONT, 0, 0));
512 ::GetClientRect(hWnd, &rc);
513 SIZE size = { rc.right - rc.left, rc.bottom - rc.top };
514 bool r =
ModifyText(_str, size, dc, lpsz, drawStyle);
517 ::ReleaseDC(hWnd, dc);
534 static BOOL CALLBACK ms_DrawStateProc(HDC hDC, LPARAM lParam, WPARAM wParam,
int cx,
int cy)
536 LPCTSTR str =
reinterpret_cast<LPCTSTR
>(lParam);
537 DWORD drawStyle =
static_cast<DWORD
>(wParam);
538 RECT rc = { 0, 0, cx, cy };
539 ::DrawText(hDC, str, -1, &rc, drawStyle);
561 COLORREF m_backColor;
573 CTextBkDrawer(
const SIZE& size, HFONT font, COLORREF textColor, COLORREF backColor, LPCTSTR str, DWORD style = DT_CENTER | DT_VCENTER,
int margin = 0)
574 : _super(size, font, textColor, str, style, margin), m_backColor(backColor)
587 CTextBkDrawer(HFONT font, COLORREF textColor, COLORREF backColor, LPCTSTR str, DWORD style = DT_CENTER | DT_VCENTER,
int margin = 0)
588 : _super(font, textColor, str, style, margin), m_backColor(backColor)
609 virtual void Draw(HDC dc,
int x = 0,
int y = 0)
const
615 ::ExtTextOut(dc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
void Restore(void)
[設定] リストア.
void SetBkColor(COLORREF c)
[設定] 背景色設定.
void SetBkMode(int mode)
[設定] 背景モード設定.
void SelectFont(HFONT font)
[選択] フォント選択.
virtual void Draw(HDC dc, int x=0, int y=0) const
[描画] 描画.
void SetBackColor(COLORREF color)
[設定] 背景色設定.
CTextBkDrawer(HFONT font, COLORREF textColor, COLORREF backColor, LPCTSTR str, DWORD style=DT_CENTER|DT_VCENTER, int margin=0)
コンストラクタ
CTextBkDrawer(const SIZE &size, HFONT font, COLORREF textColor, COLORREF backColor, LPCTSTR str, DWORD style=DT_CENTER|DT_VCENTER, int margin=0)
コンストラクタ
virtual IDrawable * Clone(void) const
[作成] クローン作成.
DWORD GetDrawStyle(void) const
[取得] スタイル取得.
COLORREF GetTextColor(void) const
[取得] 文字色取得.
COLORREF m_textColor
テキストカラー
static bool ModifyText(CSimpleStr &_str, HWND hWnd, LPCTSTR lpsz, UINT drawStyle=DT_END_ELLIPSIS|DT_NOPREFIX)
[計算] 文字列編集.
static bool DrawTextRect(HDC dc, const RECT &rect, DWORD drawStyle, const POINT &offset, COLORREF color1, COLORREF color2, LPCTSTR str)
[表示] 範囲文字表示.
DWORD m_drawStyle
DrawTextスタイル
CTextDrawer(HFONT font, COLORREF textColor, LPCTSTR str, DWORD drawStyle=DT_CENTER|DT_VCENTER, int margin=0)
コンストラクタ
virtual void Draw(HDC dc, int x=0, int y=0) const
[描画] 描画.
bool AdjustSize(int margin=1, HWND hWnd=NULL)
[設定] サイズ調整.
static bool CalcTextSize(SIZE &_size, HDC dc, UINT drawStyle, LPCTSTR str)
[計算] 文字表示大きさ計算.
static bool CalcTextRect(RECT &_rect, HDC dc, DWORD drawStyle, LPCTSTR str)
[計算] 文字表示範囲計算.
void SetDrawStyle(DWORD drawStyle=DT_CENTER|DT_VCENTER)
[設定] スタイル設定.
static bool DrawTextRect(HDC dc, const RECT &rect, DWORD drawStyle, COLORREF color, LPCTSTR str)
[表示] 範囲文字表示.
CTextDrawer(const SIZE &size, HFONT font, COLORREF textColor, LPCTSTR str, DWORD drawStyle=DT_CENTER|DT_VCENTER, int margin=0)
コンストラクタ
static DWORD ButtonToDrawStyle(DWORD buttonStyle)
[変換] ButtonスタイルをDrawTextスタイルに変換
static bool ModifyText(CSimpleStr &_str, const SIZE &size, HDC dc, LPCTSTR lpsz, UINT drawStyle=DT_END_ELLIPSIS|DT_NOPREFIX)
[計算] 文字列編集.
static bool DrawTextRect(RECT &_rect, HDC dc, DWORD drawStyle, COLORREF color, LPCTSTR str)
[表示] 範囲文字表示.
static bool DrawTextRect(RECT &_rect, HDC dc, DWORD drawStyle, const POINT &offset, COLORREF color1, COLORREF color2, LPCTSTR str)
[表示] 範囲文字表示.
static DWORD StaticToDrawStyle(DWORD staticStyle)
[変換] StaticスタイルをDrawTextスタイルに変換
void SetTextColor(COLORREF color)
[設定] 文字色設定.
void SetString(LPCTSTR str)
[設定] 文字列設定.
LPCTSTR GetString(void) const
[取得] 文字列取得.
virtual IDrawable * Clone(void) const
[作成] クローン作成.
size_t GetLen(LPCSTR lpsz)
[計算] 文字列長計算(ASCII/SJIS用)
void Copy(LPSTR _dst, LPCSTR src)
[複製] 文字列コピー(ASCII/SJIS用)