質問編集履歴
2
提示コードを修正しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -484,12 +484,346 @@
|
|
484
484
|
|
485
485
|
};
|
486
486
|
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
487
|
#endif
|
494
488
|
|
495
489
|
```
|
490
|
+
|
491
|
+
```cpp
|
492
|
+
|
493
|
+
#include "DrawCharactor.hpp"
|
494
|
+
|
495
|
+
|
496
|
+
|
497
|
+
// コンストラクタ
|
498
|
+
|
499
|
+
DrawCharactor::DrawCharactor()
|
500
|
+
|
501
|
+
{
|
502
|
+
|
503
|
+
fopen_s(&fp,"Log.txt","w"); //ファイル
|
504
|
+
|
505
|
+
|
506
|
+
|
507
|
+
|
508
|
+
|
509
|
+
//描画開始座標
|
510
|
+
|
511
|
+
mDraw_start.X = 0;
|
512
|
+
|
513
|
+
mDraw_start.Y = 0;
|
514
|
+
|
515
|
+
|
516
|
+
|
517
|
+
//描画範囲
|
518
|
+
|
519
|
+
mDraw_size.X = MAX_WIDTH;
|
520
|
+
|
521
|
+
mDraw_size.Y = MAX_HEIGHT;
|
522
|
+
|
523
|
+
|
524
|
+
|
525
|
+
//ウインドウサイズ
|
526
|
+
|
527
|
+
mRect.Left = (SHORT)0;
|
528
|
+
|
529
|
+
mRect.Top = (SHORT)0;
|
530
|
+
|
531
|
+
mRect.Right = (SHORT)MAX_WIDTH;
|
532
|
+
|
533
|
+
mRect.Bottom = (SHORT)MAX_HEIGHT;
|
534
|
+
|
535
|
+
|
536
|
+
|
537
|
+
// バッファーを作成
|
538
|
+
|
539
|
+
mHandle = CreateConsoleScreenBuffer(GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CONSOLE_TEXTMODE_BUFFER, NULL);
|
540
|
+
|
541
|
+
|
542
|
+
|
543
|
+
SetConsoleActiveScreenBuffer(mHandle); //有効にする
|
544
|
+
|
545
|
+
|
546
|
+
|
547
|
+
if (mHandle == INVALID_HANDLE_VALUE)
|
548
|
+
|
549
|
+
{
|
550
|
+
|
551
|
+
fprintf(fp, "Invalid: INVALID_HANDLE_VALUE \n");
|
552
|
+
|
553
|
+
}
|
554
|
+
|
555
|
+
|
556
|
+
|
557
|
+
// 画面バッファサイス変更
|
558
|
+
|
559
|
+
if (SetConsoleScreenBufferSize(mHandle, mDraw_size) == 0)
|
560
|
+
|
561
|
+
{
|
562
|
+
|
563
|
+
fprintf(fp,"Invalid: SetConsoleScreenBufferSize(); \n");
|
564
|
+
|
565
|
+
}
|
566
|
+
|
567
|
+
|
568
|
+
|
569
|
+
// 画面サイズ変更
|
570
|
+
|
571
|
+
if (SetConsoleWindowInfo(mHandle, TRUE, &mRect) != 0)
|
572
|
+
|
573
|
+
{
|
574
|
+
|
575
|
+
fprintf(fp, "Invalid: SetConsoleWindowInfo(); \n");
|
576
|
+
|
577
|
+
}
|
578
|
+
|
579
|
+
|
580
|
+
|
581
|
+
}
|
582
|
+
|
583
|
+
|
584
|
+
|
585
|
+
// バッファーに文字を書き込む
|
586
|
+
|
587
|
+
void DrawCharactor::setDraw(const char* format, ...)
|
588
|
+
|
589
|
+
{
|
590
|
+
|
591
|
+
|
592
|
+
|
593
|
+
va_list ap;
|
594
|
+
|
595
|
+
char str[MAX_WIDTH];
|
596
|
+
|
597
|
+
va_start(ap, format);
|
598
|
+
|
599
|
+
vsprintf_s(str, sizeof(str), format, ap);
|
600
|
+
|
601
|
+
va_end(ap);
|
602
|
+
|
603
|
+
|
604
|
+
|
605
|
+
wchar_t wc[MAX_WIDTH];
|
606
|
+
|
607
|
+
size_t size = sizeof(wc);
|
608
|
+
|
609
|
+
|
610
|
+
|
611
|
+
size_t count = sizeof(wc) / sizeof(wchar_t);
|
612
|
+
|
613
|
+
mbstowcs_s(&size, wc, count, str, count - 1); //マルチ文字をワイド文字に変換
|
614
|
+
|
615
|
+
|
616
|
+
|
617
|
+
// -----------------------------------------------------------------------------------------------
|
618
|
+
|
619
|
+
int i = 0;
|
620
|
+
|
621
|
+
for (; mNowBuffer_width[mNowBuffer_height] <= MAX_WIDTH; mNowBuffer_width[mNowBuffer_height]++) {
|
622
|
+
|
623
|
+
|
624
|
+
|
625
|
+
if (wc[i] != L'\0') {
|
626
|
+
|
627
|
+
|
628
|
+
|
629
|
+
if (mNowBuffer_width[mNowBuffer_height] <= MAX_WIDTH) {
|
630
|
+
|
631
|
+
mScreenBuffer[mNowBuffer_height][mNowBuffer_width[mNowBuffer_height]].Char.UnicodeChar = wc[i];
|
632
|
+
|
633
|
+
mScreenBuffer[mNowBuffer_height][mNowBuffer_width[mNowBuffer_height]].Attributes = FOREGROUND_GREEN;
|
634
|
+
|
635
|
+
// mNowBuffer_width[mNowBuffer_height]++;
|
636
|
+
|
637
|
+
|
638
|
+
|
639
|
+
}
|
640
|
+
|
641
|
+
else
|
642
|
+
|
643
|
+
{
|
644
|
+
|
645
|
+
fprintf(fp,"setDraw() 一行の文字数を超えています。\n");
|
646
|
+
|
647
|
+
}
|
648
|
+
|
649
|
+
i++;
|
650
|
+
|
651
|
+
}
|
652
|
+
|
653
|
+
else {
|
654
|
+
|
655
|
+
break;
|
656
|
+
|
657
|
+
}
|
658
|
+
|
659
|
+
}
|
660
|
+
|
661
|
+
|
662
|
+
|
663
|
+
// -----------------------------------------------------------------------------------------------
|
664
|
+
|
665
|
+
//fprintf(fp, "ああああ\n");
|
666
|
+
|
667
|
+
}
|
668
|
+
|
669
|
+
|
670
|
+
|
671
|
+
|
672
|
+
|
673
|
+
|
674
|
+
|
675
|
+
|
676
|
+
|
677
|
+
// バッファーに文字を書き込む
|
678
|
+
|
679
|
+
void DrawCharactor::setDraw_Line(const char* format, ...)
|
680
|
+
|
681
|
+
{
|
682
|
+
|
683
|
+
|
684
|
+
|
685
|
+
va_list ap;
|
686
|
+
|
687
|
+
char str[MAX_WIDTH];
|
688
|
+
|
689
|
+
va_start(ap, format);
|
690
|
+
|
691
|
+
vsprintf_s(str, sizeof(str), format, ap);
|
692
|
+
|
693
|
+
va_end(ap);
|
694
|
+
|
695
|
+
|
696
|
+
|
697
|
+
wchar_t wc[MAX_WIDTH];
|
698
|
+
|
699
|
+
size_t size = sizeof(wc);
|
700
|
+
|
701
|
+
|
702
|
+
|
703
|
+
size_t count = sizeof(wc) / sizeof(wchar_t);
|
704
|
+
|
705
|
+
mbstowcs_s(&size, wc, count, str, count - 1); //マルチ文字をワイド文字に変換
|
706
|
+
|
707
|
+
|
708
|
+
|
709
|
+
// -----------------------------------------------------------------------------------------------
|
710
|
+
|
711
|
+
int i = 0;
|
712
|
+
|
713
|
+
for (; mNowBuffer_width[mNowBuffer_height] <= MAX_WIDTH; mNowBuffer_width[mNowBuffer_height]++) {
|
714
|
+
|
715
|
+
|
716
|
+
|
717
|
+
if (wc[i] != L'\0') {
|
718
|
+
|
719
|
+
|
720
|
+
|
721
|
+
if (mNowBuffer_width[mNowBuffer_height] <= MAX_WIDTH) {
|
722
|
+
|
723
|
+
mScreenBuffer[mNowBuffer_height][mNowBuffer_width[mNowBuffer_height]].Char.UnicodeChar = wc[i];
|
724
|
+
|
725
|
+
mScreenBuffer[mNowBuffer_height][mNowBuffer_width[mNowBuffer_height]].Attributes = FOREGROUND_GREEN;
|
726
|
+
|
727
|
+
//mNowBuffer_width[mNowBuffer_height]++;
|
728
|
+
|
729
|
+
|
730
|
+
|
731
|
+
}
|
732
|
+
|
733
|
+
else
|
734
|
+
|
735
|
+
{
|
736
|
+
|
737
|
+
fprintf(fp, "setDraw_Line() 一行の文字数を超えています。\n");
|
738
|
+
|
739
|
+
}
|
740
|
+
|
741
|
+
i++;
|
742
|
+
|
743
|
+
}
|
744
|
+
|
745
|
+
else {
|
746
|
+
|
747
|
+
break;
|
748
|
+
|
749
|
+
}
|
750
|
+
|
751
|
+
}
|
752
|
+
|
753
|
+
|
754
|
+
|
755
|
+
mNowBuffer_height++;
|
756
|
+
|
757
|
+
|
758
|
+
|
759
|
+
|
760
|
+
|
761
|
+
// -----------------------------------------------------------------------------------------------
|
762
|
+
|
763
|
+
//fprintf(fp, "ああああ\n");
|
764
|
+
|
765
|
+
}
|
766
|
+
|
767
|
+
|
768
|
+
|
769
|
+
// 描画
|
770
|
+
|
771
|
+
void DrawCharactor::GenerateOutput()
|
772
|
+
|
773
|
+
{
|
774
|
+
|
775
|
+
WriteConsoleOutput(mHandle,mScreenBuffer[0], mDraw_size, mDraw_start, &mRect); //現在のカーソル位置から始まる文字列をコンソール画面バッファーに書き込み
|
776
|
+
|
777
|
+
mNowBuffer_height = 0;
|
778
|
+
|
779
|
+
|
780
|
+
|
781
|
+
for (int i = 0; i < MAX_HEIGHT; i++)
|
782
|
+
|
783
|
+
{
|
784
|
+
|
785
|
+
mNowBuffer_width[i] = 0;
|
786
|
+
|
787
|
+
}
|
788
|
+
|
789
|
+
|
790
|
+
|
791
|
+
}
|
792
|
+
|
793
|
+
|
794
|
+
|
795
|
+
// ハンドルを返す
|
796
|
+
|
797
|
+
HANDLE DrawCharactor::getHandle()
|
798
|
+
|
799
|
+
{
|
800
|
+
|
801
|
+
return mHandle;
|
802
|
+
|
803
|
+
}
|
804
|
+
|
805
|
+
|
806
|
+
|
807
|
+
|
808
|
+
|
809
|
+
// デストラクタ
|
810
|
+
|
811
|
+
DrawCharactor::~DrawCharactor()
|
812
|
+
|
813
|
+
{
|
814
|
+
|
815
|
+
// スクリーンバッファを解放
|
816
|
+
|
817
|
+
CloseHandle(mHandle);
|
818
|
+
|
819
|
+
mHandle = NULL;
|
820
|
+
|
821
|
+
|
822
|
+
|
823
|
+
fclose(fp);
|
824
|
+
|
825
|
+
|
826
|
+
|
827
|
+
}
|
828
|
+
|
829
|
+
```
|
1
提示コードを修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -20,12 +20,200 @@
|
|
20
20
|
|
21
21
|
|
22
22
|
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
|
23
27
|
```cpp
|
24
28
|
|
29
|
+
#include "stdio.h"
|
30
|
+
|
31
|
+
#include "stdlib.h"
|
32
|
+
|
33
|
+
#include <Windows.h>
|
34
|
+
|
35
|
+
#include "stdio.h"
|
36
|
+
|
37
|
+
#include "stdlib.h"
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
#include "DrawCharactor.hpp"
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
|
25
49
|
#include "KeyInput.hpp"
|
26
50
|
|
27
51
|
|
28
52
|
|
53
|
+
// ウインドウサイズ
|
54
|
+
|
55
|
+
#define MAX_WIDTH ((int)100)
|
56
|
+
|
57
|
+
#define MAX_HEIGHT ((int)40)
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
FILE* fp = NULL;
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
int main()
|
68
|
+
|
69
|
+
{
|
70
|
+
|
71
|
+
fopen_s(&fp,"Mian_Log.txt","w");
|
72
|
+
|
73
|
+
DrawCharactor* dc = new DrawCharactor();
|
74
|
+
|
75
|
+
KeyInput* key = new KeyInput(dc->getHandle());
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
int y = 0;
|
84
|
+
|
85
|
+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
86
|
+
|
87
|
+
while (true)
|
88
|
+
|
89
|
+
{
|
90
|
+
|
91
|
+
if (key->getKeyDown(KeyCode::UP_KEY) == true)
|
92
|
+
|
93
|
+
{
|
94
|
+
|
95
|
+
y--;
|
96
|
+
|
97
|
+
fprintf(fp, "UP\n");
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
}
|
102
|
+
|
103
|
+
else if (key->getKeyDown(KeyCode::DOWN_KEY) == true)
|
104
|
+
|
105
|
+
{
|
106
|
+
|
107
|
+
fprintf(fp,"Down\n");
|
108
|
+
|
109
|
+
y++;
|
110
|
+
|
111
|
+
}
|
112
|
+
|
113
|
+
// fprintf(fp, "Down\n");
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
for (int i = 0; i < 5; i++)
|
120
|
+
|
121
|
+
{
|
122
|
+
|
123
|
+
if (y == i)
|
124
|
+
|
125
|
+
{
|
126
|
+
|
127
|
+
dc->setDraw("-> ");
|
128
|
+
|
129
|
+
dc->setDraw_Line("AAAA");
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
}
|
134
|
+
|
135
|
+
else
|
136
|
+
|
137
|
+
{
|
138
|
+
|
139
|
+
dc->setDraw_Line("AAAA");
|
140
|
+
|
141
|
+
}
|
142
|
+
|
143
|
+
}
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
/// dc->setDraw_Line("Menu ");
|
162
|
+
|
163
|
+
// dc->setDraw_Line("test");
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
dc->GenerateOutput();
|
176
|
+
|
177
|
+
}
|
178
|
+
|
179
|
+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
delete dc;
|
184
|
+
|
185
|
+
delete key;
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
fclose(fp);
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
return 0;
|
200
|
+
|
201
|
+
}
|
202
|
+
|
203
|
+
```
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
```cpp
|
212
|
+
|
213
|
+
#include "KeyInput.hpp"
|
214
|
+
|
215
|
+
|
216
|
+
|
29
217
|
KeyInput::KeyInput(HANDLE h)
|
30
218
|
|
31
219
|
{
|