新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
C#打開記事本實(shí)現(xiàn)實(shí)例解析
C#打開記事本的功能實(shí)現(xiàn)是如何的呢?我們在項(xiàng)目中也許會(huì)碰到這個(gè)小插曲,那么具體的實(shí)現(xiàn)方法是什么呢?,還有要實(shí)現(xiàn)給記事本添加內(nèi)容,那么下面我們通過實(shí)例向你介紹具體的實(shí)現(xiàn)過程。

創(chuàng)新互聯(lián)建站主營大姚網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,成都app開發(fā),大姚h5重慶小程序開發(fā)搭建,大姚網(wǎng)站營銷推廣歡迎大姚等地區(qū)企業(yè)咨詢
C#打開記事本實(shí)現(xiàn)實(shí)例:
- /// ﹤summary﹥
- /// C#打開記事本之傳遞消息給記事本
- /// ﹤/summary﹥
- /// ﹤param name="hWnd"﹥﹤/param﹥
- /// ﹤param name="Msg"﹥﹤/param﹥
- /// ﹤param name="wParam"﹥﹤/param﹥
- /// ﹤param name="lParam"﹥﹤/param﹥
- /// ﹤returns﹥﹤/returns﹥
- [DllImport("User32.DLL")]
- public static extern int SendMessage(
- IntPtr hWnd, uint Msg, int wParam, string lParam);
- /// ﹤summary﹥
- /// C#打開記事本之查找句柄
- /// ﹤/summary﹥
- /// ﹤param name="hwndParent"﹥﹤/param﹥
- /// ﹤param name="hwndChildAfter"﹥﹤/param﹥
- /// ﹤param name="lpszClass"﹥﹤/param﹥
- /// ﹤param name="lpszWindow"﹥﹤/param﹥
- /// ﹤returns﹥﹤/returns﹥
- [DllImport("User32.DLL")]
- public static extern IntPtr FindWindowEx(
- IntPtr hwndParent, IntPtr hwndChildAfter,
- string lpszClass, string lpszWindow);
- /// ﹤summary﹥
- /// C#打開記事本之記事本需要的常量
- /// ﹤/summary﹥
- public const uint WM_SETTEXT = 0x000C;
- #endregion
- private void button1_Click(object sender, EventArgs e)
- {
- #region [ 啟動(dòng)記事本 ]
- System.Diagnostics.Process Proc;
- try
- {
- // 啟動(dòng)記事本
- Proc = new System.Diagnostics.Process();
- Proc.StartInfo.FileName = "notepad.exe";
- Proc.StartInfo.UseShellExecute = false;
- Proc.StartInfo.RedirectStandardInput = true;
- Proc.StartInfo.RedirectStandardOutput = true;
- Proc.Start();
- }
- catch
- {
- Proc = null;
- }
- #endregion
- #region [ 傳遞數(shù)據(jù)給記事本 ]
- if (Proc != null)
- {
- // C#打開記事本之調(diào)用 API, 傳遞數(shù)據(jù)
- while (Proc.MainWindowHandle == IntPtr.Zero)
- {
- Proc.Refresh();
- }
- IntPtr vHandle = FindWindowEx(
- Proc.MainWindowHandle, IntPtr.Zero, "Edit", null);
- // C#打開記事本之傳遞數(shù)據(jù)給記事本
- SendMessage(vHandle, WM_SETTEXT, 0, "Message");
- }
- #endregion
- }
C#打開記事本的具體實(shí)現(xiàn)內(nèi)容就向你介紹到這里,希望對你了解和學(xué)習(xí)C#打開記事本的開發(fā)實(shí)現(xiàn)有所幫助。
分享文章:C#打開記事本實(shí)現(xiàn)實(shí)例解析
標(biāo)題路徑:http://www.dlmjj.cn/article/cdgcioc.html


咨詢
建站咨詢
