• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

UART通信を用いた組み込みデバッグ用途向けメモリモニタ


Commit MetaInfo

修订版33fa799c02906b9432d87987a873c9e2a89c7e07 (tree)
时间2018-04-22 22:03:47
作者Yasushi Tanaka <tanaka_yasushi2008@yaho...>
CommiterYasushi Tanaka

Log Message

スクリーンは完成

更改概述

差异

--- a/DebugMonitor/DebugMonitor.vcxproj
+++ b/DebugMonitor/DebugMonitor.vcxproj
@@ -58,7 +58,7 @@
5858 <Link>
5959 <SubSystem>Windows</SubSystem>
6060 <GenerateDebugInformation>true</GenerateDebugInformation>
61- <AdditionalDependencies>imm32.lib;%(AdditionalDependencies)</AdditionalDependencies>
61+ <AdditionalDependencies>imm32.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
6262 </Link>
6363 </ItemDefinitionGroup>
6464 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
--- a/DebugMonitor/src/framework/screen.c
+++ b/DebugMonitor/src/framework/screen.c
@@ -29,34 +29,16 @@
2929 #define SCREEN_COLOR_BLACK (RGB(0, 0, 0))
3030
3131 /*
32- * 構造体
32+ * 仮想キャラクタ構造体
3333 */
34-typedef struct _SCREEN_CHR
34+typedef struct _SCREEN_VIRT_CHR
3535 {
3636 /* 現在のキャラクタ */
37- wchar_t curr_chr;
37+ SCREEN_CHR current;
3838
39- /* 現在の全角左右フラグ(TRUEで左) */
40- BOOL curr_lr;
41-
42- /* 現在のフォアグラウンドカラー */
43- COLORREF curr_fore;
44-
45- /* 現在のバックグラウンドカラー */
46- COLORREF curr_back;
47-
48- /* 過去のキャラクタ */
49- wchar_t prev_chr;
50-
51- /* 過去の全角左右フラグ(TRUEで左) */
52- BOOL prev_lr;
53-
54- /* 過去のフォアグラウンドカラー */
55- COLORREF prev_fore;
56-
57- /* 過去のバックグラウンドカラー */
58- COLORREF prev_back;
59-} SCREEN_CHR;
39+ /* 描画したキャラクタ */
40+ SCREEN_CHR draw;
41+} SCREEN_VIRT_CHR;
6042
6143 /*
6244 * static変数
@@ -78,7 +60,7 @@ static LONG g_lScreenExtWidth;
7860 static LONG g_lScreenExtHeight;
7961
8062 /* 仮想画面 */
81-static SCREEN_CHR g_ScreenAry[SCREEN_HEIGHT_MAX][SCREEN_WIDTH_MAX];
63+static SCREEN_VIRT_CHR g_ScreenAry[SCREEN_HEIGHT_MAX][SCREEN_WIDTH_MAX];
8264
8365 /* 現在のフォアグラウンドカラー */
8466 static COLORREF g_ForeTextColor;
@@ -91,6 +73,74 @@ static BOOL g_bRequestDraw;
9173
9274 /*
9375 * スクリーン
76+ * 描画比較
77+ */
78+static BOOL screen_drawcompare(LONG x, LONG y)
79+{
80+ BOOL bCompare;
81+
82+ assert(0 <= x);
83+ assert(SCREEN_WIDTH_MAX > x);
84+ assert(0 <= y);
85+ assert(SCREEN_HEIGHT_MAX > y);
86+
87+ /* 比較フラグをTRUEに */
88+ bCompare = TRUE;
89+
90+ /* キャラクタ */
91+ if (g_ScreenAry[y][x].current.chr != g_ScreenAry[y][x].draw.chr)
92+ {
93+ bCompare = FALSE;
94+ }
95+
96+ /* 左右 */
97+ if (g_ScreenAry[y][x].current.lr != g_ScreenAry[y][x].draw.lr)
98+ {
99+ bCompare = FALSE;
100+ }
101+
102+ /* フォアグラウンドカラー */
103+ if (g_ScreenAry[y][x].current.fore != g_ScreenAry[y][x].draw.fore)
104+ {
105+ bCompare = FALSE;
106+ }
107+
108+ /* バックグラウンドカラー */
109+ if (g_ScreenAry[y][x].current.back != g_ScreenAry[y][x].draw.back)
110+ {
111+ bCompare = FALSE;
112+ }
113+
114+ /* 比較結果を返す */
115+ return bCompare;
116+}
117+
118+/*
119+ * スクリーン
120+ * 描画要求フラグ設定
121+ */
122+static void screen_requestdraw(LONG x, LONG y)
123+{
124+ BOOL bCompare;
125+
126+ assert(0 <= x);
127+ assert(x < SCREEN_WIDTH_MAX);
128+ assert(0 <= y);
129+ assert(y < SCREEN_HEIGHT_MAX);
130+
131+ /* 比較 */
132+ bCompare = screen_drawcompare(x, y);
133+
134+ /* もしFALSEであれば、描画要求フラグを設定 */
135+ if (FALSE == bCompare)
136+ {
137+ /* 描画要求フラグを設定 */
138+ g_bRequestDraw = TRUE;
139+ }
140+}
141+
142+/*
143+ * スクリーン
94144 * 文字列セット
95145 */
96146 static void screen_settextw(UINT x, UINT y, COLORREF fore, COLORREF back, const wchar_t *format, ...)
@@ -130,10 +180,13 @@ static void screen_settextw(UINT x, UINT y, COLORREF fore, COLORREF back, const
130180 if (0x0100 > buf[offset])
131181 {
132182 /* 半角 */
133- g_ScreenAry[y][x].curr_chr = buf[offset];
134- g_ScreenAry[y][x].curr_lr = TRUE;
135- g_ScreenAry[y][x].curr_fore = fore;
136- g_ScreenAry[y][x].curr_back = back;
183+ g_ScreenAry[y][x].current.chr = buf[offset];
184+ g_ScreenAry[y][x].current.lr = TRUE;
185+ g_ScreenAry[y][x].current.fore = fore;
186+ g_ScreenAry[y][x].current.back = back;
187+
188+ /* 描画要求フラグ */
189+ screen_requestdraw((LONG)x, (LONG)y);
137190
138191 /* 半角は+1 */
139192 x++;
@@ -144,16 +197,22 @@ static void screen_settextw(UINT x, UINT y, COLORREF fore, COLORREF back, const
144197 if ((SCREEN_WIDTH_MAX - 1) > x)
145198 {
146199 /* Leftセット */
147- g_ScreenAry[y][x + 0].curr_chr = buf[offset];
148- g_ScreenAry[y][x + 0].curr_lr = TRUE;
149- g_ScreenAry[y][x + 0].curr_fore = fore;
150- g_ScreenAry[y][x + 0].curr_back = back;
200+ g_ScreenAry[y][x + 0].current.chr = buf[offset];
201+ g_ScreenAry[y][x + 0].current.lr = TRUE;
202+ g_ScreenAry[y][x + 0].current.fore = fore;
203+ g_ScreenAry[y][x + 0].current.back = back;
151204
152- /* Leftセット */
153- g_ScreenAry[y][x + 1].curr_chr = buf[offset];
154- g_ScreenAry[y][x + 1].curr_lr = FALSE;
155- g_ScreenAry[y][x + 1].curr_fore = fore;
156- g_ScreenAry[y][x + 1].curr_back = back;
205+ /* 描画要求フラグ(Left) */
206+ screen_requestdraw((LONG)(x + 0), (LONG)y);
207+
208+ /* Rightセット */
209+ g_ScreenAry[y][x + 1].current.chr = buf[offset];
210+ g_ScreenAry[y][x + 1].current.lr = FALSE;
211+ g_ScreenAry[y][x + 1].current.fore = fore;
212+ g_ScreenAry[y][x + 1].current.back = back;
213+
214+ /* 描画要求フラグ(Right) */
215+ screen_requestdraw((LONG)(x + 1), (LONG)y);
157216
158217 /* 全角は+2 */
159218 x += 2;
@@ -167,9 +226,6 @@ static void screen_settextw(UINT x, UINT y, COLORREF fore, COLORREF back, const
167226
168227 /* 次のオフセットに進む */
169228 offset++;
170-
171- /* 描画要求あり */
172- g_bRequestDraw = TRUE;
173229 }
174230 }
175231
@@ -225,10 +281,12 @@ static void screen_calcwidthheight(HWND hWnd)
225281 * スクリーン
226282 * WM_CREATEメッセージハンドラ
227283 */
228-static BOOL screen_oncreate(HWND hWnd, const CREATESTRUCT *lpcs)
284+static BOOL screen_oncreate(HWND hWnd)
229285 {
230- UINT x;
231- UINT y;
286+ LONG x;
287+ LONG y;
288+
289+ assert(NULL != hWnd);
232290
233291 /* 仮想画面を初期化 */
234292 for (y = 0; y < SCREEN_HEIGHT_MAX; y++)
@@ -236,16 +294,16 @@ static BOOL screen_oncreate(HWND hWnd, const CREATESTRUCT *lpcs)
236294 for (x = 0; x < SCREEN_WIDTH_MAX; x++)
237295 {
238296 /* 現在のキャラクタは半角スペース、文字:黒色、背景:白色とする */
239- g_ScreenAry[y][x].curr_chr = L' ';
240- g_ScreenAry[y][x].curr_lr = TRUE;
241- g_ScreenAry[y][x].curr_fore = SCREEN_COLOR_BLACK;
242- g_ScreenAry[y][x].curr_back = SCREEN_COLOR_WHITE;
243-
244- /* 過去のキャラクタはヌル文字とする */
245- g_ScreenAry[y][x].prev_chr = L'\0';
246- g_ScreenAry[y][x].prev_lr = TRUE;
247- g_ScreenAry[y][x].prev_fore = SCREEN_COLOR_BLACK;
248- g_ScreenAry[y][x].prev_back = SCREEN_COLOR_WHITE;
297+ g_ScreenAry[y][x].current.chr = L' ';
298+ g_ScreenAry[y][x].current.lr = TRUE;
299+ g_ScreenAry[y][x].current.fore = SCREEN_COLOR_BLACK;
300+ g_ScreenAry[y][x].current.back = SCREEN_COLOR_WHITE;
301+
302+ /* 描画したキャラクタはヌル文字とする */
303+ g_ScreenAry[y][x].draw.chr = L'\0';
304+ g_ScreenAry[y][x].draw.lr = TRUE;
305+ g_ScreenAry[y][x].draw.fore = SCREEN_COLOR_BLACK;
306+ g_ScreenAry[y][x].draw.back = SCREEN_COLOR_WHITE;
249307 }
250308 }
251309
@@ -263,6 +321,12 @@ static void screen_ondestroy(HWND hWnd)
263321 {
264322 assert(NULL != hWnd);
265323 assert(hWnd == g_hScreenWnd);
324+
325+ /* ウィンドウが無効であることを示す */
326+ g_hScreenWnd = NULL;
327+
328+ /* 描画要求は必要ない */
329+ g_bRequestDraw = FALSE;
266330 }
267331
268332 /*
@@ -282,65 +346,60 @@ static void screen_onsize(HWND hWnd, LONG cx, LONG cy)
282346 InvalidateRect(hWnd, NULL, TRUE);
283347
284348 /* テスト */
285- screen_settextw(0, 0, SCREEN_COLOR_WHITE, SCREEN_COLOR_BLACK, L"幅=%d文字 高さ=%d文字", g_lScreenWidth, g_lScreenHeight);
349+ screen_settextw(90, 0, SCREEN_COLOR_WHITE, SCREEN_COLOR_BLACK, L"幅=%d文字 高さ=%d文字", g_lScreenWidth, g_lScreenHeight);
286350 }
287351
288352 /*
289353 * スクリーン
290354 * WM_ERASEBKGNDメッセージハンドラ
291355 */
292-static void screen_onerasebkgnd(HDC hDC)
293-{
294- /* Todo:余り領域があれば描画 */
295-}
296-
297-/*
298- * スクリーン
299- * 描画比較
300- */
301-static BOOL screen_drawcompare(LONG x, LONG y)
356+static void screen_onerasebkgnd(HWND hWnd, HDC hDC)
302357 {
303- BOOL bCompare;
304-
305- assert(0 <= x);
306- assert(SCREEN_WIDTH_MAX > x);
307- assert(0 <= y);
308- assert(SCREEN_HEIGHT_MAX > y);
358+ HBRUSH hBrush;
359+ RECT rect;
309360
310- /* 比較フラグをTRUEに */
311- bCompare = TRUE;
361+ assert(NULL != hWnd);
362+ assert(NULL != hDC);
312363
313- /* キャラクタ */
314- if (g_ScreenAry[y][x].curr_chr != g_ScreenAry[y][x].prev_chr)
364+ /* 余り領域がなければ何もしない */
365+ if ((0 == g_lScreenExtWidth) && (0 == g_lScreenExtHeight))
315366 {
316- bCompare = FALSE;
367+ return;
317368 }
318369
319- /* 左右 */
320- if (g_ScreenAry[y][x].curr_lr != g_ScreenAry[y][x].prev_lr)
321- {
322- bCompare = FALSE;
323- }
370+ /* 背景ブラシを取得 */
371+ hBrush = GetSysColorBrush(COLOR_WINDOW);
324372
325- /* フォアグラウンドカラー */
326- if (g_ScreenAry[y][x].curr_fore != g_ScreenAry[y][x].prev_fore)
373+ /* 右側の余り領域を描画 */
374+ if (0 != g_lScreenExtWidth)
327375 {
328- bCompare = FALSE;
376+ /* クライアント領域を取得 */
377+ GetClientRect(hWnd, &rect);
378+
379+ /* rect.leftのみ修正 */
380+ rect.left = SCREEN_WIDTH_MAX + g_tm.tmAveCharWidth;
381+
382+ /* ブラシで塗りつぶす */
383+ FillRect(hDC, &rect, hBrush);
329384 }
330385
331- /* バックグラウンドカラー */
332- if (g_ScreenAry[y][x].curr_back != g_ScreenAry[y][x].prev_back)
386+ /* 下側の余り領域を描画 */
387+ if (0 != g_lScreenExtHeight)
333388 {
334- bCompare = FALSE;
335- }
389+ /* クライアント領域を取得 */
390+ GetClientRect(hWnd, &rect);
336391
337- /* 比較結果を返す */
338- return bCompare;
392+ /* rect.topのみ修正 */
393+ rect.top = SCREEN_HEIGHT_MAX + g_tmAllHeight;
394+
395+ /* ブラシで塗りつぶす */
396+ FillRect(hDC, &rect, hBrush);
397+ }
339398 }
340399
341400 /*
342401 * スクリーン
343- * 描画1キャラクタ
402+ * キャラクタ描画
344403 */
345404 static void screen_drawone(HDC hDC, LONG x, LONG y)
346405 {
@@ -355,33 +414,33 @@ static void screen_drawone(HDC hDC, LONG x, LONG y)
355414 assert(SCREEN_HEIGHT_MAX > y);
356415
357416 /* 右側は描画しない */
358- if (FALSE == g_ScreenAry[y][x].curr_lr)
417+ if (FALSE == g_ScreenAry[y][x].current.lr)
359418 {
360419 return;
361420 }
362421
363422 /* フォアグラウンドカラーを更新 */
364- if (g_ScreenAry[y][x].curr_fore != g_ForeTextColor)
423+ if (g_ScreenAry[y][x].current.fore != g_ForeTextColor)
365424 {
366- clrPrev = SetTextColor(hDC, g_ScreenAry[y][x].curr_fore);
425+ clrPrev = SetTextColor(hDC, g_ScreenAry[y][x].current.fore);
367426 assert(CLR_INVALID != clrPrev);
368427 if (CLR_INVALID == clrPrev)
369428 {
370429 return;
371430 }
372- g_ForeTextColor = g_ScreenAry[y][x].curr_fore;
431+ g_ForeTextColor = g_ScreenAry[y][x].current.fore;
373432 }
374433
375434 /* バックグラウンドカラーを更新 */
376- if (g_ScreenAry[y][x].curr_back != g_BackTextColor)
435+ if (g_ScreenAry[y][x].current.back != g_BackTextColor)
377436 {
378- clrPrev = SetBkColor(hDC, g_ScreenAry[y][x].curr_back);
437+ clrPrev = SetBkColor(hDC, g_ScreenAry[y][x].current.back);
379438 assert(CLR_INVALID != clrPrev);
380439 if (CLR_INVALID == clrPrev)
381440 {
382441 return;
383442 }
384- g_BackTextColor = g_ScreenAry[y][x].curr_back;
443+ g_BackTextColor = g_ScreenAry[y][x].current.back;
385444 }
386445
387446 /* 担当矩形を選択 */
@@ -391,13 +450,13 @@ static void screen_drawone(HDC hDC, LONG x, LONG y)
391450 rect.bottom = rect.top + g_tmAllHeight;
392451
393452 /* 全角文字の場合は幅を2倍にする */
394- if (0x0100 <= g_ScreenAry[y][x].curr_chr)
453+ if (0x0100 <= g_ScreenAry[y][x].current.chr)
395454 {
396455 rect.right += g_tm.tmAveCharWidth;
397456 }
398457
399458 /* テキストを描画 */
400- bResult = ExtTextOut(hDC, rect.left, rect.top, ETO_OPAQUE, &rect, (LPWSTR)&g_ScreenAry[y][x].curr_chr, 1, NULL);
459+ bResult = ExtTextOut(hDC, rect.left, rect.top, ETO_OPAQUE, &rect, (LPWSTR)&g_ScreenAry[y][x].current.chr, 1, NULL);
401460 assert(FALSE != bResult);
402461 if (FALSE == bResult)
403462 {
@@ -420,31 +479,31 @@ static void screen_drawupate(LONG x, LONG y)
420479 assert(0 < g_lScreenWidth);
421480
422481 /* キャラクタ */
423- g_ScreenAry[y][x].prev_chr = g_ScreenAry[y][x].curr_chr;
482+ g_ScreenAry[y][x].draw.chr = g_ScreenAry[y][x].current.chr;
424483
425484 /* 左右 */
426- g_ScreenAry[y][x].prev_lr = g_ScreenAry[y][x].curr_lr;
485+ g_ScreenAry[y][x].draw.lr = g_ScreenAry[y][x].current.lr;
427486
428487 /* フォアグラウンドカラー */
429- g_ScreenAry[y][x].prev_fore = g_ScreenAry[y][x].curr_fore;
488+ g_ScreenAry[y][x].draw.fore = g_ScreenAry[y][x].current.fore;
430489
431490 /* バックグラウンドカラー */
432- g_ScreenAry[y][x].prev_back = g_ScreenAry[y][x].curr_back;
491+ g_ScreenAry[y][x].draw.back = g_ScreenAry[y][x].current.back;
433492
434493 /* 描画範囲のx終端以外でなく、かつキャラクタが0x0100以上(全角)で、Lの場合 */
435- if ((x < (g_lScreenWidth - 1)) && (0x0100 <= g_ScreenAry[y][x].curr_chr) && (TRUE == g_ScreenAry[y][x].curr_lr))
494+ if ((x < (g_lScreenWidth - 1)) && (0x0100 <= g_ScreenAry[y][x].current.chr) && (TRUE == g_ScreenAry[y][x].current.lr))
436495 {
437- /* 一つ右側も描画しているので、右のprevを更新 */
438- g_ScreenAry[y][x + 1].prev_chr = g_ScreenAry[y][x].curr_chr;
496+ /* 一つ右側も描画しているので、右のdrawを更新 */
497+ g_ScreenAry[y][x + 1].draw.chr = g_ScreenAry[y][x].current.chr;
439498
440499 /* 左右は右にする */
441- g_ScreenAry[y][x + 1].prev_lr = FALSE;
500+ g_ScreenAry[y][x + 1].draw.lr = FALSE;
442501
443502 /* フォアグラウンドカラー */
444- g_ScreenAry[y][x + 1].prev_fore = g_ScreenAry[y][x].curr_fore;
503+ g_ScreenAry[y][x + 1].draw.fore = g_ScreenAry[y][x].current.fore;
445504
446505 /* バックグラウンドカラー */
447- g_ScreenAry[y][x + 1].prev_back = g_ScreenAry[y][x].curr_back;
506+ g_ScreenAry[y][x + 1].draw.back = g_ScreenAry[y][x].current.back;
448507 }
449508 }
450509
@@ -474,25 +533,25 @@ static void screen_drawmain(HWND hWnd, HDC hDC)
474533 return;
475534 }
476535
477- /* フォアグラウンドカラーを選択(黒) */
478- clrPrev = SetTextColor(hDC, SCREEN_COLOR_BLACK);
536+ /* 最初のフォアグラウンドカラーを選択(白色) */
537+ clrPrev = SetTextColor(hDC, SCREEN_COLOR_WHITE);
479538 assert(CLR_INVALID != clrPrev);
480539 if (CLR_INVALID == clrPrev)
481540 {
482541 SelectObject(hDC, hDefFont);
483542 return;
484543 }
485- g_ForeTextColor = SCREEN_COLOR_BLACK;
544+ g_ForeTextColor = SCREEN_COLOR_WHITE;
486545
487- /* バックグラウンドカラーを選択(白) */
488- clrPrev = SetBkColor(hDC, SCREEN_COLOR_WHITE);
546+ /* 最初のバックグラウンドカラーを選択(黒色) */
547+ clrPrev = SetBkColor(hDC, SCREEN_COLOR_BLACK);
489548 assert(CLR_INVALID != clrPrev);
490549 if (CLR_INVALID == clrPrev)
491550 {
492551 SelectObject(hDC, hDefFont);
493552 return;
494553 }
495- g_BackTextColor = SCREEN_COLOR_WHITE;
554+ g_BackTextColor = SCREEN_COLOR_BLACK;
496555
497556 /* ループ */
498557 for (y = 0; y < g_lScreenHeight; y++)
@@ -505,6 +564,7 @@ static void screen_drawmain(HWND hWnd, HDC hDC)
505564 /* 一致していない場合、描画と更新 */
506565 if (FALSE == bCompare)
507566 {
567+ /* このキャラクタは描画する必要がある */
508568 screen_drawone(hDC, x, y);
509569 screen_drawupate(x, y);
510570 }
@@ -513,6 +573,9 @@ static void screen_drawmain(HWND hWnd, HDC hDC)
513573
514574 /* フォントを戻す */
515575 SelectObject(hDC, hDefFont);
576+
577+ /* 描画要求なし */
578+ g_bRequestDraw = FALSE;
516579 }
517580
518581 /*
@@ -521,21 +584,21 @@ static void screen_drawmain(HWND hWnd, HDC hDC)
521584 */
522585 static void screen_onpaint(HWND hWnd)
523586 {
524- int x;
525- int y;
587+ LONG x;
588+ LONG y;
526589 HDC hDC;
527590 PAINTSTRUCT ps;
528591
529592 assert(NULL != hWnd);
530593
531- /* スクリーンの表示範囲について、過去キャラクタをヌル文字にする */
594+ /* スクリーンの表示範囲について、描画キャラクタをヌル文字にする */
532595 assert(0 <= g_lScreenHeight);
533596 assert(0 <= g_lScreenWidth);
534597 for (y = 0; y < g_lScreenHeight; y++)
535598 {
536599 for (x = 0; x < g_lScreenWidth; x++)
537600 {
538- g_ScreenAry[y][x].prev_chr = L'\0';
601+ g_ScreenAry[y][x].draw.chr = L'\0';
539602 }
540603 }
541604
@@ -552,21 +615,43 @@ static void screen_onpaint(HWND hWnd)
552615
553616 /*
554617 * スクリーン
618+ * アイドル描画
619+ */
620+static void screen_drawidle(void)
621+{
622+ HDC hDC;
623+
624+ assert(NULL != g_hScreenWnd);
625+
626+ /* デバイスコンテキストを取得 */
627+ hDC = GetDC(g_hScreenWnd);
628+ assert(NULL != hDC);
629+ if (NULL == hDC)
630+ {
631+ return;
632+ }
633+
634+ /* 描画共通 */
635+ screen_drawmain(g_hScreenWnd, hDC);
636+
637+ /* デバイスコンテキストを解放 */
638+ ReleaseDC(g_hScreenWnd, hDC);
639+}
640+
641+/*
642+ * スクリーン
555643 * ウィンドウプロシージャ
556644 */
557645 static LRESULT CALLBACK screen_proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
558646 {
559647 BOOL bResult;
560- const CREATESTRUCT *lpcs;
561648
562649 switch (uMsg)
563650 {
564651 /* ウィンドウが作成された */
565652 case WM_CREATE:
566653 /* ハンドラを呼び出す */
567- lpcs = (const CREATESTRUCT *)lParam;
568- assert(NULL != lpcs);
569- bResult = screen_oncreate(hWnd, lpcs);
654+ bResult = screen_oncreate(hWnd);
570655 assert(FALSE != bResult);
571656
572657 /* ハンドラの結果によって、CreateWindowを失敗させる */
@@ -577,8 +662,10 @@ static LRESULT CALLBACK screen_proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM
577662 }
578663
579664 /* テスト */
580- screen_settextw(1, 1, RGB(255, 255, 0), RGB(128, 128, 128), L"文字平均幅=%d", g_tm.tmAveCharWidth);
581- screen_settextw(1, 2, RGB(128, 128, 128), RGB(255, 255, 0), L"文字最大幅=%d", g_tm.tmMaxCharWidth);
665+ screen_settextw(90, 1, RGB(255, 255, 0), RGB(128, 128, 128), L"文字平均幅 =%d", g_tm.tmAveCharWidth);
666+ screen_settextw(90, 2, RGB(128, 128, 128), RGB(255, 255, 0), L"文字最大幅 =%d", g_tm.tmMaxCharWidth);
667+ screen_settextw(90, 3, RGB(128, 128, 128), RGB(255, 255, 0), L"文字高さ =%d", g_tm.tmHeight + g_tm.tmExternalLeading);
668+ screen_settextw(90, 4, RGB(128, 128, 128), RGB(255, 255, 0), L"文字最大高 =%d", g_tmAllHeight);
582669
583670 /* 正常終了 */
584671 return 0;
@@ -598,7 +685,7 @@ static LRESULT CALLBACK screen_proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM
598685 /* 背景を再描画する */
599686 case WM_ERASEBKGND:
600687 /* ハンドラを呼び出す */
601- screen_onerasebkgnd((HDC)wParam);
688+ screen_onerasebkgnd(hWnd, (HDC)wParam);
602689 /* 自力でを背景を描画した場合は非ゼロを返す必要がある */
603690 return 1;
604691
@@ -674,45 +761,45 @@ BOOL screen_init(HWND hParentWnd, LONG lWidth, LONG lHeight)
674761 BOOL bResult;
675762
676763 /* static変数を初期化 */
677- g_hScreenWnd = NULL;
678- g_lScreenWidth = 0;
679- g_lScreenHeight = 0;
680- g_lScreenExtWidth = 0;
681- g_lScreenExtHeight = 0;
682- ZeroMemory(g_ScreenAry, sizeof(g_ScreenAry));
683- g_bRequestDraw = TRUE;
684-
685- /* ウィンドウクラスの登録 */
686- bResult = screen_register();
687- assert(FALSE != bResult);
688- if (FALSE == bResult)
689- {
690- return FALSE;
691- }
764+g_hScreenWnd = NULL;
765+g_lScreenWidth = 0;
766+g_lScreenHeight = 0;
767+g_lScreenExtWidth = 0;
768+g_lScreenExtHeight = 0;
769+ZeroMemory(g_ScreenAry, sizeof(g_ScreenAry));
770+g_bRequestDraw = TRUE;
771+
772+/* ウィンドウクラスの登録 */
773+bResult = screen_register();
774+assert(FALSE != bResult);
775+if (FALSE == bResult)
776+{
777+ return FALSE;
778+}
692779
693- /* ウィンドウの作成 */
694- g_hScreenWnd = CreateWindow(
695- SCREEN_CLASS_NAME,
696- L"",
697- WS_CHILD | WS_VISIBLE,
698- 0,
699- 0,
700- lWidth,
701- lHeight,
702- hParentWnd,
703- NULL,
704- g_hAppInstance,
705- NULL);
706-
707- /* ウィンドウが作成できたかチェック */
708- assert(NULL != g_hScreenWnd);
709- if (NULL == g_hScreenWnd)
710- {
711- return FALSE;
712- }
780+/* ウィンドウの作成 */
781+g_hScreenWnd = CreateWindow(
782+ SCREEN_CLASS_NAME,
783+ SCREEN_CLASS_NAME,
784+ WS_CHILD | WS_VISIBLE,
785+ 0,
786+ 0,
787+ lWidth,
788+ lHeight,
789+ hParentWnd,
790+ NULL,
791+ g_hAppInstance,
792+ NULL);
793+
794+/* ウィンドウが作成できたかチェック */
795+assert(NULL != g_hScreenWnd);
796+if (NULL == g_hScreenWnd)
797+{
798+ return FALSE;
799+}
713800
714- /* 作成成功 */
715- return TRUE;
801+/* 作成成功 */
802+return TRUE;
716803 }
717804
718805 /*
@@ -732,3 +819,80 @@ void screen_resize(LONG lWidth, LONG lHeight)
732819 return;
733820 }
734821 }
822+
823+/*
824+ * スクリーン
825+ * アイドル
826+ */
827+void screen_idle(void)
828+{
829+ SYSTEMTIME st;
830+
831+ /* ウィンドウが有効で、描画要求が存在する場合 */
832+ if ((NULL != g_hScreenWnd) && (FALSE != g_bRequestDraw))
833+ {
834+ /* アイドル描画 */
835+ screen_drawidle();
836+ }
837+
838+ GetLocalTime(&st);
839+ screen_settextw(90, 5, SCREEN_COLOR_WHITE, SCREEN_COLOR_BLACK, L"%02d:%02d:%02d", st.wHour, st.wMinute, st.wSecond);
840+}
841+
842+/*
843+ * スクリーン
844+ * 矩形コピー
845+ */
846+void screen_copyregion(LONG left, LONG top, LONG width, LONG height, const SCREEN_CHR *ptr)
847+{
848+ LONG x;
849+ LONG y;
850+ LONG copy_width;
851+ LONG copy_height;
852+
853+ assert(0 <= left);
854+ assert(0 <= top);
855+ assert(0 <= width);
856+ assert(0 <= height);
857+ assert(NULL != ptr);
858+
859+ /* コピー幅を算出 */
860+ copy_width = width;
861+ if ((left + copy_width) > SCREEN_WIDTH_MAX)
862+ {
863+ copy_width = SCREEN_WIDTH_MAX - left;
864+ }
865+ if (0 >= copy_width)
866+ {
867+ /* コピーできる幅が0文字またはマイナス */
868+ return;
869+ }
870+
871+ /* コピー高さを算出 */
872+ copy_height = height;
873+ if ((top + copy_height) > SCREEN_HEIGHT_MAX)
874+ {
875+ copy_height = SCREEN_HEIGHT_MAX - top;
876+ }
877+ if (0 >= copy_height)
878+ {
879+ /* コピーできる高さが0文字またはマイナス */
880+ return;
881+ }
882+
883+ /* ループ */
884+ for (y = 0; y < copy_height; y++)
885+ {
886+ for (x = 0; x < copy_width; x++)
887+ {
888+ /* コピー */
889+ g_ScreenAry[y + top][x + left].current = ptr[x];
890+
891+ /* 比較して描画要求 */
892+ screen_requestdraw(x + left, y + top);
893+ }
894+
895+ /* ptrを進める */
896+ ptr += width;
897+ }
898+}
--- a/DebugMonitor/src/framework/screen.h
+++ b/DebugMonitor/src/framework/screen.h
@@ -8,6 +8,24 @@
88 #pragma once
99
1010 /*
11+ * キャラクタ構造体
12+ */
13+typedef struct _SCREEN_CHR
14+{
15+ /* キャラクタ(0x0100未満は半角、0x0100以上は全角 */
16+ wchar_t chr;
17+
18+ /* 全角の左・右フラグ(TRUE:左、FALSE:右)。半角は常にTRUE */
19+ BOOL lr;
20+
21+ /* フォアグラウンドカラー(テキスト色) */
22+ COLORREF fore;
23+
24+ /* バックグラウンドカラー(背景色) */
25+ COLORREF back;
26+} SCREEN_CHR;
27+
28+/*
1129 * グローバル関数
1230 */
1331
@@ -16,3 +34,9 @@ BOOL screen_init(HWND hParentWnd, LONG lWidth, LONG lHeight);
1634
1735 /* リサイズ */
1836 void screen_resize(LONG lWidth, LONG lHeight);
37+
38+/* アイドル */
39+void screen_idle(void);
40+
41+/* 矩形コピー */
42+void screen_copyregion(LONG left, LONG top, LONG width, LONG height, const SCREEN_CHR *ptr);
--- a/DebugMonitor/src/framework/winmain.c
+++ b/DebugMonitor/src/framework/winmain.c
@@ -23,7 +23,7 @@
2323 #define WINDOW_FONT_FACENAME L"MS ゴシック"
2424
2525 /* フォントのポイント数 */
26-#define WINDOW_FONT_POINT 12
26+#define WINDOW_FONT_POINT 9
2727
2828 /* フォントの高さに加えるマージン(%) */
2929 #define WINDOW_FONT_HEIGHT_MERGIN 10
@@ -307,9 +307,20 @@ static BOOL OnCreateFont(HWND hWnd)
307307 */
308308 static BOOL OnCreate(HWND hWnd, const CREATESTRUCT *lpcs)
309309 {
310+ BOOL bResult;
311+ MMRESULT mmResult;
312+
310313 assert(NULL != hWnd);
311314 assert(NULL != lpcs);
312315
316+ /* マルチメディアタイマの最小分解能を設定 */
317+ mmResult = timeBeginPeriod(1);
318+ assert(TIMERR_NOERROR == mmResult);
319+ if (TIMERR_NOERROR != mmResult)
320+ {
321+ return FALSE;
322+ }
323+
313324 /* フォントを作成 */
314325 if (FALSE == OnCreateFont(hWnd))
315326 {
@@ -320,7 +331,12 @@ static BOOL OnCreate(HWND hWnd, const CREATESTRUCT *lpcs)
320331 CalcSubWidthSize(hWnd);
321332
322333 /* スクリーンを作成 */
323- screen_init(hWnd, g_lScreenWidth, g_lScreenHeight);
334+ bResult = screen_init(hWnd, g_lScreenWidth, g_lScreenHeight);
335+ assert(FALSE != bResult);
336+ if (FALSE == bResult)
337+ {
338+ return FALSE;
339+ }
324340
325341 /* 正常終了 */
326342 return TRUE;
@@ -341,16 +357,18 @@ static void OnDestroy(HWND hWnd)
341357 DeleteObject(g_hFont);
342358 g_hFont = NULL;
343359 }
360+
361+ /* マルチメディアタイマの最小分解能を復元 */
362+ timeEndPeriod(1);
344363 }
345364
346365 /*
347366 * WinMain
348367 * WM_SIZEメッセージハンドラ
349368 */
350-static void OnSize(HWND hWnd, LONG cx, LONG cy)
369+static void OnSize(HWND hWnd)
351370 {
352371 assert(NULL != hWnd);
353- assert(hWnd == g_hFrameWnd);
354372
355373 /* スクリーンとログのサイズを算出 */
356374 CalcSubWidthSize(hWnd);
@@ -399,7 +417,7 @@ static LRESULT CALLBACK FrameWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPA
399417 /* ウィンドウがリサイズされた */
400418 case WM_SIZE:
401419 /* ハンドラを呼び出す */
402- OnSize(hWnd, (LONG)LOWORD(lParam), (LONG)HIWORD(lParam));
420+ OnSize(hWnd);
403421 return 0;
404422
405423 /* その他 */
@@ -485,6 +503,7 @@ static BOOL InitInstance(HINSTANCE hInstance)
485503 ImmDisableIME((DWORD)-1);
486504
487505 /* 高DPI対応であることを明示する(Windows Vistaで追加されたAPI) */
506+ /* APIで行うことは推奨されていない。マニフェストで行うのが正しい */
488507 bResult = SetProcessDPIAware();
489508 assert(FALSE != bResult);
490509 if (FALSE == bResult)
@@ -564,6 +583,9 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine
564583 else
565584 {
566585 /* アイドル処理 */
586+ screen_idle();
587+
588+ /* 必ずSleepを入れる */
567589 Sleep(10);
568590 }
569591 }