質問編集履歴
2
編集
title
CHANGED
File without changes
|
body
CHANGED
@@ -285,4 +285,97 @@
|
|
285
285
|
// 終了
|
286
286
|
return 0;
|
287
287
|
}
|
288
|
+
```
|
289
|
+
|
290
|
+
if文のmodoruを使っていたプログラムを正しく動くように書き直しました。
|
291
|
+
```
|
292
|
+
#include "DxLib.h"
|
293
|
+
|
294
|
+
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
|
295
|
+
{
|
296
|
+
char String[256];
|
297
|
+
int InputHandle;
|
298
|
+
int modoru = 0;
|
299
|
+
int modoruframe = 0;
|
300
|
+
|
301
|
+
SetGraphMode(700, 780, 32); // ウィンドウの大きさを指定
|
302
|
+
ChangeWindowMode(TRUE); // 全画面ではなくウインドウを使用
|
303
|
+
// DXライブラリの初期化
|
304
|
+
if (DxLib_Init() == -1) return -1;
|
305
|
+
|
306
|
+
// 描画先を裏にする
|
307
|
+
SetDrawScreen(DX_SCREEN_BACK);
|
308
|
+
|
309
|
+
// キー入力ハンドルを作る(キャンセルなし全角文字有り数値入力じゃなし)
|
310
|
+
InputHandle = MakeKeyInput(50, FALSE, FALSE, FALSE);
|
311
|
+
|
312
|
+
// 作成したキー入力ハンドルをアクティブにする
|
313
|
+
SetActiveKeyInput(InputHandle);
|
314
|
+
|
315
|
+
// キー入力終了待ちループ
|
316
|
+
// (ProcessMessageをループごとに行う)
|
317
|
+
if (modoru == 0) {
|
318
|
+
|
319
|
+
while (ProcessMessage() == 0)
|
320
|
+
{
|
321
|
+
|
322
|
+
// 画面の初期化
|
323
|
+
ClearDrawScreen();
|
324
|
+
|
325
|
+
//まずは描画する部分から作る。
|
326
|
+
// 入力モードを描画
|
327
|
+
DrawKeyInputModeString(640, 480);
|
328
|
+
// 入力途中の文字列を描画
|
329
|
+
DrawKeyInputString(0, 0, InputHandle);
|
330
|
+
// 入力が終了している場合は終了
|
331
|
+
//エンターキーが押されていないとき
|
332
|
+
if (CheckKeyInput(InputHandle) != 0) {
|
333
|
+
|
334
|
+
// 入力された文字列を取得
|
335
|
+
GetKeyInputString(String, InputHandle);
|
336
|
+
DrawString(0, 0, String, GetColor(255, 255, 255));
|
337
|
+
|
338
|
+
// DrawFormatString(100, 150, GetColor(255, 255, 0), "ProcessMessage()は%d,modoruは%d", ProcessMessage(), modoru);
|
339
|
+
modoru = 1;
|
340
|
+
// 裏画面の内容を表画面に反映させる
|
341
|
+
|
342
|
+
// 再度インプットハンドルをアクティブにする
|
343
|
+
SetActiveKeyInput(InputHandle);
|
344
|
+
// 入力文字列を初期化する
|
345
|
+
SetKeyInputString("", InputHandle);
|
346
|
+
}
|
347
|
+
// 入力された文字列を画面に表示する
|
348
|
+
//関数ProcessMessage()にエラーがない限りループの外には出ず、ループはずっと続くのでProcessMessage()内にif文を書いた。
|
349
|
+
if (modoru == 1) {
|
350
|
+
// DrawString(0, 300, "あなたが入力した文字列は", GetColor(255, 255, 255));
|
351
|
+
DrawString(0, 16, String, GetColor(255, 255, 255));
|
352
|
+
|
353
|
+
}
|
354
|
+
|
355
|
+
//ProcessMessage()は1のままでここに書くことで上のif文の描画関数すべて関わるのでここにScreenFlip()を描けばよい。
|
356
|
+
ScreenFlip();
|
357
|
+
|
358
|
+
}
|
359
|
+
}
|
360
|
+
|
361
|
+
|
362
|
+
// 用済みのインプットハンドルを削除する
|
363
|
+
DeleteKeyInput(InputHandle);
|
364
|
+
|
365
|
+
ClearDrawScreen();
|
366
|
+
|
367
|
+
|
368
|
+
// 裏画面の内容を表画面に反映させる
|
369
|
+
ScreenFlip();
|
370
|
+
|
371
|
+
// キー入力待ち
|
372
|
+
// WaitKey();
|
373
|
+
|
374
|
+
// DXライブラリの使用終了
|
375
|
+
DxLib_End();
|
376
|
+
|
377
|
+
// 終了
|
378
|
+
return 0;
|
379
|
+
}
|
380
|
+
|
288
381
|
```
|
1
編集
title
CHANGED
File without changes
|
body
CHANGED
@@ -178,4 +178,111 @@
|
|
178
178
|
//return 0;
|
179
179
|
}
|
180
180
|
|
181
|
+
```
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
あの後、epistemeさんから頂いたプログラムを自分なりに少しいじり、あることに気が付いたのですが、
|
186
|
+
char buffer[256];を使わずに、関数strcmpを使うと、関数strcmpの方で入力した文字をバッファに入れるなどを自動でやってくれているためchar buffer[256];を使わなくても同じような結果が得られたのでしょうか?
|
187
|
+
```
|
188
|
+
#include "DxLib.h"
|
189
|
+
#include <string>
|
190
|
+
|
191
|
+
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
|
192
|
+
{
|
193
|
+
char String[256];
|
194
|
+
int InputHandle;
|
195
|
+
int modoru = 0;
|
196
|
+
std::string input;
|
197
|
+
std::string message;
|
198
|
+
int duration = 0;
|
199
|
+
|
200
|
+
SetGraphMode(700, 780, 32); // ウィンドウの大きさを指定
|
201
|
+
ChangeWindowMode(TRUE); // 全画面ではなくウインドウを使用
|
202
|
+
// DXライブラリの初期化
|
203
|
+
if (DxLib_Init() == -1) return -1;
|
204
|
+
|
205
|
+
// 描画先を裏にする
|
206
|
+
SetDrawScreen(DX_SCREEN_BACK);
|
207
|
+
|
208
|
+
// キー入力ハンドルを作る(キャンセルなし全角文字有り数値入力じゃなし)
|
209
|
+
InputHandle = MakeKeyInput(50, FALSE, FALSE, FALSE);
|
210
|
+
|
211
|
+
// 作成したキー入力ハンドルをアクティブにする
|
212
|
+
SetActiveKeyInput(InputHandle);
|
213
|
+
|
214
|
+
// キー入力終了待ちループ
|
215
|
+
// (ProcessMessageをループごとに行う)
|
216
|
+
|
217
|
+
while (ProcessMessage() == 0)
|
218
|
+
{
|
219
|
+
|
220
|
+
// 画面の初期化
|
221
|
+
ClearDrawScreen();
|
222
|
+
|
223
|
+
//まずは描画する部分から作る。
|
224
|
+
// 入力モードを描画
|
225
|
+
DrawKeyInputModeString(640, 480);
|
226
|
+
// 入力途中の文字列を描画
|
227
|
+
DrawKeyInputString(0, 0, InputHandle);
|
228
|
+
|
229
|
+
|
230
|
+
//その後にif文での分岐を考える。
|
231
|
+
// 入力が終了している場合は終了
|
232
|
+
//ループ内とは言えエンターキー一回でCheckKeyInputが呼べればいい。
|
233
|
+
//エンターキーが押されていないとき?の部分。
|
234
|
+
if (CheckKeyInput(InputHandle) != 0) {
|
235
|
+
// 入力された文字列を取得
|
236
|
+
// char buffer[256];//
|
237
|
+
// 入力された文字列を取得
|
238
|
+
GetKeyInputString(String, InputHandle);
|
239
|
+
// input = buffer;
|
240
|
+
DrawString(0, 0, String, GetColor(255, 255, 255));
|
241
|
+
if (strcmp(String, "hello") == 0) {
|
242
|
+
message = "hello! my friend!!";
|
243
|
+
}
|
244
|
+
else {
|
245
|
+
message = "not 'hello'";
|
246
|
+
}
|
247
|
+
duration = 1;
|
248
|
+
// 再度インプットハンドルをアクティブにする
|
249
|
+
SetActiveKeyInput(InputHandle);
|
250
|
+
// 入力文字列を初期化する
|
251
|
+
SetKeyInputString("", InputHandle);
|
252
|
+
|
253
|
+
}
|
254
|
+
|
255
|
+
// DrawFormatString(100, 150, GetColor(255, 255, 0), "ProcessMessage()は%d,modoruは%d", ProcessMessage(), modoru);
|
256
|
+
|
257
|
+
DrawString(100, 500, message.c_str(), GetColor(200, 200, 255));
|
258
|
+
|
259
|
+
// 裏画面の内容を表画面に反映させる
|
260
|
+
ScreenFlip();
|
261
|
+
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
|
266
|
+
}
|
267
|
+
|
268
|
+
// 用済みのインプットハンドルを削除する
|
269
|
+
DeleteKeyInput(InputHandle);
|
270
|
+
|
271
|
+
// 画面の初期化
|
272
|
+
ClearDrawScreen();
|
273
|
+
|
274
|
+
|
275
|
+
// 裏画面の内容を表画面に反映させる
|
276
|
+
ScreenFlip();
|
277
|
+
|
278
|
+
// キー入力待ち
|
279
|
+
// WaitKey();
|
280
|
+
|
281
|
+
//ループないやループから出た後で何かしらの問題が発生したら終了する。
|
282
|
+
// DXライブラリの使用終了
|
283
|
+
DxLib_End();
|
284
|
+
|
285
|
+
// 終了
|
286
|
+
return 0;
|
287
|
+
}
|
181
288
|
```
|