c++如何调整窗口大小
时间: 2024-05-30 15:04:29 浏览: 15
以下是C++中调整窗口大小的方法:
1.使用SetWindowPos函数
```c++
HWND hWnd = GetForegroundWindow(); // 获取当前窗口句柄
int x = 0; // 窗口左上角x坐标
int y = 0; // 窗口左上角y坐标
int width = 800; // 窗口宽度
int height = 600; // 窗口高度
UINT flags = SWP_NOZORDER | SWP_NOACTIVATE; // 窗口调整标志
SetWindowPos(hWnd, NULL, x, y, width, height, flags); // 调整窗口大小
```
2.使用MoveWindow函数
```c++
HWND hWnd = GetForegroundWindow(); // 获取当前窗口句柄
int x = 0; // 窗口左上角x坐标
int y = 0; // 窗口左上角y坐标
int width = 800; // 窗口宽度
int height = 600; // 窗口高度
BOOL repaint = TRUE; // 是否重绘窗口
MoveWindow(hWnd, x, y, width, height, repaint); // 调整窗口大小
```
3.使用SetWindowPlacement函数
```c++
HWND hWnd = GetForegroundWindow(); // 获取当前窗口句柄
WINDOWPLACEMENT wp; // 窗口位置信息结构体
wp.length = sizeof(WINDOWPLACEMENT);
GetWindowPlacement(hWnd, &wp); // 获取窗口位置信息
wp.rcNormalPosition.left = 0; // 窗口左上角x坐标
wp.rcNormalPosition.top = 0; // 窗口左上角y坐标
wp.rcNormalPosition.right = 800; // 窗口右下角x坐标
wp.rcNormalPosition.bottom = 600; // 窗口右下角y坐标
SetWindowPlacement(hWnd, &wp); // 调整窗口大小
```