【问题标题】:更改 uwp 进程的标题
【发布时间】:2022-01-23 14:23:36
【问题描述】:

我想更改 calc.exe 的标题栏。我读到它是通过 SetWindowTextA() 完成的,但是当我使用它时,它只会更改预览 (1) 的标题,我也想更改 (2) 的标题。

谁能为我解释为什么它在 (1) 处更改标题而不是 (2) 以及如何更改 (2) 处的标题

【问题讨论】:

  • 图片不错,但也请将您的代码发布为文本,格式化为代码。

标签: c++ winapi uwp window


【解决方案1】:

计算器标题是使用UI Automation检索的文本控件类型。然而,根据 Text Control Type 的说法,IValueProvider从不受文本控件支持的。所以你不能。

编辑:

#include <Windows.h>
#include <UIAutomation.h>
#include <wchar.h>

int Element(IUIAutomation* automation)
{
    // Get the element under the cursor
// Use GetPhysicalCursorPos to interact properly with
// High DPI
    POINT pt;
    GetPhysicalCursorPos(&pt);

    IUIAutomationElement* pAtMouse;
    HRESULT hr = automation->ElementFromPoint(pt, &pAtMouse);
    if (FAILED(hr))
        return hr;

    // Get the element's name and print it
    BSTR name;
    hr = pAtMouse->get_CurrentName(&name);
    if (SUCCEEDED(hr))
    {
        IUIAutomationTextPattern* pattern;
        pAtMouse->GetCurrentPatternAs(UIA_TextPatternId, IID_IUIAutomationTextPattern,(void**)&pattern);
        //TODO
        wprintf(L"Element's Name: %s \n", name);
        SysFreeString(name);
    }

    // Get the element's Control Type (in the current languange)
    // and print it
    BSTR controlType;
    hr = pAtMouse->get_CurrentLocalizedControlType(&controlType);
    if (SUCCEEDED(hr))
    {
        wprintf(L"Element's Control Type: %s \n", controlType);
        SysFreeString(controlType);
    }

    // Clean up our COM pointers
    pAtMouse->Release();
    return hr;
}

int main(int argc, TCHAR* argv[])
{
    // Initialize COM and create the main Automation object
    IUIAutomation* g_pAutomation;
    CoInitialize(NULL);
    HRESULT hr = CoCreateInstance(__uuidof(CUIAutomation), NULL,
        CLSCTX_INPROC_SERVER, __uuidof(IUIAutomation),
        (void**)&g_pAutomation);
    if (FAILED(hr))
        return (hr);

    bool quit = false;
    while (!quit)
    {
        SHORT leftControlMod = GetAsyncKeyState(VK_LCONTROL);
        if (leftControlMod != 0)
        {
            Element(g_pAutomation);
        }
        quit = GetAsyncKeyState(VK_ESCAPE);
    }

    g_pAutomation->Release();
    CoUninitialize();
    return 0;
}

【讨论】:

  • 你能告诉我获取此信息的代码吗?我是新手,我想学习如何获取此信息
  • 已添加。将鼠标移动到 Calculator 标题并按下 left-control。还有一些UI Automation Samples可以参考。不要忘记设置项目Per Monitor High DPI Aware
  • 非常感谢你拯救了我的一天
猜你喜欢
  • 2021-02-11
  • 2021-11-18
  • 2019-04-26
  • 2018-12-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-11-23
相关资源
最近更新 更多