Windowsでウィンドウサイズの修正

諏訪子 <suwako@076.moe>、2026-05-03 20:15
コミット a8eae150d48de6e696aae12b71c43488231a66d2 ・親 6415199 ・ファイルを見る

1個のファイル、+55 -1

@@ -94,6 +94,40 @@
9494
9595 // ncurses
9696 initscr();
97+#ifdef _WIN32
98+ HWND console = GetConsoleWindow();
99+ if (console) {
100+ LONG style = GetWindowLong(console, GWL_STYLE);
101+ style |= WS_MAXIMIZEBOX | WS_THICKFRAME;
102+ SetWindowLong(console, GWL_STYLE, style);
103+
104+ const int MIN_WIDTH = 100;
105+ const int MIN_HEIGHT = 30;
106+
107+ HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
108+ CONSOLE_SCREEN_BUFFER_INFO csbi;
109+ GetConsoleScreenBufferInfo(hOut, &csbi);
110+
111+ RECT rect;
112+ GetWindowRect(console, &rect);
113+
114+ int cw = csbi.srWindow.Right - csbi.srWindow.Left + 1;
115+ int ch = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
116+
117+ MINMAXINFO mmi = {};
118+ mmi.ptMinTrackSize.x = MIN_WIDTH * 8;
119+ mmi.ptMinTrackSize.y = MIN_HEIGHT * 16;
120+
121+ COORD minBuf = { MIN_WIDTH, MIN_HEIGHT };
122+ SetConsoleScreenBufferSize(hOut, minBuf);
123+
124+ SMALL_RECT rectWin = { 0, 0, MIN_WIDTH - 1, MIN_HEIGHT - 1 };
125+ SetConsoleWindowInfo(hOut, TRUE, &rectWin);
126+ }
127+
128+ resize_term(40, 120);
129+#endif
130+ getmaxyx(stdscr, rows, cols);
97131 clearok(stdscr, TRUE);
98132 cbreak();
99133 noecho();
@@ -935,11 +969,31 @@
935969
936970 ch = getch();
937971
972+ if (ch == KEY_RESIZE) {
973+ getmaxyx(stdscr, rows, cols);
974+ delwin(hexPanel);
975+ delwin(asciiPanel);
976+
977+ bpr = std::min<size_t>(16, (cols / 2 - 10) / 4);
978+ if (bpr < 4) bpr = 4;
979+
980+ hexPanel = newwin(rows - 3, cols / 2, 1, 0);
981+ asciiPanel = newwin(rows - 3, cols / 2, 1, cols / 2);
982+
983+ scrollok(hexPanel, TRUE);
984+ scrollok(asciiPanel, TRUE);
985+ wattrset(hexPanel, COLOR_PAIR(8));
986+ wattrset(asciiPanel, COLOR_PAIR(8));
987+
988+ render();
989+ continue;
990+ }
991+
938992 if (!hasFile && ch != ':' && ch != 'Z') {
939993 statusMode = Status_Error;
940994 statusText = "ファイルを読み込んでいません。「:o <file>」を御利用下さい。";
941995 render();
942- return;
996+ continue;
943997 }
944998
945999 if ((ch == 'j' || ch == KEY_DOWN) && curPos + bpr < buf.size()) {