新聞中心
C#調(diào)用記事本并填寫(xiě)內(nèi)容的功能實(shí)現(xiàn)是如何的呢?在我們編程開(kāi)發(fā)的過(guò)程中,實(shí)現(xiàn)C#調(diào)用記事本要用到什么方法呢?那么這里我們通過(guò)實(shí)例的形式向你介紹具體的過(guò)程:

成都創(chuàng)新互聯(lián)公司堅(jiān)信:善待客戶,將會(huì)成為終身客戶。我們能堅(jiān)持多年,是因?yàn)槲覀円恢笨芍档眯刨?。我們從不忽悠初訪客戶,我們用心做好本職工作,不忘初心,方得始終。十年網(wǎng)站建設(shè)經(jīng)驗(yàn)成都創(chuàng)新互聯(lián)公司是成都老牌網(wǎng)站營(yíng)銷服務(wù)商,為您提供成都網(wǎng)站建設(shè)、網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)、html5、網(wǎng)站制作、高端網(wǎng)站設(shè)計(jì)、小程序開(kāi)發(fā)服務(wù),給眾多知名企業(yè)提供過(guò)好品質(zhì)的建站服務(wù)。
C#調(diào)用記事本并填寫(xiě)內(nèi)容實(shí)例:
- 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 路過(guò)");
- }
C#調(diào)用記事本并填寫(xiě)內(nèi)容之發(fā)送回車(chē):
- [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 路過(guò)\r\n換行"); // 用"\r\n"換行
- SendMessage(vHandle, EM_SETSEL,
- int.MaxValue, int.MaxValue); // 光標(biāo)移到最后
- 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#調(diào)用記事本并填寫(xiě)內(nèi)容的基本內(nèi)容就向你介紹到這里,希望對(duì)你了解和學(xué)習(xí)C#調(diào)用記事本并填寫(xiě)內(nèi)容有所幫助。
本文題目:C#調(diào)用記事本實(shí)例淺析
文章轉(zhuǎn)載:http://www.5511xx.com/article/cosppse.html


咨詢
建站咨詢
