如何在 Window 10 中的窗口内获取 TextBox 控件的句柄 [英] How to get handle to a TextBox control inside window in Window 10

查看:18
本文介绍了如何在 Window 10 中的窗口内获取 TextBox 控件的句柄的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 C# 自动化到 Windows 10.
其中一项任务是将数据写入名为添加排除"的窗口中的文本框.

I am working on automation to Windows 10 with C#.
One of the tasks is to write data to a TextBox in window called "Add exclusion".

为了进入这个窗口:
打开设置 => 更新 &安全性 => Windows Defender => 添加排除 => 排除文件扩展名

In order to enter this window:
Open Settings => Update & security => Windows Defender => Add an exclution => Exclude a file extension

我知道我需要使用 SendMessage(...)SetWindowText(...) 函数将数据写入控件.
但是我需要向这些函数传递我想要写入的控件的句柄.
所以我需要使用 GetDlgItem(hDlg, nIDDlgItem).
参数 nIDDlgItem 是控件 ID,但我无法在添加排除"窗口中找到 TextBox 控件的控件 ID.

I understood that I need to use SendMessage(...) or SetWindowText(...) functions for writing data to a control.
But I need to pass these functions a handle of the control I want to write to.
So I need to use GetDlgItem(hDlg, nIDDlgItem).
The parameter nIDDlgItem is the control ID but I am not able to find the control ID of the TextBox control in the "Add exclusion" window.

我使用了 Spy++,但是当我放置目标图标时,我只收到了Shell_Dialog"类:

I used Spy++ but when I put the target icon I received only "Shell_Dialog" class:

我只有窗口句柄:

I have only the window handle:

我需要 TextBox 控件的句柄.

I need the handle of the TextBox control.

编辑 (20.6.2016):
我尝试使用 Windows 10 Kit 中的 Inspect.exe 工具,但是当我将光标放在 TextBox 控件上时,它会写我访问被拒绝":

EDIT (20.6.2016):
I tried to use the Inspect.exe tool from Windows 10 Kit but when I am placing the curoser on the TextBox control it writes me "Access is denied":

参考文献:
外部应用中文本框的SetText.Win32 API
Inspect (Inspect.exe) 是一个基于 Windows 的工具,可让您选择任何 UI 元素

推荐答案

为了能够做到这一点,我需要使用具有管理员权限的 Inspect.exe 工具.

In order to be able to do it I needed to use the Inspect.exe tool with administrator permissions.

谢谢@NineBerry,
在我以管理员身份打开 Inspect.exe 后,我可以看到所有详细信息.

Thanks @NineBerry,
After I opened the Inspect.exe as administrator I could see all the details.

这篇关于如何在 Window 10 中的窗口内获取 TextBox 控件的句柄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆