【发布时间】:2022-01-23 14:23:36
【问题描述】:
我想更改 calc.exe 的标题栏。我读到它是通过 SetWindowTextA() 完成的,但是当我使用它时,它只会更改预览 (1) 的标题,我也想更改 (2) 的标题。
谁能为我解释为什么它在 (1) 处更改标题而不是 (2) 以及如何更改 (2) 处的标题
【问题讨论】:
-
图片不错,但也请将您的代码发布为文本,格式化为代码。
我想更改 calc.exe 的标题栏。我读到它是通过 SetWindowTextA() 完成的,但是当我使用它时,它只会更改预览 (1) 的标题,我也想更改 (2) 的标题。
谁能为我解释为什么它在 (1) 处更改标题而不是 (2) 以及如何更改 (2) 处的标题
【问题讨论】:
计算器标题是使用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;
}
【讨论】:
left-control。还有一些UI Automation Samples可以参考。不要忘记设置项目Per Monitor High DPI Aware。