manipulating the simple windows Calculator using win32 API in c#?

前端 未结 2 2033
抹茶落季
抹茶落季 2020-12-18 15:02

Well, I\'ve tried my best to look at code examples and posts all over the web on how to do this, but I haven\'t been able to make any headway in a few months using windows A

2条回答
  •  既然无缘
    2020-12-18 15:47

    Since you say you're using C# you should be using the System.Windows.Automation namespace, whose entire purpose in life is to allow you to control other programs via automation.

    You didn't give details as to what you wanted, but here's a program that pushes "7" in the calculator.

    using System.Windows.Automation;
    
    class Program
    {
     public static void Main()
     {
      var calcWindow = AutomationElement.RootElement.FindFirst(
       TreeScope.Children,
       new PropertyCondition(AutomationElement.NameProperty, "Calculator"));
      if (calcWindow == null) return;
    
      var sevenButton = calcWindow.FindFirst(TreeScope.Descendants,
       new PropertyCondition(AutomationElement.NameProperty, "7"));
    
      var invokePattern = sevenButton.GetCurrentPattern(InvokePattern.Pattern)
                         as InvokePattern;
      invokePattern.Invoke();
     }
    }
    

提交回复
热议问题