开发者

Set Textbox Value on other applications dialog PInvoke

开发者 https://www.devze.com 2023-03-31 18:12 出处:网络
Is it possible to use PInvoke (or some other method) to change the value of a textbox on a dialog owned by another process?

Is it possible to use PInvoke (or some other method) to change the value of a textbox on a dialog owned by another process?

Developing in .NET. I assumed that the availability of calls like SetWindowText would indicate that the same can be done for textboxes. 开发者_如何学GoI'd rather not use SendKeys.


Of course it's possible to do so. You can check source code of my LinqToWindows library: https://github.com/Eskat0n/linqtowindows

This library uses PInvoke for obtaining handler of window specified via LINQ where clause, gets instances of child windows and change it's Text property like following (changing text of all Edit elements in open file dialog window):

var shell = new Shell();

var openDialog = shell.Windows
    .Where(x => x.Text.Contains("Open"))
    .SingleOrDefault()
    .Cast<OpenFileDialog>();

var edits = openDialog.OfType<Edit>();
foreach (var edit in edits)
    edit.Text = "Hello Word!";

Code is untested but should work. Please take a look at test project included into LinqToWindows solution for further examples.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号