C#调用记事本并填写内容的功能实现是如何的呢?在我们编程开发的过程中,实现C#调用记事本要用到什么方法呢?那么这里我们通过实例的形式向你介绍具体的过程:
成都创新互联公司坚信:善待客户,将会成为终身客户。我们能坚持多年,是因为我们一直可值得信赖。我们从不忽悠初访客户,我们用心做好本职工作,不忘初心,方得始终。十年网站建设经验成都创新互联公司是成都老牌网站营销服务商,为您提供成都网站建设、网站建设、网站设计、html5、网站制作、高端网站设计、小程序开发服务,给众多知名企业提供过好品质的建站服务。
C#调用记事本并填写内容实例:
- using System.Runtime.InteropServices;
- using System.Diagnostics;
- [DllImport("User32.DLL")]
- public static extern int SendMessage(IntPtr hWnd,
- uint Msg, int wParam, string lParam);
- [DllImport("User32.DLL")]
- public static extern IntPtr FindWindowEx(IntPtr hwndParent,
- IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
- public const uint WM_SETTEXT = 0x000C;
- private void button1_Click(object sender, EventArgs e)
- {
- Process vProcess = Process.Start("notepad.exe");
- while (vProcess.MainWindowHandle ==
- IntPtr.Zero) vProcess.Refresh();
- IntPtr vHandle = FindWindowEx(vProcess.MainWindowHandle,
- IntPtr.Zero, "Edit", null);
- SendMessage(vHandle, WM_SETTEXT, 0, "Zswang 路过");
- }
C#调用记事本并填写内容之发送回车:
- [DllImport("User32.DLL")]
- public static extern int SendMessage(IntPtr hWnd,
- uint Msg, int wParam, string lParam);
- [DllImport("User32.DLL")]
- public static extern int SendMessage(IntPtr hWnd,
- uint Msg, int wParam, int lParam);
- [DllImport("User32.DLL")]
- public static extern IntPtr FindWindowEx(IntPtr hwndParent,
- IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
- public const uint WM_SETTEXT = 0x000C;
- public const uint WM_CHAR = 0x0102;
- public const uint EM_SETSEL = 0x00B1;
- private void button1_Click(object sender, EventArgs e)
- {
- Process vProcess = Process.Start("notepad.exe");
- while (vProcess.MainWindowHandle ==
- IntPtr.Zero) vProcess.Refresh();
- IntPtr vHandle = FindWindowEx(vProcess.MainWindowHandle,
- IntPtr.Zero, "Edit", null);
- SendMessage(vHandle, WM_SETTEXT,
- 0, "Zswang 路过\r\n换行"); // 用"\r\n"换行
- SendMessage(vHandle, EM_SETSEL,
- int.MaxValue, int.MaxValue); // 光标移到最后
- SendMessage(vHandle, WM_CHAR, (int)Keys.Enter, 0);
- SendMessage(vHandle, WM_CHAR, (int)'h', 0);
- SendMessage(vHandle, WM_CHAR, (int)'e', 0);
- SendMessage(vHandle, WM_CHAR, (int)'l', 0);
- SendMessage(vHandle, WM_CHAR, (int)'l', 0);
- SendMessage(vHandle, WM_CHAR, (int)'o', 0);
- }
C#调用记事本并填写内容的基本内容就向你介绍到这里,希望对你了解和学习C#调用记事本并填写内容有所帮助。
当前标题:C#调用记事本实例浅析
浏览地址:http://www.stwzsj.com/qtweb/news40/15890.html
网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联