UART通信を用いた組み込みデバッグ用途向けメモリモニタ
Revisión | 8634a4e72a4da8bec42eb994b5698cb86839c9a6 (tree) |
---|---|
Tiempo | 2018-05-16 22:32:39 |
Autor | Yasushi Tanaka <tanaka_yasushi2008@yaho...> |
Commiter | Yasushi Tanaka |
リソースを追加
@@ -47,13 +47,13 @@ | ||
47 | 47 | </PropertyGroup> |
48 | 48 | <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> |
49 | 49 | <ClCompile> |
50 | - <PrecompiledHeader> | |
51 | - </PrecompiledHeader> | |
50 | + <PrecompiledHeader>Create</PrecompiledHeader> | |
52 | 51 | <WarningLevel>Level4</WarningLevel> |
53 | 52 | <Optimization>Disabled</Optimization> |
54 | 53 | <PreprocessorDefinitions>_CRTDBG_MAP_ALLOC;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
55 | 54 | <SDLCheck>true</SDLCheck> |
56 | - <AdditionalIncludeDirectories>$(ProjectDir)src\framework;$(ProjectDir)src\comm;$(ProjectDir)src\app;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |
55 | + <AdditionalIncludeDirectories>$(ProjectDir)src\framework;$(ProjectDir)src\comm;$(ProjectDir)src\app;$(ProjectDir)res;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |
56 | + <PrecompiledHeaderFile>header.h</PrecompiledHeaderFile> | |
57 | 57 | </ClCompile> |
58 | 58 | <Link> |
59 | 59 | <SubSystem>Windows</SubSystem> |
@@ -64,15 +64,15 @@ | ||
64 | 64 | <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> |
65 | 65 | <ClCompile> |
66 | 66 | <WarningLevel>Level4</WarningLevel> |
67 | - <PrecompiledHeader> | |
68 | - </PrecompiledHeader> | |
67 | + <PrecompiledHeader>NotUsing</PrecompiledHeader> | |
69 | 68 | <Optimization>MaxSpeed</Optimization> |
70 | 69 | <FunctionLevelLinking>true</FunctionLevelLinking> |
71 | 70 | <IntrinsicFunctions>true</IntrinsicFunctions> |
72 | 71 | <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
73 | 72 | <SDLCheck>true</SDLCheck> |
74 | - <AdditionalIncludeDirectories>$(ProjectDir)src\framework;$(ProjectDir)src\comm;$(ProjectDir)src\app;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |
73 | + <AdditionalIncludeDirectories>$(ProjectDir)src\framework;$(ProjectDir)src\comm;$(ProjectDir)src\app;$(ProjectDir)res;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |
75 | 74 | <RuntimeLibrary>MultiThreaded</RuntimeLibrary> |
75 | + <PrecompiledHeaderFile>header.h</PrecompiledHeaderFile> | |
76 | 76 | </ClCompile> |
77 | 77 | <Link> |
78 | 78 | <SubSystem>Windows</SubSystem> |
@@ -83,6 +83,7 @@ | ||
83 | 83 | </Link> |
84 | 84 | </ItemDefinitionGroup> |
85 | 85 | <ItemGroup> |
86 | + <ClInclude Include="res\resource.h" /> | |
86 | 87 | <ClInclude Include="src\app\app.h" /> |
87 | 88 | <ClInclude Include="src\comm\comm.h" /> |
88 | 89 | <ClInclude Include="src\comm\ymodem.h" /> |
@@ -105,6 +106,9 @@ | ||
105 | 106 | <ClCompile Include="src\framework\screen.c" /> |
106 | 107 | <ClCompile Include="src\framework\winmain.c" /> |
107 | 108 | </ItemGroup> |
109 | + <ItemGroup> | |
110 | + <ResourceCompile Include="res\DebugMonitor.rc" /> | |
111 | + </ItemGroup> | |
108 | 112 | <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> |
109 | 113 | <ImportGroup Label="ExtensionTargets"> |
110 | 114 | </ImportGroup> |
@@ -31,6 +31,9 @@ | ||
31 | 31 | <Filter Include="ソース ファイル\app"> |
32 | 32 | <UniqueIdentifier>{7f74ed15-8047-46a8-b2bf-3cd283e0275c}</UniqueIdentifier> |
33 | 33 | </Filter> |
34 | + <Filter Include="ヘッダー ファイル\res"> | |
35 | + <UniqueIdentifier>{0893a148-4f06-4220-b6f2-e59c315e2ee9}</UniqueIdentifier> | |
36 | + </Filter> | |
34 | 37 | </ItemGroup> |
35 | 38 | <ItemGroup> |
36 | 39 | <ClInclude Include="src\framework\screen.h"> |
@@ -63,6 +66,9 @@ | ||
63 | 66 | <ClInclude Include="src\comm\ymodem.h"> |
64 | 67 | <Filter>ヘッダー ファイル\comm</Filter> |
65 | 68 | </ClInclude> |
69 | + <ClInclude Include="res\resource.h"> | |
70 | + <Filter>ヘッダー ファイル\res</Filter> | |
71 | + </ClInclude> | |
66 | 72 | </ItemGroup> |
67 | 73 | <ItemGroup> |
68 | 74 | <ClCompile Include="src\framework\winmain.c"> |
@@ -93,4 +99,9 @@ | ||
93 | 99 | <Filter>ソース ファイル\comm</Filter> |
94 | 100 | </ClCompile> |
95 | 101 | </ItemGroup> |
102 | + <ItemGroup> | |
103 | + <ResourceCompile Include="res\DebugMonitor.rc"> | |
104 | + <Filter>リソース ファイル</Filter> | |
105 | + </ResourceCompile> | |
106 | + </ItemGroup> | |
96 | 107 | </Project> |
\ No newline at end of file |
@@ -0,0 +1,43 @@ | ||
1 | +// Generated by ResEdit 1.6.6 | |
2 | +// Copyright (C) 2006-2015 | |
3 | +// http://www.resedit.net | |
4 | + | |
5 | +#include <windows.h> | |
6 | +#include <commctrl.h> | |
7 | +#include <richedit.h> | |
8 | +#include "resource.h" | |
9 | + | |
10 | + | |
11 | + | |
12 | + | |
13 | +// | |
14 | +// Menu resources | |
15 | +// | |
16 | +LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL | |
17 | +IDR_MAINMENU MENU | |
18 | +{ | |
19 | + POPUP "ファイル(&F)" | |
20 | + { | |
21 | + MENUITEM "終了(&X)", IDM_EXIT | |
22 | + } | |
23 | + POPUP "ヘルプ(&H)" | |
24 | + { | |
25 | + MENUITEM "バージョン情報(&A)", IDM_ABOUT | |
26 | + } | |
27 | +} | |
28 | + | |
29 | + | |
30 | + | |
31 | +// | |
32 | +// Dialog resources | |
33 | +// | |
34 | +LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL | |
35 | +IDD_ABOUTDIALOG DIALOG 0, 0, 186, 95 | |
36 | +STYLE DS_3DLOOK | DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_VISIBLE | WS_POPUP | WS_SYSMENU | |
37 | +CAPTION "バージョン情報" | |
38 | +FONT 8, "MS UI Gothic" | |
39 | +{ | |
40 | + DEFPUSHBUTTON "OK", IDOK, 68, 72, 50, 14, 0, WS_EX_LEFT | |
41 | + CTEXT "DebugMonitor", IDD_ABOUT_APP, 19, 23, 145, 10, SS_CENTER | SS_CENTERIMAGE, WS_EX_LEFT | |
42 | + CTEXT "http://ja.osdn.net/users/xm6_original/", IDD_ABOUT_COPYRIGHT, 15, 47, 151, 9, SS_CENTER, WS_EX_LEFT | |
43 | +} |
@@ -0,0 +1,10 @@ | ||
1 | +#ifndef IDC_STATIC | |
2 | +#define IDC_STATIC (-1) | |
3 | +#endif | |
4 | + | |
5 | +#define IDR_MAINMENU 100 | |
6 | +#define IDD_ABOUTDIALOG 102 | |
7 | +#define IDD_ABOUT_APP 104 | |
8 | +#define IDD_ABOUT_COPYRIGHT 106 | |
9 | +#define IDM_EXIT 40000 | |
10 | +#define IDM_ABOUT 40001 |
@@ -19,8 +19,6 @@ | ||
19 | 19 | void app_run(void) |
20 | 20 | { |
21 | 21 | UINT portnum; |
22 | - BYTE buf[240]; | |
23 | - UINT loop; | |
24 | 22 | BOOL result; |
25 | 23 | |
26 | 24 | portnum = 0; |
@@ -42,17 +40,8 @@ void app_run(void) | ||
42 | 40 | /* ポート指定 */ |
43 | 41 | ymodem_init(0); |
44 | 42 | |
45 | - /* データ作成 */ | |
46 | - for (loop = 0; loop < sizeof(buf); loop++) | |
47 | - { | |
48 | - buf[loop] = (BYTE)loop; | |
49 | - } | |
50 | - | |
51 | - /* ファイルバッファへ転送 */ | |
52 | - memcpy(ymodem_get_filebuf(), buf, sizeof(buf)); | |
53 | - | |
54 | - /* ファイル送信 */ | |
55 | - result = ymodem_send("test.bin", sizeof(buf)); | |
43 | + /* ファイル受信 */ | |
44 | + result = ymodem_recv(); | |
56 | 45 | if (FALSE == result) |
57 | 46 | { |
58 | 47 | return; |
@@ -51,41 +51,61 @@ | ||
51 | 51 | */ |
52 | 52 | |
53 | 53 | /* 送信タイムアウト */ |
54 | -#define YMODEM_SEND_TIMEOUT 1000 | |
54 | +#define YMODEM_SEND_TIMEOUT 1000 | |
55 | 55 | |
56 | 56 | /* 送信リトライ回数 */ |
57 | -#define YMODEM_SEND_RETRY 40 | |
57 | +#define YMODEM_SEND_RETRY 40 | |
58 | + | |
59 | +/* 受信タイムアウト */ | |
60 | +#define YMODEM_RECV_TIMEOUT 500 | |
61 | + | |
62 | +/* 受信リトライ回数 */ | |
63 | +#define YMODEM_RECV_RETRY 80 | |
58 | 64 | |
59 | 65 | /* |
60 | 66 | * 状態遷移 |
61 | 67 | */ |
62 | 68 | |
63 | 69 | /* 初期状態 */ |
64 | -#define YMODEM_TRANS_NONE 0 | |
70 | +#define YMODEM_STATE_NONE 0 | |
71 | + | |
72 | +/* | |
73 | + * 送信系 | |
74 | + */ | |
65 | 75 | |
66 | 76 | /* 受信側の'C'送信待ち(1) */ |
67 | -#define YMODEM_TRANS_WAITC1 1 | |
77 | +#define YMODEM_STATE_WAITC1 1 | |
68 | 78 | |
69 | 79 | /* ファイル情報送信 */ |
70 | -#define YMODEM_TRANS_SENDINFO 2 | |
80 | +#define YMODEM_STATE_SENDINFO 2 | |
71 | 81 | |
72 | 82 | /* ファイル情報ACK待ち */ |
73 | -#define YMODEM_TRANS_INFOACK 3 | |
83 | +#define YMODEM_STATE_INFOACK 3 | |
74 | 84 | |
75 | 85 | /* 受信側の'C'送信待ち(2) */ |
76 | -#define YMODEM_TRANS_WAITC2 4 | |
86 | +#define YMODEM_STATE_WAITC2 4 | |
77 | 87 | |
78 | 88 | /* データブロック送信 */ |
79 | -#define YMODEM_TRANS_SENDDATA 5 | |
89 | +#define YMODEM_STATE_SENDDATA 5 | |
80 | 90 | |
81 | 91 | /* データブロックACK待ち */ |
82 | -#define YMODEM_TRANS_DATAACK 6 | |
92 | +#define YMODEM_STATE_DATAACK 6 | |
83 | 93 | |
84 | 94 | /* EOT送信 */ |
85 | -#define YMODEM_TRANS_SENDEOT 7 | |
95 | +#define YMODEM_STATE_SENDEOT 7 | |
86 | 96 | |
87 | 97 | /* EOTに対するACK待ち */ |
88 | -#define YMODEM_TRANS_EOTACK 8 | |
98 | +#define YMODEM_STATE_EOTACK 8 | |
99 | + | |
100 | +/* | |
101 | + * 受信系 | |
102 | + */ | |
103 | + | |
104 | +/* 'C'送信(1) */ | |
105 | +#define YMODEM_STATE_SENDC1 9 | |
106 | + | |
107 | +/* SOH送信待ち */ | |
108 | +#define YMODEM_STATE_WAITSOH 10 | |
89 | 109 | |
90 | 110 | /* |
91 | 111 | * YMODEMオブジェクト |
@@ -279,6 +299,41 @@ static void ymodem_object_init(YMODEM_OBJECT *object, UINT comm_index) | ||
279 | 299 | |
280 | 300 | /* |
281 | 301 | * YMODEM |
302 | + * エラー(成功) | |
303 | + */ | |
304 | +static void ymodem_error_success(YMODEM_OBJECT *object) | |
305 | +{ | |
306 | + assert(NULL != object); | |
307 | + | |
308 | + /* 成功 */ | |
309 | + object->status = YMODEM_SUCCESS; | |
310 | + | |
311 | + /* 初期状態に戻す */ | |
312 | + object->state = YMODEM_STATE_NONE; | |
313 | + | |
314 | + /* 送信中か */ | |
315 | + if (FALSE != object->sending) | |
316 | + { | |
317 | + /* 送信中でない */ | |
318 | + object->sending = FALSE; | |
319 | + | |
320 | + /* ログ */ | |
321 | + logwin_printf("ファイル送信成功"); | |
322 | + } | |
323 | + | |
324 | + /* 受信中か */ | |
325 | + if (FALSE != object->sending) | |
326 | + { | |
327 | + /* 受信中でない */ | |
328 | + object->receiving = FALSE; | |
329 | + | |
330 | + /* ログ */ | |
331 | + logwin_printf("ファイル受信成功"); | |
332 | + } | |
333 | +} | |
334 | + | |
335 | +/* | |
336 | + * YMODEM | |
282 | 337 | * エラー(ポートがクローズされた) |
283 | 338 | */ |
284 | 339 | static void ymodem_error_closed(YMODEM_OBJECT *object) |
@@ -618,6 +673,90 @@ static BYTE ymodem_wait_send(YMODEM_OBJECT *object) | ||
618 | 673 | ymodem_error_cancel(object); |
619 | 674 | return 0; |
620 | 675 | } |
676 | + | |
677 | + /* その他は読み捨て */ | |
678 | + default: | |
679 | + break; | |
680 | + } | |
681 | + } | |
682 | + | |
683 | + /* 有効な受信データなし */ | |
684 | + return 0; | |
685 | +} | |
686 | + | |
687 | +/* | |
688 | + * YMODEM | |
689 | + * 受信時の受信キャラクタ待ち | |
690 | + */ | |
691 | +static BYTE ymodem_wait_recv(YMODEM_OBJECT *object) | |
692 | +{ | |
693 | + BOOL result; | |
694 | + UINT len; | |
695 | + UINT error; | |
696 | + BYTE buf; | |
697 | + | |
698 | + /* タイムアウトチェック */ | |
699 | + result = ymodem_check_timeout(object, YMODEM_RECV_TIMEOUT); | |
700 | + if (FALSE != result) | |
701 | + { | |
702 | + /* タイムアウトしたので、リトライチェック */ | |
703 | + result = ymodem_check_retry(object, YMODEM_RECV_RETRY); | |
704 | + if (FALSE != result) | |
705 | + { | |
706 | + /* タイムアウトエラー */ | |
707 | + ymodem_error_timeout(object); | |
708 | + return 0; | |
709 | + } | |
710 | + } | |
711 | + | |
712 | + /* 受信バッファのデータサイズを得る */ | |
713 | + len = comm_get_bytes(object->comm_index); | |
714 | + while (len > 0) | |
715 | + { | |
716 | + /* 1バイト読み込み */ | |
717 | + error = comm_recv(object->comm_index, &buf, sizeof(buf)); | |
718 | + if (0 == error) | |
719 | + { | |
720 | + /* ポートがクローズされた */ | |
721 | + ymodem_error_closed(object); | |
722 | + return 0; | |
723 | + } | |
724 | + | |
725 | + /* CAN以外であればCANカウンタをクリア */ | |
726 | + if (YMODEM_CAN != buf) | |
727 | + { | |
728 | + object->cancel = 0; | |
729 | + } | |
730 | + | |
731 | + switch (buf) | |
732 | + { | |
733 | + /* SOH */ | |
734 | + case YMODEM_SOH: | |
735 | + return YMODEM_SOH; | |
736 | + | |
737 | + /* STX */ | |
738 | + case YMODEM_STX: | |
739 | + return YMODEM_STX; | |
740 | + | |
741 | + /* EOT */ | |
742 | + case YMODEM_EOT: | |
743 | + return YMODEM_EOT; | |
744 | + | |
745 | + /* CAN */ | |
746 | + case YMODEM_CAN: | |
747 | + object->can_cnt++; | |
748 | + /* キャンセルチェック */ | |
749 | + result = ymodem_check_cancel(object); | |
750 | + if (FALSE != result) | |
751 | + { | |
752 | + /* キャンセルエラー */ | |
753 | + ymodem_error_cancel(object); | |
754 | + return 0; | |
755 | + } | |
756 | + | |
757 | + /* その他は読み捨て */ | |
758 | + default: | |
759 | + break; | |
621 | 760 | } |
622 | 761 | } |
623 | 762 |
@@ -736,7 +875,7 @@ static void ymodem_waitc1_do(YMODEM_OBJECT *object) | ||
736 | 875 | /* 'C'であれば状態遷移 */ |
737 | 876 | if (YMODEM_C == buf) |
738 | 877 | { |
739 | - ymodem_object_trans(object, YMODEM_TRANS_SENDINFO); | |
878 | + ymodem_object_trans(object, YMODEM_STATE_SENDINFO); | |
740 | 879 | } |
741 | 880 | } |
742 | 881 |
@@ -803,7 +942,7 @@ static void ymodem_sendinfo_do(YMODEM_OBJECT *object) | ||
803 | 942 | if (FALSE != result) |
804 | 943 | { |
805 | 944 | /* ファイル情報ACK待ち */ |
806 | - ymodem_object_trans(object, YMODEM_TRANS_INFOACK); | |
945 | + ymodem_object_trans(object, YMODEM_STATE_INFOACK); | |
807 | 946 | } |
808 | 947 | } |
809 | 948 |
@@ -847,7 +986,7 @@ static void ymodem_infoack_do(YMODEM_OBJECT *object) | ||
847 | 986 | { |
848 | 987 | /* ACKは状態遷移 */ |
849 | 988 | case YMODEM_ACK: |
850 | - ymodem_object_trans(object, YMODEM_TRANS_WAITC2); | |
989 | + ymodem_object_trans(object, YMODEM_STATE_WAITC2); | |
851 | 990 | break; |
852 | 991 | |
853 | 992 | /* NAKはリトライチェック */ |
@@ -862,7 +1001,7 @@ static void ymodem_infoack_do(YMODEM_OBJECT *object) | ||
862 | 1001 | else |
863 | 1002 | { |
864 | 1003 | /* ファイル情報を再送 */ |
865 | - ymodem_object_trans(object, YMODEM_TRANS_SENDINFO); | |
1004 | + ymodem_object_trans(object, YMODEM_STATE_SENDINFO); | |
866 | 1005 | } |
867 | 1006 | break; |
868 | 1007 |
@@ -915,11 +1054,11 @@ static void ymodem_waitc2_do(YMODEM_OBJECT *object) | ||
915 | 1054 | { |
916 | 1055 | if (0 < object->file_size) |
917 | 1056 | { |
918 | - ymodem_object_trans(object, YMODEM_TRANS_SENDDATA); | |
1057 | + ymodem_object_trans(object, YMODEM_STATE_SENDDATA); | |
919 | 1058 | } |
920 | 1059 | else |
921 | 1060 | { |
922 | - ymodem_object_trans(object, YMODEM_TRANS_SENDEOT); | |
1061 | + ymodem_object_trans(object, YMODEM_STATE_SENDEOT); | |
923 | 1062 | } |
924 | 1063 | } |
925 | 1064 | } |
@@ -990,7 +1129,7 @@ static void ymodem_senddata_do(YMODEM_OBJECT *object) | ||
990 | 1129 | result = ymodem_check_offset(object); |
991 | 1130 | if (FALSE != result) |
992 | 1131 | { |
993 | - ymodem_object_trans(object, YMODEM_TRANS_DATAACK); | |
1132 | + ymodem_object_trans(object, YMODEM_STATE_DATAACK); | |
994 | 1133 | } |
995 | 1134 | } |
996 | 1135 |
@@ -1043,7 +1182,7 @@ static void ymodem_dataack_do(YMODEM_OBJECT *object) | ||
1043 | 1182 | object->retry = 0; |
1044 | 1183 | |
1045 | 1184 | /* EOT送信 */ |
1046 | - ymodem_object_trans(object, YMODEM_TRANS_SENDEOT); | |
1185 | + ymodem_object_trans(object, YMODEM_STATE_SENDEOT); | |
1047 | 1186 | } |
1048 | 1187 | else |
1049 | 1188 | { |
@@ -1057,7 +1196,7 @@ static void ymodem_dataack_do(YMODEM_OBJECT *object) | ||
1057 | 1196 | object->buf_offset += 0x80; |
1058 | 1197 | |
1059 | 1198 | /* データブロック送信 */ |
1060 | - ymodem_object_trans(object, YMODEM_TRANS_SENDDATA); | |
1199 | + ymodem_object_trans(object, YMODEM_STATE_SENDDATA); | |
1061 | 1200 | } |
1062 | 1201 | break; |
1063 | 1202 |
@@ -1074,7 +1213,7 @@ static void ymodem_dataack_do(YMODEM_OBJECT *object) | ||
1074 | 1213 | else |
1075 | 1214 | { |
1076 | 1215 | /* データブロックを再送 */ |
1077 | - ymodem_object_trans(object, YMODEM_TRANS_SENDDATA); | |
1216 | + ymodem_object_trans(object, YMODEM_STATE_SENDDATA); | |
1078 | 1217 | } |
1079 | 1218 | break; |
1080 | 1219 |
@@ -1127,7 +1266,7 @@ static void ymodem_sendeot_do(YMODEM_OBJECT *object) | ||
1127 | 1266 | else |
1128 | 1267 | { |
1129 | 1268 | /* 状態遷移 */ |
1130 | - ymodem_object_trans(object, YMODEM_TRANS_EOTACK); | |
1269 | + ymodem_object_trans(object, YMODEM_STATE_EOTACK); | |
1131 | 1270 | } |
1132 | 1271 | } |
1133 | 1272 |
@@ -1176,9 +1315,7 @@ static void ymodem_eotack_do(YMODEM_OBJECT *object) | ||
1176 | 1315 | /* ACK */ |
1177 | 1316 | case YMODEM_ACK: |
1178 | 1317 | /* ACKは送信終了 */ |
1179 | - object->sending = FALSE; | |
1180 | - object->status = YMODEM_SUCCESS; | |
1181 | - object->state = YMODEM_TRANS_NONE; | |
1318 | + ymodem_error_success(object); | |
1182 | 1319 | break; |
1183 | 1320 | |
1184 | 1321 | /* NAK */ |
@@ -1194,7 +1331,7 @@ static void ymodem_eotack_do(YMODEM_OBJECT *object) | ||
1194 | 1331 | else |
1195 | 1332 | { |
1196 | 1333 | /* EOTを再送 */ |
1197 | - ymodem_object_trans(object, YMODEM_TRANS_SENDEOT); | |
1334 | + ymodem_object_trans(object, YMODEM_STATE_SENDEOT); | |
1198 | 1335 | } |
1199 | 1336 | break; |
1200 | 1337 |
@@ -1216,6 +1353,90 @@ static void ymodem_eotack_exit(YMODEM_OBJECT *object) | ||
1216 | 1353 | |
1217 | 1354 | /* |
1218 | 1355 | * YMODEM |
1356 | + * 'C'送信(1) | |
1357 | + * enter | |
1358 | + */ | |
1359 | +static void ymodem_sendc1_enter(YMODEM_OBJECT *object) | |
1360 | +{ | |
1361 | +} | |
1362 | + | |
1363 | +/* | |
1364 | + * YMODEM | |
1365 | + * 'C'送信(1) | |
1366 | + * do | |
1367 | + */ | |
1368 | +static void ymodem_sendc1_do(YMODEM_OBJECT *object) | |
1369 | +{ | |
1370 | + UINT result; | |
1371 | + BYTE buf; | |
1372 | + | |
1373 | + assert(NULL != object); | |
1374 | + | |
1375 | + /* C送信 */ | |
1376 | + buf = YMODEM_C; | |
1377 | + result = comm_send(object->comm_index, &buf, sizeof(buf)); | |
1378 | + if (0 == result) | |
1379 | + { | |
1380 | + /* 書き込みに失敗した */ | |
1381 | + ymodem_error_closed(object); | |
1382 | + } | |
1383 | + else | |
1384 | + { | |
1385 | + /* 状態遷移 */ | |
1386 | + ymodem_object_trans(object, YMODEM_STATE_WAITSOH); | |
1387 | + } | |
1388 | +} | |
1389 | + | |
1390 | +/* | |
1391 | + * YMODEM | |
1392 | + * 'C'送信(1) | |
1393 | + * exit | |
1394 | + */ | |
1395 | +static void ymodem_sendc1_exit(YMODEM_OBJECT *object) | |
1396 | +{ | |
1397 | +} | |
1398 | + | |
1399 | +/* | |
1400 | + * YMODEM | |
1401 | + * SOH送信待ち | |
1402 | + * enter | |
1403 | + */ | |
1404 | +static void ymodem_waitsoh_enter(YMODEM_OBJECT *object) | |
1405 | +{ | |
1406 | + /* 開始時間を初期化 */ | |
1407 | + object->start_time = timeGetTime(); | |
1408 | +} | |
1409 | + | |
1410 | +/* | |
1411 | + * YMODEM | |
1412 | + * SOH送信待ち | |
1413 | + * do | |
1414 | + */ | |
1415 | +static void ymodem_waitsoh_do(YMODEM_OBJECT *object) | |
1416 | +{ | |
1417 | + BYTE buf; | |
1418 | + | |
1419 | + /* 受信時の受信キャラクタ待ち */ | |
1420 | + buf = ymodem_wait_recv(object); | |
1421 | + | |
1422 | + /* SOHであれば状態遷移 */ | |
1423 | + if (YMODEM_SOH == buf) | |
1424 | + { | |
1425 | + ymodem_object_trans(object, YMODEM_STATE_SENDINFO); | |
1426 | + } | |
1427 | +} | |
1428 | + | |
1429 | +/* | |
1430 | + * YMODEM | |
1431 | + * SOH送信待ち | |
1432 | + * exit | |
1433 | + */ | |
1434 | +static void ymodem_waitsoh_exit(YMODEM_OBJECT *object) | |
1435 | +{ | |
1436 | +} | |
1437 | + | |
1438 | +/* | |
1439 | + * YMODEM | |
1219 | 1440 | * オブジェクト状態遷移要求 |
1220 | 1441 | */ |
1221 | 1442 | static void ymodem_object_trans(YMODEM_OBJECT *object, UINT state) |
@@ -1226,48 +1447,58 @@ static void ymodem_object_trans(YMODEM_OBJECT *object, UINT state) | ||
1226 | 1447 | switch (object->state) |
1227 | 1448 | { |
1228 | 1449 | /* 初期状態 */ |
1229 | - case YMODEM_TRANS_NONE: | |
1450 | + case YMODEM_STATE_NONE: | |
1230 | 1451 | break; |
1231 | 1452 | |
1232 | 1453 | /* 受信側の'C'送信待ち(1) */ |
1233 | - case YMODEM_TRANS_WAITC1: | |
1454 | + case YMODEM_STATE_WAITC1: | |
1234 | 1455 | ymodem_waitc1_exit(object); |
1235 | 1456 | break; |
1236 | 1457 | |
1237 | 1458 | /* ファイル情報の送信 */ |
1238 | - case YMODEM_TRANS_SENDINFO: | |
1459 | + case YMODEM_STATE_SENDINFO: | |
1239 | 1460 | ymodem_sendinfo_exit(object); |
1240 | 1461 | break; |
1241 | 1462 | |
1242 | 1463 | /* ファイル情報ACK待ち */ |
1243 | - case YMODEM_TRANS_INFOACK: | |
1464 | + case YMODEM_STATE_INFOACK: | |
1244 | 1465 | ymodem_infoack_exit(object); |
1245 | 1466 | break; |
1246 | 1467 | |
1247 | 1468 | /* 受信側の'C'送信待ち(2) */ |
1248 | - case YMODEM_TRANS_WAITC2: | |
1469 | + case YMODEM_STATE_WAITC2: | |
1249 | 1470 | ymodem_waitc2_exit(object); |
1250 | 1471 | break; |
1251 | 1472 | |
1252 | 1473 | /* データブロック送信 */ |
1253 | - case YMODEM_TRANS_SENDDATA: | |
1474 | + case YMODEM_STATE_SENDDATA: | |
1254 | 1475 | ymodem_senddata_exit(object); |
1255 | 1476 | break; |
1256 | 1477 | |
1257 | 1478 | /* データブロックACK待ち */ |
1258 | - case YMODEM_TRANS_DATAACK: | |
1479 | + case YMODEM_STATE_DATAACK: | |
1259 | 1480 | ymodem_dataack_exit(object); |
1260 | 1481 | break; |
1261 | 1482 | |
1262 | 1483 | /* EOT送信 */ |
1263 | - case YMODEM_TRANS_SENDEOT: | |
1484 | + case YMODEM_STATE_SENDEOT: | |
1264 | 1485 | ymodem_sendeot_exit(object); |
1265 | 1486 | break; |
1266 | 1487 | |
1267 | 1488 | /* EOTに対するACK待ち */ |
1268 | - case YMODEM_TRANS_EOTACK: | |
1489 | + case YMODEM_STATE_EOTACK: | |
1269 | 1490 | ymodem_eotack_exit(object); |
1270 | 1491 | break; |
1492 | + | |
1493 | + /* 'C'送信(1) */ | |
1494 | + case YMODEM_STATE_SENDC1: | |
1495 | + ymodem_sendc1_exit(object); | |
1496 | + break; | |
1497 | + | |
1498 | + /* SOH送信待ち */ | |
1499 | + case YMODEM_STATE_WAITSOH: | |
1500 | + ymodem_waitsoh_exit(object); | |
1501 | + break; | |
1271 | 1502 | } |
1272 | 1503 | |
1273 | 1504 | /* 状態変更 */ |
@@ -1277,44 +1508,54 @@ static void ymodem_object_trans(YMODEM_OBJECT *object, UINT state) | ||
1277 | 1508 | switch (object->state) |
1278 | 1509 | { |
1279 | 1510 | /* 受信側の'C'送信待ち(1) */ |
1280 | - case YMODEM_TRANS_WAITC1: | |
1511 | + case YMODEM_STATE_WAITC1: | |
1281 | 1512 | ymodem_waitc1_enter(object); |
1282 | 1513 | break; |
1283 | 1514 | |
1284 | 1515 | /* ファイル情報の送信 */ |
1285 | - case YMODEM_TRANS_SENDINFO: | |
1516 | + case YMODEM_STATE_SENDINFO: | |
1286 | 1517 | ymodem_sendinfo_enter(object); |
1287 | 1518 | break; |
1288 | 1519 | |
1289 | 1520 | /* ファイル情報ACK待ち */ |
1290 | - case YMODEM_TRANS_INFOACK: | |
1521 | + case YMODEM_STATE_INFOACK: | |
1291 | 1522 | ymodem_infoack_enter(object); |
1292 | 1523 | break; |
1293 | 1524 | |
1294 | 1525 | /* 受信側の'C'送信待ち(2) */ |
1295 | - case YMODEM_TRANS_WAITC2: | |
1526 | + case YMODEM_STATE_WAITC2: | |
1296 | 1527 | ymodem_waitc2_enter(object); |
1297 | 1528 | break; |
1298 | 1529 | |
1299 | 1530 | /* データブロック送信 */ |
1300 | - case YMODEM_TRANS_SENDDATA: | |
1531 | + case YMODEM_STATE_SENDDATA: | |
1301 | 1532 | ymodem_senddata_enter(object); |
1302 | 1533 | break; |
1303 | 1534 | |
1304 | 1535 | /* データブロックACK待ち */ |
1305 | - case YMODEM_TRANS_DATAACK: | |
1536 | + case YMODEM_STATE_DATAACK: | |
1306 | 1537 | ymodem_dataack_enter(object); |
1307 | 1538 | break; |
1308 | 1539 | |
1309 | 1540 | /* EOT送信 */ |
1310 | - case YMODEM_TRANS_SENDEOT: | |
1541 | + case YMODEM_STATE_SENDEOT: | |
1311 | 1542 | ymodem_sendeot_enter(object); |
1312 | 1543 | break; |
1313 | 1544 | |
1314 | 1545 | /* EOTに対するACK待ち */ |
1315 | - case YMODEM_TRANS_EOTACK: | |
1546 | + case YMODEM_STATE_EOTACK: | |
1316 | 1547 | ymodem_eotack_enter(object); |
1317 | 1548 | break; |
1549 | + | |
1550 | + /* 'C'送信(1) */ | |
1551 | + case YMODEM_STATE_SENDC1: | |
1552 | + ymodem_sendc1_enter(object); | |
1553 | + break; | |
1554 | + | |
1555 | + /* SOH送信待ち */ | |
1556 | + case YMODEM_STATE_WAITSOH: | |
1557 | + ymodem_waitsoh_enter(object); | |
1558 | + break; | |
1318 | 1559 | } |
1319 | 1560 | } |
1320 | 1561 |
@@ -1333,48 +1574,58 @@ static void ymodem_object_idle(YMODEM_OBJECT *object) | ||
1333 | 1574 | } |
1334 | 1575 | |
1335 | 1576 | /* do処理 */ |
1336 | - assert(YMODEM_TRANS_NONE != object->state); | |
1577 | + assert(YMODEM_STATE_NONE != object->state); | |
1337 | 1578 | switch (object->state) |
1338 | 1579 | { |
1339 | 1580 | /* 受信側の'C'送信待ち(1) */ |
1340 | - case YMODEM_TRANS_WAITC1: | |
1581 | + case YMODEM_STATE_WAITC1: | |
1341 | 1582 | ymodem_waitc1_do(object); |
1342 | 1583 | break; |
1343 | 1584 | |
1344 | 1585 | /* ファイル情報の送信 */ |
1345 | - case YMODEM_TRANS_SENDINFO: | |
1586 | + case YMODEM_STATE_SENDINFO: | |
1346 | 1587 | ymodem_sendinfo_do(object); |
1347 | 1588 | break; |
1348 | 1589 | |
1349 | 1590 | /* ファイル情報ACK待ち */ |
1350 | - case YMODEM_TRANS_INFOACK: | |
1591 | + case YMODEM_STATE_INFOACK: | |
1351 | 1592 | ymodem_infoack_do(object); |
1352 | 1593 | break; |
1353 | 1594 | |
1354 | 1595 | /* 受信側の'C'送信待ち(2) */ |
1355 | - case YMODEM_TRANS_WAITC2: | |
1596 | + case YMODEM_STATE_WAITC2: | |
1356 | 1597 | ymodem_waitc2_do(object); |
1357 | 1598 | break; |
1358 | 1599 | |
1359 | 1600 | /* データブロック送信 */ |
1360 | - case YMODEM_TRANS_SENDDATA: | |
1601 | + case YMODEM_STATE_SENDDATA: | |
1361 | 1602 | ymodem_senddata_do(object); |
1362 | 1603 | break; |
1363 | 1604 | |
1364 | 1605 | /* データブロックACK待ち */ |
1365 | - case YMODEM_TRANS_DATAACK: | |
1606 | + case YMODEM_STATE_DATAACK: | |
1366 | 1607 | ymodem_dataack_do(object); |
1367 | 1608 | break; |
1368 | 1609 | |
1369 | 1610 | /* EOT送信 */ |
1370 | - case YMODEM_TRANS_SENDEOT: | |
1611 | + case YMODEM_STATE_SENDEOT: | |
1371 | 1612 | ymodem_sendeot_do(object); |
1372 | 1613 | break; |
1373 | 1614 | |
1374 | - /* EOTに対するACK待ち */ | |
1375 | - case YMODEM_TRANS_EOTACK: | |
1615 | + /* EOTに対するACK待ち */ | |
1616 | + case YMODEM_STATE_EOTACK: | |
1376 | 1617 | ymodem_eotack_do(object); |
1377 | 1618 | break; |
1619 | + | |
1620 | + /* 'C'送信(1) */ | |
1621 | + case YMODEM_STATE_SENDC1: | |
1622 | + ymodem_sendc1_do(object); | |
1623 | + break; | |
1624 | + | |
1625 | + /* SOH送信待ち */ | |
1626 | + case YMODEM_STATE_WAITSOH: | |
1627 | + ymodem_waitsoh_do(object); | |
1628 | + break; | |
1378 | 1629 | } |
1379 | 1630 | } |
1380 | 1631 |
@@ -1435,7 +1686,51 @@ static BOOL ymodem_object_send(YMODEM_OBJECT *object, const char *filename, UINT | ||
1435 | 1686 | object->file_size = filesize; |
1436 | 1687 | |
1437 | 1688 | /* 状態遷移 */ |
1438 | - ymodem_object_trans(object, YMODEM_TRANS_WAITC1); | |
1689 | + ymodem_object_trans(object, YMODEM_STATE_WAITC1); | |
1690 | + | |
1691 | + /* 成功 */ | |
1692 | + return TRUE; | |
1693 | +} | |
1694 | + | |
1695 | +/* | |
1696 | + * YMODEM | |
1697 | + * オブジェクト受信開始 | |
1698 | + */ | |
1699 | +static BOOL ymodem_object_recv(YMODEM_OBJECT *object) | |
1700 | +{ | |
1701 | + BOOL result; | |
1702 | + | |
1703 | + assert(NULL != object); | |
1704 | + | |
1705 | + /* 送信中または受信中であればエラー */ | |
1706 | + assert((FALSE == object->sending) && (FALSE == object->receiving)); | |
1707 | + if ((FALSE != object->sending) || (FALSE != object->receiving)) | |
1708 | + { | |
1709 | + /* 送信中または受信中である */ | |
1710 | + return FALSE; | |
1711 | + } | |
1712 | + | |
1713 | + /* 通信ポートがオープンできなければエラー */ | |
1714 | + result = comm_open(object->comm_index); | |
1715 | + if (FALSE == result) | |
1716 | + { | |
1717 | + return FALSE; | |
1718 | + } | |
1719 | + | |
1720 | + /* 受信中 */ | |
1721 | + object->receiving = TRUE; | |
1722 | + | |
1723 | + /* BUSY */ | |
1724 | + object->status = YMODEM_BUSY; | |
1725 | + | |
1726 | + /* 受信バッファの読み捨て */ | |
1727 | + ymodem_discard_recv(object); | |
1728 | + | |
1729 | + /* リトライ回数を初期化 */ | |
1730 | + object->retry = 0; | |
1731 | + | |
1732 | + /* 状態遷移 */ | |
1733 | + ymodem_object_trans(object, YMODEM_STATE_SENDC1); | |
1439 | 1734 | |
1440 | 1735 | /* 成功 */ |
1441 | 1736 | return TRUE; |
@@ -1528,49 +1823,59 @@ static void ymodem_object_monitor(YMODEM_OBJECT *object) | ||
1528 | 1823 | switch (object->state) |
1529 | 1824 | { |
1530 | 1825 | /* 初期状態 */ |
1531 | - case YMODEM_TRANS_NONE: | |
1826 | + case YMODEM_STATE_NONE: | |
1532 | 1827 | monitor_printf("内部状態 初期状態\n"); |
1533 | 1828 | break; |
1534 | 1829 | |
1535 | 1830 | /* 受信側の'C'送信待ち(1) */ |
1536 | - case YMODEM_TRANS_WAITC1: | |
1831 | + case YMODEM_STATE_WAITC1: | |
1537 | 1832 | monitor_printf("内部状態 受信側の'C'送信待ち(1)\n"); |
1538 | 1833 | break; |
1539 | 1834 | |
1540 | 1835 | /* ファイル情報送信 */ |
1541 | - case YMODEM_TRANS_SENDINFO: | |
1836 | + case YMODEM_STATE_SENDINFO: | |
1542 | 1837 | monitor_printf("内部状態 ファイル情報送信\n"); |
1543 | 1838 | break; |
1544 | 1839 | |
1545 | 1840 | /* ファイル情報ACK待ち */ |
1546 | - case YMODEM_TRANS_INFOACK: | |
1841 | + case YMODEM_STATE_INFOACK: | |
1547 | 1842 | monitor_printf("内部状態 ファイル情報ACK待ち\n"); |
1548 | 1843 | break; |
1549 | 1844 | |
1550 | 1845 | /* 受信側の'C'送信待ち(2) */ |
1551 | - case YMODEM_TRANS_WAITC2: | |
1846 | + case YMODEM_STATE_WAITC2: | |
1552 | 1847 | monitor_printf("内部状態 受信側の'C'送信待ち(2)\n"); |
1553 | 1848 | break; |
1554 | 1849 | |
1555 | 1850 | /* データブロック送信 */ |
1556 | - case YMODEM_TRANS_SENDDATA: | |
1851 | + case YMODEM_STATE_SENDDATA: | |
1557 | 1852 | monitor_printf("内部状態 データブロック送信\n"); |
1558 | 1853 | break; |
1559 | 1854 | |
1560 | 1855 | /* データブロックACK待ち */ |
1561 | - case YMODEM_TRANS_DATAACK: | |
1856 | + case YMODEM_STATE_DATAACK: | |
1562 | 1857 | monitor_printf("内部状態 データブロックACK待ち\n"); |
1563 | 1858 | break; |
1564 | 1859 | |
1565 | 1860 | /* EOT送信 */ |
1566 | - case YMODEM_TRANS_SENDEOT: | |
1861 | + case YMODEM_STATE_SENDEOT: | |
1567 | 1862 | monitor_printf("内部状態 EOT送信\n"); |
1568 | 1863 | break; |
1569 | 1864 | |
1570 | 1865 | /* EOTに対するACK待ち */ |
1571 | - case YMODEM_TRANS_EOTACK: | |
1866 | + case YMODEM_STATE_EOTACK: | |
1572 | 1867 | monitor_printf("内部状態 EOTに対するACK待ち\n"); |
1573 | 1868 | break; |
1869 | + | |
1870 | + /* 'C'送信(1) */ | |
1871 | + case YMODEM_STATE_SENDC1: | |
1872 | + monitor_printf("内部状態 'C'送信(1)\n"); | |
1873 | + break; | |
1874 | + | |
1875 | + /* SOH送信待ち */ | |
1876 | + case YMODEM_STATE_WAITSOH: | |
1877 | + monitor_printf("内部状態 SOH送信待ち\n"); | |
1878 | + break; | |
1574 | 1879 | } |
1575 | 1880 | |
1576 | 1881 | /* ブロック番号 */ |
@@ -1636,7 +1941,8 @@ BOOL ymodem_send(const char* filename, UINT filesize) | ||
1636 | 1941 | */ |
1637 | 1942 | BOOL ymodem_recv(void) |
1638 | 1943 | { |
1639 | - return FALSE; | |
1944 | + /* オブジェクト受信開始 */ | |
1945 | + return ymodem_object_recv(&g_ymodem_object); | |
1640 | 1946 | } |
1641 | 1947 | |
1642 | 1948 | /* |
@@ -8,17 +8,29 @@ | ||
8 | 8 | #pragma once |
9 | 9 | |
10 | 10 | /* |
11 | - * 定数 | |
11 | + * ステータス | |
12 | 12 | */ |
13 | 13 | |
14 | -/* ステータス */ | |
15 | -#define YMODEM_SUCCESS 0 /* 成功 */ | |
16 | -#define YMODEM_BUSY 1 /* 動作中 */ | |
17 | -#define YMODEM_SIZEOVER 2 /* バッファサイズ溢れ */ | |
18 | -#define YMODEM_TIMEOUT 3 /* タイムアウト */ | |
19 | -#define YMODEM_RETRY 4 /* リトライオーバー */ | |
20 | -#define YMODEM_CANCEL 5 /* キャンセル要求受信 */ | |
21 | -#define YMODEM_CLOSED 6 /* ポートクローズ */ | |
14 | +/* 成功 */ | |
15 | +#define YMODEM_SUCCESS 0 | |
16 | + | |
17 | +/* 動作中 */ | |
18 | +#define YMODEM_BUSY 1 | |
19 | + | |
20 | +/* バッファサイズ溢れ */ | |
21 | +#define YMODEM_SIZEOVER 2 | |
22 | + | |
23 | +/* タイムアウト */ | |
24 | +#define YMODEM_TIMEOUT 3 | |
25 | + | |
26 | +/* リトライオーバー */ | |
27 | +#define YMODEM_RETRY 4 | |
28 | + | |
29 | +/* キャンセル要求受信 */ | |
30 | +#define YMODEM_CANCEL 5 | |
31 | + | |
32 | +/* ポートクローズ */ | |
33 | +#define YMODEM_CLOSED 6 | |
22 | 34 | |
23 | 35 | /* |
24 | 36 | * グローバル関数 |
@@ -13,6 +13,7 @@ | ||
13 | 13 | #include "comm.h" |
14 | 14 | #include "ymodem.h" |
15 | 15 | #include "app.h" |
16 | +#include "resource.h" | |
16 | 17 | #include "winmain.h" |
17 | 18 | |
18 | 19 | /* |
@@ -298,7 +299,7 @@ static BOOL OnCreateFont(HWND hWnd) | ||
298 | 299 | * WinMain |
299 | 300 | * WM_CREATEメッセージハンドラ |
300 | 301 | */ |
301 | -static BOOL OnCreate(HWND hWnd, const CREATESTRUCT *lpcs) | |
302 | +static BOOL OnCreate(HWND hWnd) | |
302 | 303 | { |
303 | 304 | BOOL bResult; |
304 | 305 | int x; |
@@ -307,7 +308,6 @@ static BOOL OnCreate(HWND hWnd, const CREATESTRUCT *lpcs) | ||
307 | 308 | int height; |
308 | 309 | |
309 | 310 | assert(NULL != hWnd); |
310 | - assert(NULL != lpcs); | |
311 | 311 | |
312 | 312 | /* フォントを作成 */ |
313 | 313 | if (FALSE == OnCreateFont(hWnd)) |
@@ -440,6 +440,73 @@ static void OnSize(HWND hWnd) | ||
440 | 440 | |
441 | 441 | /* |
442 | 442 | * WinMain |
443 | + * バージョン情報ダイアログプロシージャ | |
444 | + */ | |
445 | +static BOOL CALLBACK AboutDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) | |
446 | +{ | |
447 | + RECT rect; | |
448 | + RECT rectParent; | |
449 | + int x; | |
450 | + int y; | |
451 | + | |
452 | + switch (message) | |
453 | + { | |
454 | + /* ダイアログの初期化 */ | |
455 | + case WM_INITDIALOG: | |
456 | + /* ダイアログと親ウィンドウの矩形を取得 */ | |
457 | + GetWindowRect(hDlg, &rect); | |
458 | + GetWindowRect(GetParent(hDlg), &rectParent); | |
459 | + | |
460 | + /* 親ウィンドウの中央になるように位置を設定 */ | |
461 | + x = ((rectParent.left + rectParent.right) / 2) - ((rect.right - rect.left) / 2); | |
462 | + y = ((rectParent.top + rectParent.bottom) / 2) - ((rect.bottom - rect.top) / 2); | |
463 | + SetWindowPos(hDlg, NULL, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE); | |
464 | + return TRUE; | |
465 | + | |
466 | + /* コマンド */ | |
467 | + case WM_COMMAND: | |
468 | + switch (LOWORD(wParam)) | |
469 | + { | |
470 | + case IDOK: | |
471 | + case IDCANCEL: | |
472 | + EndDialog(hDlg, 0); | |
473 | + return TRUE; | |
474 | + } | |
475 | + break; | |
476 | + } | |
477 | + | |
478 | + /* その他のメッセージ */ | |
479 | + return FALSE; | |
480 | +} | |
481 | + | |
482 | +/* | |
483 | + * WinMain | |
484 | + * WM_COMMANDメッセージハンドラ | |
485 | + */ | |
486 | +static void OnCommand(HWND hWnd, WORD wID) | |
487 | +{ | |
488 | + assert(NULL != hWnd); | |
489 | + | |
490 | + switch (wID) | |
491 | + { | |
492 | + /* ファイル(F)-終了(X) */ | |
493 | + case IDM_EXIT: | |
494 | + PostMessage(hWnd, WM_CLOSE, 0, 0); | |
495 | + break; | |
496 | + | |
497 | + /* ヘルプ(H)-バージョン情報(A) */ | |
498 | + case IDM_ABOUT: | |
499 | + DialogBox(g_hAppInstance, MAKEINTRESOURCE(IDD_ABOUTDIALOG), hWnd, AboutDialogProc); | |
500 | + break; | |
501 | + | |
502 | + /* その他 */ | |
503 | + default: | |
504 | + break; | |
505 | + } | |
506 | +} | |
507 | + | |
508 | +/* | |
509 | + * WinMain | |
443 | 510 | * WM_ACTIVATEメッセージハンドラ |
444 | 511 | */ |
445 | 512 | static void OnActivate(HWND hWnd) |
@@ -529,7 +596,6 @@ static void OnKeyDown(HWND hWnd, WPARAM wParam, LPARAM lParam) | ||
529 | 596 | */ |
530 | 597 | static LRESULT CALLBACK FrameWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) |
531 | 598 | { |
532 | - const CREATESTRUCT *lpcs; | |
533 | 599 | BOOL bResult; |
534 | 600 | |
535 | 601 | switch (uMsg) |
@@ -537,9 +603,7 @@ static LRESULT CALLBACK FrameWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPA | ||
537 | 603 | /* ウィンドウが作成された */ |
538 | 604 | case WM_CREATE: |
539 | 605 | /* ハンドラを呼び出す */ |
540 | - lpcs = (const CREATESTRUCT *)lParam; | |
541 | - assert(NULL != lpcs); | |
542 | - bResult = OnCreate(hWnd, lpcs); | |
606 | + bResult = OnCreate(hWnd); | |
543 | 607 | |
544 | 608 | /* ハンドラの結果によって、CreateWindowを失敗させる */ |
545 | 609 | if (FALSE == bResult) |
@@ -566,6 +630,15 @@ static LRESULT CALLBACK FrameWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPA | ||
566 | 630 | OnSize(hWnd); |
567 | 631 | return 0; |
568 | 632 | |
633 | + /* コマンドが送信された */ | |
634 | + case WM_COMMAND: | |
635 | + /* ハンドラを呼び出す */ | |
636 | + if (0 == HIWORD(wParam)) | |
637 | + { | |
638 | + OnCommand(hWnd, LOWORD(wParam)); | |
639 | + } | |
640 | + return 0; | |
641 | + | |
569 | 642 | /* ウィンドウが表示された */ |
570 | 643 | case WM_ACTIVATE: |
571 | 644 | /* ハンドラを呼び出す */ |
@@ -715,7 +788,7 @@ static BOOL InitInstance(HINSTANCE hInstance) | ||
715 | 788 | CW_USEDEFAULT, |
716 | 789 | CW_USEDEFAULT, |
717 | 790 | NULL, |
718 | - NULL, | |
791 | + LoadMenu(g_hAppInstance, MAKEINTRESOURCE(IDR_MAINMENU)), | |
719 | 792 | g_hAppInstance, |
720 | 793 | NULL); |
721 | 794 |