问题
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".
In order to enter this window:
Open Settings => Update & security => Windows Defender => Add an exclution => Exclude a file extension
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.
I used Spy++ but when I put the target icon I received only "Shell_Dialog" class:
I have only the window handle:
I need the handle of the TextBox control.
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":
References:
SetText of textbox in external app. Win32 API
Inspect (Inspect.exe) is a Windows-based tool that enables you select any UI element
回答1:
Third alternative is to select parent (ie. dialog window) for your button (ie. it will be of Dialog class), and register for WM_COMMAND messages from it. Then after pressing it you button ID will be displayed as wID: XX in message window.
Source: Using visual studio's spy++ tool:
回答2:
In order to be able to do it I needed to use the Inspect.exe tool with administrator permissions.
Thanks @NineBerry,
After I opened the Inspect.exe as administrator I could see all the details.
来源:https://stackoverflow.com/questions/37912261/how-to-get-handle-to-a-textbox-control-inside-window-in-window-10