int top = どこからか取得
int left = どこからか取得
int windowHeight = どこからか取得
int windowWidth = どこからか取得;
if (windowHeight > 0 && windowWidth > 0
&& top > 0 && left > 0
) {
// スクリーンの解像度を取得
int screenWidth = GetSystemMetrics(SM_CXSCREEN);
int screenHeight = GetSystemMetrics(SM_CYSCREEN);
// ウインドウが画面内に収まるように調整
if (left + windowWidth > screenWidth) {
left = screenWidth - windowWidth;
}
if (top + windowHeight > screenHeight) {
top = screenHeight - windowHeight;
}
// 左上が画面内に収まるように調整
left = max(0, left);
top = max(0, top);
// ウインドウの位置とサイズを設定
SetWindowPos(NULL, left, top, windowWidth, windowHeight, SWP_NOZORDER);
}