You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用纯winbgi设置BGI窗口大小?(不含graphics.h、winbgim)

解决WinBGI窗口大小设置问题

纯WinBGI未提供直接的窗口初始化大小配置函数,你可以借助它封装的Windows底层窗口句柄,调用原生Windows API来调整窗口尺寸:

  1. 获取WinBGI窗口句柄
    WinBGI实例对象提供了获取底层窗口句柄的方法,通过getHWND()即可拿到:
HWND hWnd = win.getHWND();
  1. 调用Windows API调整窗口
    使用SetWindowPos或MoveWindow函数设置窗口宽高与位置。以下示例将窗口设为800x600并居中显示:
#include <windows.h> // 需引入Windows API头文件

// 计算居中位置
int screenWidth = GetSystemMetrics(SM_CXSCREEN);
int screenHeight = GetSystemMetrics(SM_CYSCREEN);
int targetWidth = 800;
int targetHeight = 600;
int xPos = (screenWidth - targetWidth) / 2;
int yPos = (screenHeight - targetHeight) / 2;

// 用SetWindowPos设置窗口参数
SetWindowPos(hWnd, NULL, xPos, yPos, targetWidth, targetHeight, SWP_NOZORDER | SWP_NOACTIVATE);

// 也可使用MoveWindow实现相同效果
// MoveWindow(hWnd, xPos, yPos, targetWidth, targetHeight, TRUE);
  1. 关键注意点
  • 需在WinBGI窗口初始化完成后调用这些API,比如win.begin()执行之后。
  • SWP_NOZORDER和SWP_NOACTIVATE参数用于保持窗口原有层级与激活状态,可根据需求调整。
  • 若仅需调整大小无需改变位置,可先用GetWindowRect获取当前窗口位置,再传入对应坐标参数。

内容的提问来源于stack exchange,提问作者JSP

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 07:25:24