这里是一个简单的示例程序,可以获取 Windows 11 文件资源管理器中当前活动选项卡的路径:

#include <iostream>
#include <Windows.h>

int main()
{
    HWND hwnd = FindWindowEx(nullptr, nullptr, L"CabinetWClass", nullptr);
    if (hwnd == nullptr)
    {
        std::cout << "File Explorer is not running." << std::endl;
        return 1;
    }
    
    hwnd = FindWindowEx(hwnd, nullptr, L"WorkerW", nullptr);
    if (hwnd == nullptr)
    {
        std::cout << "Could not find WorkerW window." << std::endl;
        return 2;
    }
    
    hwnd = FindWindowEx(hwnd, nullptr, L"ReBarWindow32", nullptr);
    if (hwnd == nullptr)
    {
        std::cout << "Could not find ReBarWindow32 window." << std::endl;
        return 3;
    }
    
    hwnd = FindWindowEx(hwnd, nullptr, L"Address Band Root", nullptr);
    if (hwnd == nullptr)
    {
        std::cout << "Could not find Address Band Root window." << std::endl;
        return 4;
    }
    
    wchar_t path[MAX_PATH] = { 0 };
    SendMessage(hwnd, WM_GETTEXT, MAX_PATH, reinterpret_cast<LPARAM>(path));
    
    std::wcout << "Current path: " << path << std::endl;
    
    return 0;
}

该程序首先查找文件资源管理器的主窗口,然后逐级查找子窗口,直到找到“Address Band Root”窗口。最后,程序调用 SendMessage 函数,向该窗口发送 WM_GETTEXT 消息,以获取当前选项卡的路径

C++编写针对 Windows 11 的程序来获取文件资源管理器中当前活动选项卡的路径FindWindowExhandle IntPtrZero Address Band Root null;

原文地址: https://www.cveoy.top/t/topic/hloH 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录