Guest User

Untitled

a guest
Aug 3rd, 2020
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.30 KB | None | 0 0
  1. #pragma warning(disable: 4996)
  2. #include "DxLib.h"
  3. #include <mecab.h>
  4. #pragma comment(lib, "libmecab.lib")
  5.  
  6. int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
  7. {
  8.     SetGraphMode(1500, 780, 32);        // ウィンドウの大きさを指定
  9.     ChangeWindowMode(TRUE);             // 全画面ではなくウインドウを使用
  10.     if (DxLib_Init() == -1) return -1;  // DXライブラリの初期化
  11.     SetFontSize(33);                    // サイズを変更
  12.     SetDrawScreen(DX_SCREEN_BACK);      // 描画先を裏にする
  13.     int InputHandle = MakeKeyInput(256, FALSE, FALSE, FALSE);
  14.     SetActiveKeyInput(InputHandle); // 作成したキー入力ハンドルをアクティブにする
  15.     char buffer[256];
  16.     const char *result = "";
  17.     char buf[4096];
  18.     const char *words[100];
  19.     int n = 0;
  20.     unsigned word_color = GetColor(0, 255, 255);
  21.  
  22.     while (ProcessMessage() == 0) {
  23.         ClearDrawScreen(); // 画面の初期化
  24.         DrawKeyInputModeString(1500, 0); // 入力モードを描画
  25.         DrawKeyInputString(0, 0, InputHandle); // 入力途中の文字列を描画
  26.  
  27.         if (CheckKeyInput(InputHandle) != 0) { //エンターキーが押された時
  28.             GetKeyInputString(buffer, InputHandle); // 入力された文字列を取得
  29.  
  30.             MeCab::Tagger* tagger = MeCab::createTagger("");
  31.             result = tagger->parse(buffer);
  32.             strcpy_s(buf, sizeof buf, result);
  33.             delete tagger;
  34.             n = 0;
  35.             words[n] = strtok(buf, "\t\n");
  36.             while (n < 100 && words[n]) {
  37.                 strtok(NULL, "\t\n");
  38.                 words[++n] = strtok(NULL, "\t\n");
  39.             }
  40.  
  41.             SetActiveKeyInput(InputHandle); // 再度インプットハンドルをアクティブにする
  42.             SetKeyInputString("", InputHandle); // 入力文字列を初期化する
  43.         }
  44.         //DrawFormatString(100, 600, GetColor(175, 80, 100), "resultは%s", result);
  45.         for (int i = 0; i < n; i++)
  46.             DrawString(100, 200 + i*40, words[i], word_color);
  47.  
  48.         ScreenFlip(); // 裏画面の内容を表画面に反映させる
  49.     }
  50.     DeleteKeyInput(InputHandle); // 用済みのインプットハンドルを削除する
  51.     DxLib_End(); // DXライブラリの使用終了
  52.     return 0;
  53. }
Add Comment
Please, Sign In to add comment