c++ - 可以从外部进程移动/调整窗口大小 [C++/Windows]

标签 c++ windows process

是否可以使用 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/

相关文章:

c++ - 坏流中的异常

时间:2019-03-09 标签:c++directxmulititextures

c++ - OS X 上 std::enable_shared_from_this<> 的编译错误

linux - 多操作系统环境中的 Git 行尾

Windows:具有重定向输入和输出的子进程

PHP 检查进程 ID

c++ - 在 C++ 中从平面 JSON 数组构建树

c++ - Windows和Linux之间的相对路径分辨率差异?

wpf - 错误模块名称 : PresentationFramework. ni.dll

c# - 从进程内存中读取 int