Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma warning(disable: 4996)
- #include "DxLib.h"
- #include <mecab.h>
- #pragma comment(lib, "libmecab.lib")
- int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
- {
- SetGraphMode(1500, 780, 32); // ウィンドウの大きさを指定
- ChangeWindowMode(TRUE); // 全画面ではなくウインドウを使用
- if (DxLib_Init() == -1) return -1; // DXライブラリの初期化
- SetFontSize(33); // サイズを変更
- SetDrawScreen(DX_SCREEN_BACK); // 描画先を裏にする
- int InputHandle = MakeKeyInput(256, FALSE, FALSE, FALSE);
- SetActiveKeyInput(InputHandle); // 作成したキー入力ハンドルをアクティブにする
- char buffer[256];
- const char *result = "";
- char buf[4096];
- const char *words[100];
- int n = 0;
- unsigned word_color = GetColor(0, 255, 255);
- while (ProcessMessage() == 0) {
- ClearDrawScreen(); // 画面の初期化
- DrawKeyInputModeString(1500, 0); // 入力モードを描画
- DrawKeyInputString(0, 0, InputHandle); // 入力途中の文字列を描画
- if (CheckKeyInput(InputHandle) != 0) { //エンターキーが押された時
- GetKeyInputString(buffer, InputHandle); // 入力された文字列を取得
- MeCab::Tagger* tagger = MeCab::createTagger("");
- result = tagger->parse(buffer);
- strcpy_s(buf, sizeof buf, result);
- delete tagger;
- n = 0;
- words[n] = strtok(buf, "\t\n");
- while (n < 100 && words[n]) {
- strtok(NULL, "\t\n");
- words[++n] = strtok(NULL, "\t\n");
- }
- SetActiveKeyInput(InputHandle); // 再度インプットハンドルをアクティブにする
- SetKeyInputString("", InputHandle); // 入力文字列を初期化する
- }
- //DrawFormatString(100, 600, GetColor(175, 80, 100), "resultは%s", result);
- for (int i = 0; i < n; i++)
- DrawString(100, 200 + i*40, words[i], word_color);
- ScreenFlip(); // 裏画面の内容を表画面に反映させる
- }
- DeleteKeyInput(InputHandle); // 用済みのインプットハンドルを削除する
- DxLib_End(); // DXライブラリの使用終了
- return 0;
- }
Add Comment
Please, Sign In to add comment