TNB Library
TnbReportViewer.h
[詳解]
1#pragma once
17#ifdef _UNICODE
18#include "TnbStr.h"
19#endif
20#include "TnbSync.h"
21
22
23
24#ifndef _TnbDOXYGEN //Document作成用シンボル
25
26#ifdef _DEBUG
27 #define _TnbREPORT_Viewer_ON
28#endif
29
30#if defined(_WIN32_WCE) && defined(_TnbREPORT_Viewer_ON)
31 #undef _TnbREPORT_Viewer_ON
32#endif
33
34/*
35 * 通信種別
36 * [31-28] 空
37 * [27-24] カテゴリ(RS232c,Socket など)
38 * [23] 0;送信 1;受信
39 * [22] 0;バイナリ 1;テキスト
40 * [21-16] 空
41 * [15-0] 0〜0xFFFF;ポート番号、ATOM識別子
42*/
43#define TNBVIW_KIND_RS232C (0x01<<24) //Rs232c
44#define TNBVIW_KIND_SOCK_S (0x02<<24) //Socket(Server)
45#define TNBVIW_KIND_SOCK_C (0x03<<24) //Socket(Client)
46#define TNBVIW_KIND_SOCK_U (0x04<<24) //Socket(UDP)
47#define TNBVIW_KIND_MAILS (0x05<<24) //Mailslot
48#define TNBVIW_KIND_USB (0x06<<24) //USB
49#define TNBVIW_KIND_FILE (0x07<<24) //FILE
50#define TNBVIW_KIND_TEMP (0x08<<24) //ByteTemp
51#define TNBVIW_KIND_PIPE (0x09<<24) //パイプ
52#define TNBVIW_KIND_COPYDATA (0x0B<<24) //CopyData(Message)
53#define TNBVIW_KIND_ATOM (0x0F<<24) //汎用
54#define TNBVIW_DIRE_SEND 0 //送信
55#define TNBVIW_DIRE_RECV (int(1<<23)) //受信
56#define TNBVIW_TYPE_BIN 0 //バイナリ
57#define TNBVIW_TYPE_TEXT (int(1<<22)) //テキスト
58#define TNBVIW_TYPE_RAWTEXT (int(1<<21)) //生テキスト
59#define TNBVIW_PORT(P) (P) //Port番号 0〜0xFFFF
60
62#define TNB_TNBVIEWER_WND_TITLE "TnbCommViewer"
63#define TNB_TNBVIEWER_WND_CLASS "TnbReport"
64
66#define WM_TNBVIEWER_CMD (WM_APP)
67#define WM_TNBVIEWER_DATA1 (WM_APP+1)
68#define WM_TNBVIEWER_DATA2 (WM_APP+2)
69#define WM_TNBVIEWER_DATA3 (WM_APP+3)
70#define WM_TNBVIEWER_DATA4 (WM_APP+4)
71
72#endif //_TnbDOXYGEN
73
74
75
76//TNB Library
77namespace TNB
78{
79
80
81
96{
97public:
98
104 {
105 #ifdef _TnbREPORT_Viewer_ON
106 m_hPostWnd = ::FindWindow(NULL, _T(TNB_TNBVIEWER_WND_TITLE));
107 #endif
108 }
109
115 bool IsValid(void) const
116 {
117 #ifdef _TnbREPORT_Viewer_ON
118 return m_hPostWnd != 0;
119 #else
120 return false;
121 #endif
122 }
123
129 void Invalid(void)
130 {
131 #ifdef _TnbREPORT_Viewer_ON
132 m_hPostWnd = NULL;
133 #endif
134 }
135
142 void ToViewer(size_t sizeData, LPCVOID lpcvData, DWORD cookie)
143 {
144 #ifdef _TnbREPORT_Viewer_ON
145 if ( m_hPostWnd != NULL )
146 {
147 m_ToViewer(static_cast<DWORD>(cookie & ~TNBVIW_TYPE_TEXT), sizeData, lpcvData);
148 }
149 #endif
150 }
151
157 void ToViewer(LPCTSTR lpszText, DWORD cookie)
158 {
159 #ifdef _TnbREPORT_Viewer_ON
160 if ( m_hPostWnd != NULL )
161 {
162 #ifdef _UNICODE
163 CAscii asc = lpszText;
164 if ( ! asc.IsEmpty() )
165 {
166 m_ToViewer(static_cast<DWORD>(cookie | TNBVIW_TYPE_TEXT), asc.GetLength() + 1, asc.operator LPCSTR());
167 }
168 #else
169 m_ToViewer(static_cast<DWORD>(cookie | TNBVIW_TYPE_TEXT), strlen(lpszText) + 1, lpszText);
170 #endif
171 }
172 #endif
173 }
174
175private:
176
177 #ifdef _TnbREPORT_Viewer_ON
181 void m_PostMessage(UINT message, WPARAM wParam, LPARAM lParam)
182 {
183 BOOL r = ::PostMessage(m_hPostWnd, message, wParam, lParam);
184 if ( ! r )
185 {
186 _GetLastError("PostMessage");
187 }
188 }
195 void m_ToViewer(DWORD cookie, size_t dataSize, LPCVOID lpcvData)
196 {
197 if ( ! ::IsWindow(m_hPostWnd) )
198 {
199 m_hPostWnd = NULL;
200 }
201 else
202 {
203 const BYTE* B = static_cast<const BYTE*>(lpcvData);
204 size_t l = dataSize / 4;
205 for ( size_t i = 0; i < l; i++ )
206 {
207 const DWORD* W = reinterpret_cast<const DWORD*>(B);
208 m_PostMessage(WM_TNBVIEWER_DATA4, cookie, *W);
209 B += 4;
210 }
211 switch ( dataSize & 3 )
212 {
213 case 0:
214 default:
215 break;
216 case 1:
217 m_PostMessage(WM_TNBVIEWER_DATA1, cookie, B[0]);
218 break;
219 case 2:
220 m_PostMessage(WM_TNBVIEWER_DATA2, cookie, B[0] | (B[1] << 8));
221 break;
222 case 3:
223 m_PostMessage(WM_TNBVIEWER_DATA3, cookie, B[0] | (B[1] << 8) | (B[2] << 16));
224 break;
225 }
226 }
227 }
228 HWND m_hPostWnd;
229 #endif
230};
231
232
233
248{
249public:
250
255 CReportViewerEx(void) : m_cookieBase(0), m_atom(NULL)
256 {
257 }
258
261 {
262 m_DeleteAtom();
263 }
264
269 void SetKind(DWORD kind)
270 {
271 m_DeleteAtom();
272 m_cookieBase = kind;
273 }
274
281 bool SetKind(LPCTSTR lpszTitle)
282 {
283 ATOM a = ::GlobalAddAtom(lpszTitle);
284 if ( a != NULL )
285 {
286 if ( m_atom != a )
287 {
288 m_DeleteAtom();
289 m_atom = a;
290 }
291 m_cookieBase = TNBVIW_KIND_ATOM | m_atom;
292 return true;
293 }
294 return false;
295 }
296
302 bool HasKind(void) const
303 {
304 return m_cookieBase != 0;
305 }
306
312 bool IsValid(void) const
313 {
314 return m_viewer.IsValid();
315 }
316
322 void Invalid(void)
323 {
324 m_viewer.Invalid();
325 }
326
333 void ToViewer(size_t sizeData, LPCVOID lpcvData, DWORD dire = 0)
334 {
335 EXCLUSIVE( this );
336 m_viewer.ToViewer(sizeData, lpcvData, dire | m_cookieBase);
337 }
338
343 void ToViewer(LPCTSTR lpszText)
344 {
345 EXCLUSIVE( this );
346 m_viewer.ToViewer(lpszText, TNBVIW_TYPE_RAWTEXT | m_cookieBase);
347 }
348
349private:
351 void m_DeleteAtom(void)
352 {
353 if ( m_atom != NULL )
354 {
355 ::GlobalDeleteAtom(m_atom);
356 m_atom = NULL;
357 }
358 }
359 ATOM m_atom;
360 DWORD m_cookieBase;
361 CReportViewer m_viewer;
362};
363
364
365
366}; // TNB
文字列管理関係のヘッダ
同期処理関係のヘッダ
TNBレポートビュワー
bool HasKind(void) const
[確認] 種類設定済み確認.
~CReportViewerEx(void)
デストラクタ
void Invalid(void)
[設定] 無効化.
bool IsValid(void) const
[確認] 有効確認.
void ToViewer(LPCTSTR lpszText)
[出力] 文字列出力.
CReportViewerEx(void)
コンストラクタ.
bool SetKind(LPCTSTR lpszTitle)
[設定] 種類設定.
void SetKind(DWORD kind)
[設定] 種類設定.
void ToViewer(size_t sizeData, LPCVOID lpcvData, DWORD dire=0)
[出力] ダンプ出力.
TNBレポートビュワー
void ToViewer(size_t sizeData, LPCVOID lpcvData, DWORD cookie)
[出力] ダンプ出力.
void Invalid(void)
[設定] 無効化.
bool IsValid(void) const
[確認] 有効確認.
CReportViewer(void)
コンストラクタ.
void ToViewer(LPCTSTR lpszText, DWORD cookie)
[出力] 文字列出力.
bool IsEmpty(void) const
[確認] 空チェック
Definition: TnbStr.h:528
size_t GetLength(void) const
[取得] 文字列長
Definition: TnbStr.h:518
Section排他管理クラス
Definition: TnbSync.h:125
#define EXCLUSIVE(CLS)
簡易排他制御マクロ.
Definition: TnbSync.h:788
TNB Library
Definition: TnbDoxyTitle.txt:2