1. 通过代码查询特定的窗口,并在文本框中输入文字然后单击"OK"按钮

    • 需要查找的Dialog

    • 使用Spy++查看窗口信息

    • 通过代码实现功能
           class Program
      {
      //define method /// <summary>
      /// 查找顶级窗口,如果有指定的类名和窗口的名字则表示成功返回一个窗口的句柄。否则返回零。
      /// </summary>
      /// <param name="lpClassName">lpClassName参数指向类名</param>
      /// <param name="lpWindowName">lpWindowName指向窗口名</param>
      /// <returns></returns>
      [DllImport("User32.dll", EntryPoint = "FindWindow")]
      private static extern IntPtr FindWindow(string lpClassName, string lpWindowName); /// <summary>
      /// 在窗口列表中寻找与指定条件相符的第一个子窗口
      /// </summary>
      /// <param name="hwndParent">父窗口句柄</param>
      /// <param name="hwndChildAfter">子窗口句柄</param>
      /// <param name="lpszClass">窗口类名</param>
      /// <param name="lpszWindow">窗口名</param>
      /// <returns></returns>
      [DllImport("user32.dll", EntryPoint = "FindWindowEx")]
      private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow); /// <summary>
      /// 该函数将指定的消息发送到一个或多个窗口
      /// </summary>
      /// <param name="hWnd">接收消息的窗口句柄</param>
      /// <param name="Msg">指定被发送的消息类型</param>
      /// <param name="wParam"></param>
      /// <param name="lParam">发送的消息</param>
      /// <returns></returns>
      [DllImport("User32.dll", EntryPoint = "SendMessage")]
      private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, string lParam); //define message type
      private const int WM_GETTEXT = 0x000D;
      private const int WM_SETTEXT = 0x000C;
      private const int WM_CLICK = 0x00F5; public static void Main()
      {
      SearchWindow();
      } private static void SearchWindow()
      {
      //主窗口类型名及窗口名
      string lpszParentClassName = "";
      string lpszParentWindowName = "Print To File";
      //主窗口句柄
      IntPtr ParenthWnd = new IntPtr();
      //子窗口句柄
      IntPtr EdithWnd = new IntPtr(); //查到主窗体,得到整个窗体
      ParenthWnd = FindWindow(null, lpszParentWindowName);
      //判断这个窗体是否有效
      if (!ParenthWnd.Equals(IntPtr.Zero))
      {
      //得到FileName这个子窗体,并设置其内容
      EdithWnd = FindWindowEx(ParenthWnd, EdithWnd, "Edit", "");
      if (!EdithWnd.Equals(IntPtr.Zero))
      {
      //调用SendMessage方法设置其内容
      SendMessage(EdithWnd, WM_SETTEXT, (IntPtr), "你需要输入的文本");
      }
      //得到OK这个子窗体,并设置其内容
      EdithWnd = FindWindowEx(ParenthWnd, EdithWnd, "Button", "OK");
      if (!EdithWnd.Equals(IntPtr.Zero))
      {
      SendMessage(EdithWnd, WM_CLICK, (IntPtr), "");
      }
      }
      }
      }

user32的使用的更多相关文章

  1. C#中可直接调用WIN32的API函数--USER32.DLL

    Win32的API函数可以直接在C#中直接调用,在做WinForm时还是很有帮助的.有时候直接调用Win32的API,可以很高效的实现想要的效果. using System; using System ...

  2. Winform API "user32.dll"中的函数

    命名空间:System.Runtime.InteropServices /// <summary> /// 该函数检索一指定窗口的客户区域或整个屏幕的显示设备上下文环境的句柄,以后可以在G ...

  3. 整理分享C#通过user32.dll模拟物理按键操作的代码

    对系统模拟按键方面的知识和按键映射代码做了一下梳理,在这里分享出来,适用于开发自动操作工具和游戏外挂. 主代码: public const int KEYEVENTF_EXTENDEDKEY = 0x ...

  4. 【转】c# 调用windows API(user32.dll)

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.R ...

  5. Python 调用 user32.dll

    import ctypes h = ctypes.windll.LoadLibrary("C:\\Windows\\System32\\user32.dll") h.Message ...

  6. user32.dll

    user32.dll中的所有函数 using System; using System.Collections.Generic; using System.Linq; using System.Tex ...

  7. C# 之 user32函数库

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.R ...

  8. 【WinAPI】User32.dll注释

    #region User32.dll 函数 /// <summary> /// 该函数检索一指定窗口的客户区域或整个屏幕的显示设备上下文环境的句柄,以后可以在GDI函数中使用该句柄来在设备 ...

  9. 【整理】c# 调用windows API(user32.dll)

    User32.dll提供了很多可供调用的接口,大致如下(转自http://blog.csdn.net/zhang399401/article/details/6978803) using System ...

  10. Win32 API中的user32.dll中的ShowWindow方法参数整理

    在使用ShowWindow方法来设置窗体的状态时,由于不知道参数值,用起来非常容易混乱,所以整理了以下其参数的枚举值,方便以后的的使用.   public class User32API { #reg ...

随机推荐

  1. [tree]合并果子(哈夫曼树+优先队列)

    现在有n堆果子,第i堆有ai个果子.现在要把这些果子合并成一堆,每次合并的代价是两堆果子的总果子数.求合并所有果子的最小代价. Input 第一行包含一个整数T(T<=50),表示数据组数. 每 ...

  2. DRF知识

  3. Percona-Toolkit工具包之pt-archiver

      Preface       There's a common case that we neet to archive amount of records in some tables to a ...

  4. date 参数(option)-d

    记录这篇博客的原因是:鸟哥的linux教程中,关于date命令的部分缺少-d这个参数的介绍,并且12章中的shell编写部分有用到-d参数 date 参数(option)-d与--date=" ...

  5. 【vlan-给予mac地址认证】

    根据项目需求搭建好如下的路由和交换拓扑图: 1:用pc1  ping pc2 使交换机捕捉到4台pc及的 mac地址 查看交换机学习到的mac地址情况 2:配置交换机和pc机之间的接口,根pc机的ma ...

  6. Nginx反向代理 Laravel获取真实IP地址(PHP)

    使用VUE前后端分离开发 后端使用Laravel  想要获取到用户的真实IP地址 因为分离开发不同源跨域问题 所以只能进行前端Nginx反向代理 location /api { rewrite ^/a ...

  7. 13.6 模拟事件【JavaScript高级程序设计第三版】

    事件,就是网页中某个特别值得关注的瞬间.事件经常由用户操作或通过其他浏览器功能来触发. 但很少有人知道,也可以使用JavaScript 在任意时刻来触发特定的事件,而此时的事件就如同浏览器创建的事件一 ...

  8. scala成长之路(7)函数进阶——可能是史上最浅显易懂的闭包教程

    由于scala中函数内部能定义函数,且函数能作为函数的返回值,那么问题来了,当返回的函数使用了外层函数的局部变量时,会发生什么呢?没错,就产生是闭包. 关于闭包的解释网上一大堆,但基本上都是照葫芦画瓢 ...

  9. Preparing Cities for Robot Cars【城市准备迎接自动驾驶汽车】

    Preparing Cities for Robot Cars The possibility of self-driving robot cars has often seemed like a f ...

  10. 2019js面试题前端必问点小视频

    其实市面上的面试题有很多,但是大部分都是总结的blog居多,有时候说明一个事物也许口述几分钟就可以搞定,但是看帖子可能要分析半天 所以我就出一部分前端js必考的小视频,不管我们什么时候面试基本都绕不过 ...