ボーダレスでなければならないコンソール アプリケーションを作成しています。これを実現するために、以下に示すように、コンソール ウィンドウのスタイルとウィンドウ領域を変更しました。
ある時点で、コンソール ウィンドウが通常 2x1 文字のサイズで表示されるか、完全にバグが発生する (クライアント領域が見えない、一部が白、一部が透明、ランダムな境界線など) という問題に遭遇しました
。ShowWindow(hWnd, SW_HIDE);
現在の行は問題を解決します。やった。
そもそもなぜ問題が発生したのか、それを防ぐ方法が他にあるかどうかを突き止めようとしています。
Windows がプログラムと同時にウィンドウのプロパティ (位置、スタイル、サイズなど) にアクセスしようとするため、問題が発生する可能性があると言われました。これが本当かどうかはわかりませんが。
#include <Windows.h>
#include <iostream>
int main()
{
HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE);
SMALL_RECT srWnd = {0, 0, 1, 1};
SetConsoleWindowInfo(hCon, 1, &srWnd);
COORD cBuffSize = {81, 26};
SetConsoleScreenBufferSize(hCon, cBuffSize);
srWnd.Top = 0;
srWnd.Right = 80;
srWnd.Bottom = 25;
srWnd.Left = 0;
SetConsoleWindowInfo(hCon, 1, &srWnd);
// When the next two lines are moved so that they are the first two lines inside main(), the window gets bugged.
HWND hWnd = GetConsoleWindow();
ShowWindow(hWnd, SW_HIDE); // Or if you just remove this line
RECT rClnt;
GetClientRect(hWnd, &rClnt);
SetWindowLong(hWnd, GWL_STYLE, WS_POPUP);
LONG exStyle = GetWindowLong(hWnd, GWL_EXSTYLE);
exStyle &= ~(WS_EX_CLIENTEDGE | WS_EX_APPWINDOW);
SetWindowLongPtr(hWnd, GWL_EXSTYLE, exStyle | WS_EX_TOOLWINDOW);
rClnt.right += 1;
HRGN rgnClnt = CreateRectRgnIndirect(&rClnt);
SetWindowRgn(hWnd, rgnClnt, 1);
RECT rScrn;
GetWindowRect(GetDesktopWindow(), &rScrn);
SetWindowPos(hWnd, HWND_TOPMOST, rScrn.right / 2 - rClnt.right / 2, rScrn.bottom / 2 - rClnt.bottom / 2, 0, 0, SWP_NOSIZE | SWP_FRAMECHANGED);
ShowWindow(hWnd, SW_SHOW);
std::cin.get();
return 0;
}