是否可以使用 Windows API 从外部进程移动或调整窗口大小?
例如,您将如何编写一个列出所有当前打开的窗口的程序,让用户选择其中两个,然后让程序将它们并排放置在屏幕上?
最佳答案
感谢 Richard Critten 指出了正确的方向。
为了获得所有窗口的列表,可以使用 EnumWindows 和 SetWindowPos 来修改每个窗口的位置和分辨率。
此示例将每个可见窗口向右移动 50 像素:
#include <Windows.h>
#include <stdio.h>
BOOL CALLBACK EnumWindowsProc(HWND hWnd, long lParam) {
if(IsWindowVisible(hWnd)) {
RECT rect;
GetWindowRect(hWnd, &rect);
SetWindowPos(hWnd, HWND_TOPMOST, rect.left + 50, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_SHOWWINDOW);
}
return TRUE;
}
int main() {
EnumWindows(EnumWindowsProc, 0);
return 0;
}
关于c++ - 可以从外部进程移动/调整窗口大小 [C++/Windows],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48753962/