質問編集履歴
4
編集
title
CHANGED
File without changes
|
body
CHANGED
@@ -327,4 +327,6 @@
|
|
327
327
|
//return 0;
|
328
328
|
}
|
329
329
|
|
330
|
-
```
|
330
|
+
```
|
331
|
+
|
332
|
+
[epistemeさんのおかげで解決しました。こちらに正しいコードが載っています。](https://teratail.com/questions/270866)
|
3
編集
title
CHANGED
File without changes
|
body
CHANGED
@@ -131,4 +131,200 @@
|
|
131
131
|
//return 0;
|
132
132
|
}
|
133
133
|
コード
|
134
|
+
```
|
135
|
+
|
136
|
+
解決のための参考になると思いこちらの[サイト](https://dxlib.xsrv.jp/cgi/patiobbs/patio.cgi?mode=past&no=1467)から
|
137
|
+
```
|
138
|
+
include "DxLib.h"
|
139
|
+
#include <string.h>
|
140
|
+
|
141
|
+
int InputHandle ; // 入力ハンドル
|
142
|
+
|
143
|
+
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
144
|
+
LPSTR lpCmdLine, int nCmdShow )
|
145
|
+
{
|
146
|
+
|
147
|
+
// ウィンドウモードで起動
|
148
|
+
ChangeWindowMode( TRUE );
|
149
|
+
|
150
|
+
// DXライブラリ初期化
|
151
|
+
if( DxLib_Init() == -1 )
|
152
|
+
{
|
153
|
+
return -1 ;
|
154
|
+
}
|
155
|
+
|
156
|
+
// 入力領域と文字出力領域との境界線を引く
|
157
|
+
DrawLine( 0 , 320 , 640 , 320 , GetColor( 255 , 255 , 255 ) ) ;
|
158
|
+
|
159
|
+
|
160
|
+
// 文字列入力ハンドルを作成する
|
161
|
+
InputHandle = MakeKeyInput( 80 , FALSE , FALSE , FALSE ) ;
|
162
|
+
|
163
|
+
// 作成した入力ハンドルをアクティブにする
|
164
|
+
SetActiveKeyInput( InputHandle ) ;
|
165
|
+
|
166
|
+
SetKeyInputString( "ここに文章を入力してください" , InputHandle ) ;
|
167
|
+
|
168
|
+
// チャットループ
|
169
|
+
while( !ProcessMessage() )
|
170
|
+
{
|
171
|
+
// 文字列の入力が終っている場合
|
172
|
+
if( CheckKeyInput( InputHandle ) == 1 )
|
173
|
+
{
|
174
|
+
char Message[ 81 ] ;
|
175
|
+
|
176
|
+
// 入力された文字列を取得する
|
177
|
+
GetKeyInputString( Message , InputHandle ) ;
|
178
|
+
|
179
|
+
// 文字列表示域を黒で塗りつぶす
|
180
|
+
DrawBox( 0 , 0 , 640 , 320 , 0 , TRUE ) ;
|
181
|
+
|
182
|
+
// 入力した文字を描写する
|
183
|
+
DrawString( 0 , 0 , Message , GetColor( 255 , 255 , 255 ) ) ;
|
184
|
+
|
185
|
+
// 再度インプットハンドルをアクティブにする
|
186
|
+
SetActiveKeyInput( InputHandle ) ;
|
187
|
+
|
188
|
+
// 入力文字列を初期化する
|
189
|
+
SetKeyInputString( "" , InputHandle ) ;
|
190
|
+
|
191
|
+
}
|
192
|
+
|
193
|
+
// 画面に入力中の文字列を描画する
|
194
|
+
DrawBox( 0 , 320 + 2 , 640 , 480 , 0 , TRUE ) ;
|
195
|
+
DrawKeyInputString( 0 , 320 + 2 , InputHandle ) ;
|
196
|
+
DrawKeyInputModeString( 640 , 480 ) ;
|
197
|
+
}
|
198
|
+
|
199
|
+
// 時間待ち
|
200
|
+
WaitTimer( 3000 ) ;
|
201
|
+
|
202
|
+
DxLib_End() ; // DXライブラリ使用の終了処理
|
203
|
+
|
204
|
+
return 0 ; // ソフトの終了
|
205
|
+
}
|
206
|
+
コード
|
207
|
+
```
|
208
|
+
を参考にしました。ループが終わった際に再び文字入力を行うことでループから出ない?ようにしていると読み取れたのですが、while( !ProcessMessage() )はエラーが起きたらループから抜けるという部分で合っていますか?
|
209
|
+
|
210
|
+
過程段階ではありますが、以下のようにサイトを参考にして修正しました。
|
211
|
+
```
|
212
|
+
#include "DxLib.h"
|
213
|
+
#include "string.h" //strcmp、strncmp関数を使うために必要
|
214
|
+
|
215
|
+
int konnnitiwasound = 0;
|
216
|
+
int situreisimasitasound = 0;
|
217
|
+
|
218
|
+
int Key[256]; // キーが押されているフレーム数を格納する
|
219
|
+
|
220
|
+
// キーの入力状態を更新する
|
221
|
+
int gpUpdateKey() {
|
222
|
+
char tmpKey[256]; // 現在のキーの入力状態を格納する
|
223
|
+
GetHitKeyStateAll(tmpKey); // 全てのキーの入力状態を得る
|
224
|
+
for (int i = 0; i < 256; i++) {
|
225
|
+
if (tmpKey[i] != 0) { // i番のキーコードに対応するキーが押されていたら
|
226
|
+
Key[i]++; // 加算
|
227
|
+
}
|
228
|
+
else { // 押されていなければ
|
229
|
+
Key[i] = 0; // 0にする
|
230
|
+
}
|
231
|
+
}
|
232
|
+
return 0;
|
233
|
+
}
|
234
|
+
|
235
|
+
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
|
236
|
+
{
|
237
|
+
|
238
|
+
// 使用する文字コードを UTF-8 に設定
|
239
|
+
///SetUseCharCodeFormat(DX_CHARCODEFORMAT_UTF8);
|
240
|
+
char String[256];
|
241
|
+
int InputHandle;
|
242
|
+
|
243
|
+
SetGraphMode(700, 780, 32); // ウィンドウの大きさを指定
|
244
|
+
ChangeWindowMode(TRUE); // 全画面ではなくウインドウを使用
|
245
|
+
if (DxLib_Init() == -1) return -1; // DXライブラリ初期化処理
|
246
|
+
SetDrawScreen(DX_SCREEN_BACK); // 裏画面を使用する設定
|
247
|
+
SetFontSize(64); //サイズを64に変更
|
248
|
+
|
249
|
+
// キー入力ハンドルを作る(キャンセルなし全角文字有り数値入力じゃなし)
|
250
|
+
InputHandle = MakeKeyInput(50, FALSE, FALSE, FALSE);
|
251
|
+
|
252
|
+
// 作成したキー入力ハンドルをアクティブにする
|
253
|
+
SetActiveKeyInput(InputHandle);
|
254
|
+
|
255
|
+
|
256
|
+
// キー入力終了待ちループ
|
257
|
+
// (ProcessMessageをループごとに行う)
|
258
|
+
while (!ProcessMessage())
|
259
|
+
{
|
260
|
+
// 入力が終了している場合は終了
|
261
|
+
if (CheckKeyInput(InputHandle) != 0) {
|
262
|
+
// 入力された文字列を取得する
|
263
|
+
GetKeyInputString(String, InputHandle);
|
264
|
+
|
265
|
+
|
266
|
+
// 入力した文字を描写する
|
267
|
+
DrawString(0, 0,String, GetColor(255, 255, 255));
|
268
|
+
|
269
|
+
// 再度インプットハンドルをアクティブにする
|
270
|
+
SetActiveKeyInput(InputHandle);
|
271
|
+
|
272
|
+
}
|
273
|
+
|
274
|
+
// 画面の初期化
|
275
|
+
ClearDrawScreen();
|
276
|
+
|
277
|
+
// 入力モードを描画
|
278
|
+
DrawKeyInputModeString(640, 480);
|
279
|
+
|
280
|
+
// 入力途中の文字列を描画
|
281
|
+
DrawKeyInputString(0, 0, InputHandle);
|
282
|
+
|
283
|
+
// 裏画面の内容を表画面に反映させる
|
284
|
+
ScreenFlip();
|
285
|
+
}
|
286
|
+
|
287
|
+
// 入力された文字列を取得
|
288
|
+
GetKeyInputString(String, InputHandle);
|
289
|
+
|
290
|
+
// 用済みのインプットハンドルを削除する
|
291
|
+
DeleteKeyInput(InputHandle);
|
292
|
+
|
293
|
+
// 画面の初期化
|
294
|
+
ClearDrawScreen();
|
295
|
+
|
296
|
+
// 入力された文字列を画面に表示する
|
297
|
+
///DrawString(0, 0, "あなたが入力した文字列は", GetColor(255, 255, 255));
|
298
|
+
DrawString(0, 0, String, GetColor(255, 255, 255));
|
299
|
+
|
300
|
+
//StringはUFT-8方式で作られたので、UFT-8方式で処理されて正常に表示される
|
301
|
+
DrawString(0, 0, String, GetColor(255, 255, 255));
|
302
|
+
//比較文字列同士の文字コードが異なるのでTRUEが帰ることはない
|
303
|
+
if (strcmp(String, "hello") == 0)
|
304
|
+
{
|
305
|
+
//そもそもここは通れない。
|
306
|
+
//"あいうえおおおおおおおおアインシュタイン!"はShift-JISなので、UFT-8方式で処理しようとしてもうまく行かない
|
307
|
+
DrawString(100, 500, "hello! my friend!!", GetColor(200, 200, 255));
|
308
|
+
konnnitiwasound = LoadSoundMem("line-girl1-konnichiha1.mp3");
|
309
|
+
PlaySoundMem(konnnitiwasound, DX_PLAYTYPE_BACK);
|
310
|
+
}
|
311
|
+
else {
|
312
|
+
situreisimasitasound = LoadSoundMem("line-girl1-moushiwakegozamasen1.mp3");
|
313
|
+
PlaySoundMem(situreisimasitasound, DX_PLAYTYPE_BACK);
|
314
|
+
}
|
315
|
+
|
316
|
+
|
317
|
+
// 裏画面の内容を表画面に反映させる
|
318
|
+
ScreenFlip();
|
319
|
+
|
320
|
+
// キー入力待ち
|
321
|
+
WaitKey();
|
322
|
+
|
323
|
+
// DXライブラリの使用終了
|
324
|
+
DxLib_End();
|
325
|
+
|
326
|
+
// 終了
|
327
|
+
//return 0;
|
328
|
+
}
|
329
|
+
|
134
330
|
```
|
2
偏執
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
### 前提・実現したいこと
|
2
2
|
環境はWindows10、DXライブラリ、VS2019です。
|
3
|
-
**キー入力を行ってもウィンドウが閉じることなく、
|
3
|
+
**キー入力を行ってもウィンドウが閉じることなく、前回入力した文字がリセットされ、新しく文字を入力できるようにしたい。**
|
4
4
|
|
5
5
|
### 発生している問題・エラーメッセージ
|
6
6
|
|
1
修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -30,7 +30,23 @@
|
|
30
30
|
int konnnitiwasound = 0;
|
31
31
|
int situreisimasitasound = 0;
|
32
32
|
|
33
|
+
int Key[256]; // キーが押されているフレーム数を格納する
|
33
34
|
|
35
|
+
// キーの入力状態を更新する
|
36
|
+
int gpUpdateKey() {
|
37
|
+
char tmpKey[256]; // 現在のキーの入力状態を格納する
|
38
|
+
GetHitKeyStateAll(tmpKey); // 全てのキーの入力状態を得る
|
39
|
+
for (int i = 0; i < 256; i++) {
|
40
|
+
if (tmpKey[i] != 0) { // i番のキーコードに対応するキーが押されていたら
|
41
|
+
Key[i]++; // 加算
|
42
|
+
}
|
43
|
+
else { // 押されていなければ
|
44
|
+
Key[i] = 0; // 0にする
|
45
|
+
}
|
46
|
+
}
|
47
|
+
return 0;
|
48
|
+
}
|
49
|
+
|
34
50
|
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
|
35
51
|
{
|
36
52
|
|
@@ -57,7 +73,7 @@
|
|
57
73
|
while (!ProcessMessage())
|
58
74
|
{
|
59
75
|
// 入力が終了している場合は終了
|
60
|
-
if (CheckKeyInput(InputHandle) =
|
76
|
+
if (CheckKeyInput(InputHandle) != 0) break;
|
61
77
|
|
62
78
|
// 画面の初期化
|
63
79
|
ClearDrawScreen();
|
@@ -91,7 +107,7 @@
|
|
91
107
|
if (strcmp(String, "hello") == 0)
|
92
108
|
{
|
93
109
|
//そもそもここは通れない。
|
94
|
-
//Shift-JISなので、UFT-8方式で処理しようとしてもうまく行かない
|
110
|
+
//"あいうえおおおおおおおおアインシュタイン!"はShift-JISなので、UFT-8方式で処理しようとしてもうまく行かない
|
95
111
|
DrawString(100, 500, "hello! my friend!!", GetColor(200, 200, 255));
|
96
112
|
konnnitiwasound = LoadSoundMem("line-girl1-konnichiha1.mp3");
|
97
113
|
PlaySoundMem(konnnitiwasound, DX_PLAYTYPE_BACK);
|