TNB Library
TnbMfcSetText.h
[詳解]
1#pragma once
11#include "TnbMfcCommon.h"
12
13
14
15//TNB Library
16namespace TNB {
17namespace MFC {
18
19
20
46template<typename WND = CStatic>
47class CSetTextAddinT : public WND
48{
49 DEFSUPER(WND);
50public:
51
53 CSetTextAddinT(void) : m_postCount(0), m_isValid(false)
54 {
55 }
56
62 void SetWindowText(LPCTSTR lpszString)
63 {
64 if ( ::IsWindow(m_hWnd) && m_isValid )
65 {
66 TTRACE2("SetWindowText tid = %X, %X\n", m_mainThreadId, ::GetCurrentThreadId());
67 if ( m_mainThreadId != ::GetCurrentThreadId() )
68 {
69 CString* P = new CString(lpszString);
70 m_postCount++;
71 if ( ! _super::PostMessage(WM_TNB_POSTTEXT, 0, reinterpret_cast<LPARAM>(P)) )
72 {
73 delete P;
74 m_postCount--;
75 }
76 return;
77 }
78 _super::SetWindowText(lpszString);
79 }
80 }
81
82protected:
83
93 virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
94 {
95 switch ( message )
96 {
97 case WM_TNB_POSTTEXT:
98 {
99 CString* P = reinterpret_cast<CString*>(lParam);
100 if ( ::IsWindow(m_hWnd) )
101 {
102 _super::SetWindowText(P->operator LPCTSTR());
103 }
104 delete P;
105 m_postCount--;
106 return 0;
107 }
108 break;
109 case WM_DESTROY:
110 {
111 MSG msg;
112 m_isValid = false;
113 while ( ::PeekMessage(&msg, m_hWnd, WM_TNB_POSTTEXT, WM_TNB_POSTTEXT, PM_REMOVE) )
114 {
115 if ( msg.message == WM_TNB_POSTTEXT )
116 {
117 CString* P = reinterpret_cast<CString*>(msg.lParam);
118 delete P;
119 m_postCount--;
120 }
121 }
122 ASSERT( m_postCount == 0 );
123 }
124 break;
125 }
126 return _super::WindowProc(message, wParam, lParam);
127 }
128
134 virtual void PreSubclassWindow(void)
135 {
136 m_isValid = true;
137 m_mainThreadId = ::GetCurrentThreadId();
138 _super::PreSubclassWindow();
139 }
140
141private:
142 enum { WM_TNB_POSTTEXT = WM_APP };
143 size_t m_postCount;
144 DWORD m_mainThreadId;
145 bool m_isValid;
146};
147
148
149
150}; // MFC
151}; // TNB
MFCコントロール共通のヘッダ
文字列設定サポートクラス
Definition: TnbMfcSetText.h:48
void SetWindowText(LPCTSTR lpszString)
[設定] 文字列設定.
Definition: TnbMfcSetText.h:62
CSetTextAddinT(void)
コンストラクタ
Definition: TnbMfcSetText.h:53
virtual void PreSubclassWindow(void)
[通知] subclassing/unsubclassing functions.
virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
[通知] for processing Windows messages.
Definition: TnbMfcSetText.h:93
TNB Library
Definition: TnbDoxyTitle.txt:2