TNB Library
TnbWndTextDrawer.h
[詳解]
1#pragma once
11#include "TnbTextDrawer.h"
12#include "TnbPartsDrawable.h"
13
14
15
16//TNB Library
17namespace TNB
18{
19
20
21
38{
39 DEFSUPER(CNullDrawer);
40public:
41
52 CWndTextDrawer(const SIZE& size, HWND hWnd, COLORREF color, DWORD style, int cx = 2, int cy = 2, const IPartsDrawable* pParts = NULL)
53 : _super(size), m_style(style), m_color(color), m_hWnd(hWnd), m_cx(cx), m_cy(cy), m_pParts(pParts), m_bkMode(TRANSPARENT)
54 {
55 }
56
67 CWndTextDrawer(HWND hWnd, COLORREF color, DWORD style, int cx = 2, int cy = 2, const IPartsDrawable* pParts = NULL)
68 : _super(), m_style(style), m_color(color), m_hWnd(hWnd), m_cx(cx), m_cy(cy), m_pParts(pParts), m_bkMode(TRANSPARENT)
69 {
70 }
71
77 virtual IDrawable* Clone(void) const
78 {
79 CWndTextDrawer* P = new CWndTextDrawer(NULL, RGB(0, 0, 0), 0);
80 *P = *this;
81 return P;
82 }
83
91 virtual void Draw(HDC dc, int x = 0, int y = 0) const
92 {
93 if ( ::IsWindow(m_hWnd) )
94 {
95 int iLen = ::GetWindowTextLength(m_hWnd);
96 if ( iLen > 1 )
97 {
98 CWorkMemT<TCHAR> str(iLen + 2);
99 ::GetWindowText(m_hWnd, str, iLen + 1);
100 RECT rc = { x + m_cx, y + m_cy, x + m_size.cx - m_cx, y + m_size.cy - m_cy };
101 CDcSelectAssistant dca(dc);
102// int oldBkMode = ::SetBkMode(dc, m_bkMode);
103 dca.SetBkMode(m_bkMode);
104 HFONT font = reinterpret_cast<HFONT>(::SendMessage(m_hWnd, WM_GETFONT, 0, 0));
105// HGDIOBJ oldObj = ::SelectObject(dc, font);
106 dca.SelectFont(font);
107 CTextDrawer::DrawTextRect(rc, dc, m_style, m_color, str);
108 if ( m_pParts != NULL && ::GetFocus() == m_hWnd )
109 {
110 RECT wr;
111 ::GetClientRect(m_hWnd, &wr);
112 rc.left--;
113 rc.right++;
114 rc.top--;
115 rc.bottom += 2;
116 ::IntersectRect(&rc, &rc, &wr);
117 m_pParts->DrawFocusRect(dc, &rc);
118 }
119// ::SelectObject(dc, oldObj);
120// ::SetBkMode(dc, oldBkMode);
121 }
122 }
123 }
124
129 void SetTextColor(COLORREF color)
130 {
131 m_color = color;
132 }
133
138 void SetTextStyle(DWORD style)
139 {
140 m_style = style;
141 }
142
147 void SetBkMode(int mode)
148 {
149 m_bkMode = mode;
150 }
151
152private:
153 HWND m_hWnd;
154 COLORREF m_color;
155 DWORD m_style;
156 int m_cx;
157 int m_cy;
158 const IPartsDrawable* m_pParts;
159 int m_bkMode;
160};
161
162
163
164}; //TNB
165
166
パーツ描画情報のヘッダ
テキスト描画関係のヘッダ
デバイステキストセレクトアシスタント
void SetBkMode(int mode)
[設定] 背景モード設定.
void SelectFont(HFONT font)
[選択] フォント選択.
NULL描画クラス
Definition: TnbDrawable.h:106
SIZE m_size
サイズ
Definition: TnbDrawable.h:109
static bool DrawTextRect(RECT &_rect, HDC dc, DWORD drawStyle, const POINT &offset, COLORREF color1, COLORREF color2, LPCTSTR str)
[表示] 範囲文字表示.
WNDテキスト描画クラス
CWndTextDrawer(const SIZE &size, HWND hWnd, COLORREF color, DWORD style, int cx=2, int cy=2, const IPartsDrawable *pParts=NULL)
コンストラクタ
virtual void Draw(HDC dc, int x=0, int y=0) const
[描画] 描画.
void SetBkMode(int mode)
[設定] 背景モード設定
void SetTextColor(COLORREF color)
[設定] 色設定.
void SetTextStyle(DWORD style)
[設定] スタイル設定.
virtual IDrawable * Clone(void) const
[作成] クローン作成.
CWndTextDrawer(HWND hWnd, COLORREF color, DWORD style, int cx=2, int cy=2, const IPartsDrawable *pParts=NULL)
コンストラクタ
TNB Library
Definition: TnbDoxyTitle.txt:2
描画情報インターフェース
Definition: TnbDrawable.h:37
WINDOWパーツ描画インターフェース
virtual bool DrawFocusRect(HDC hdc, LPCRECT lpRect) const =0
[描画] フォーカス枠描画.