国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
[c#] 通過 WIN32 API 實(shí)現(xiàn)嵌入程序窗體

 [c#] 通過 WIN32 API 實(shí)現(xiàn)嵌入程序窗體



寫了一個(gè)不使用 COM, 而是通過 WIN32 API 實(shí)現(xiàn)的示例, 它把寫字板程序嵌在了自己的一個(gè)面板中.



這么做可能沒有實(shí)際意義, 因?yàn)閮蓚€(gè)程序之前沒有進(jìn)行有價(jià)值的交互, 這里僅僅是為了演示這么做到, 以下是詳細(xì)注釋過的主要源代碼.

我把它封裝到一個(gè)類中:

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Diagnostics;  
  6. using System.Runtime.InteropServices;  
  7. using System.Windows.Forms;  
  8. namespace System.Windows.Forms  
  9. {  
  10.     class InsertWindow  
  11.     {  
  12.         /// <summary>  
  13.         /// 將程序嵌入窗體  
  14.         /// </summary>  
  15.         /// <param name="pW">容器</param>  
  16.         /// <param name="appname">程序名</param>  
  17.         public InsertWindow(Panel pW,string appname)  
  18.         {  
  19.             this.pan = pW;  
  20.             this.LoadEvent(appname);  
  21.             pane();  
  22.         }  
  23.   
  24.         ~InsertWindow()  
  25.         {  
  26.             if (m_innerProcess!=null)  
  27.             {  
  28.                 m_innerProcess.Dispose();  
  29.             }  
  30.         }  
  31.  
  32.         #region  函數(shù)和變量聲明  
  33.         /* 
  34.         * 聲明 Win32 API 
  35.         */  
  36.   
  37.         [DllImport("user32.dll")]  
  38.         static extern IntPtr SetParent(IntPtr hWndChild,  
  39.             IntPtr hWndNewParent  
  40.         );  
  41.   
  42.         [DllImport("user32.dll")]  
  43.         static extern Int32 GetWindowLong(IntPtr hWnd,  
  44.             Int32 nIndex  
  45.         );  
  46.   
  47.         [DllImport("user32.dll")]  
  48.         static extern Int32 SetWindowLong(IntPtr hWnd,  
  49.             Int32 nIndex,  
  50.             Int32 dwNewLong  
  51.         );  
  52.   
  53.         [DllImport("user32.dll")]  
  54.         static extern Int32 SetWindowPos(IntPtr hWnd,  
  55.             IntPtr hWndInsertAfter,  
  56.             Int32 X,  
  57.             Int32 Y,  
  58.             Int32 cx,  
  59.             Int32 cy,  
  60.             UInt32 uFlags  
  61.         );  
  62.   
  63.         /* 
  64.          * 定義 Win32 常數(shù) 
  65.          */  
  66.         const Int32 GWL_STYLE = -16;  
  67.         const Int32 WS_BORDER = (Int32)0x00800000L;  
  68.         const Int32 WS_THICKFRAME = (Int32)0x00040000L;  
  69.   
  70.         const Int32 SWP_NOMOVE = 0x0002;  
  71.         const Int32 SWP_NOSIZE = 0x0001;  
  72.         const Int32 SWP_NOZORDER = 0x0004;  
  73.         const Int32 SWP_FRAMECHANGED = 0x0020;  
  74.   
  75.         const Int32 SW_MAXIMIZE = 3;  
  76.         IntPtr HWND_NOTOPMOST = new IntPtr(-2);  
  77.   
  78.         // 目標(biāo)應(yīng)用程序的進(jìn)程.  
  79.         Process m_innerProcess = null;  
  80.         #endregion  
  81.  
  82.         #region  容器  
  83.         private Panel pan = null;  
  84.         public Panel panel1  
  85.         {  
  86.             set { pan = value; }  
  87.             get { return pan; }  
  88.         }  
  89.         private void pane()  
  90.         {  
  91.             panel1.Anchor = AnchorStyles.Left | AnchorStyles.Top |  
  92.              AnchorStyles.Right | AnchorStyles.Bottom;  
  93.             panel1.Resize += new EventHandler(panel1_Resize);  
  94.         }  
  95.         private void panel1_Resize(object sender, EventArgs e)  
  96.         {  
  97.             // 設(shè)置目標(biāo)應(yīng)用程序的窗體樣式.  
  98.   
  99.             IntPtr innerWnd = m_innerProcess.MainWindowHandle;  
  100.             SetWindowPos(innerWnd, IntPtr.Zero, 0, 0,  
  101.                 panel1.ClientSize.Width, panel1.ClientSize.Height,  
  102.                 SWP_NOZORDER);  
  103.         }  
  104.         #endregion  
  105.  
  106.         #region  相應(yīng)事件  
  107.         private void LoadEvent(string appFile)  
  108.         {  
  109.   
  110.             // 啟動(dòng)目標(biāo)應(yīng)用程序.  
  111.             m_innerProcess = Process.Start(appFile);  
  112.             m_innerProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; //隱藏  
  113.             // 等待, 直到那個(gè)程序已經(jīng)完全啟動(dòng).   
  114.             m_innerProcess.WaitForInputIdle();  
  115.   
  116.             // 目標(biāo)應(yīng)用程序的主窗體.  
  117.             IntPtr innerWnd = m_innerProcess.MainWindowHandle;  
  118.   
  119.             // 設(shè)置目標(biāo)應(yīng)用程序的主窗體的父親(為我們的窗體).  
  120.             SetParent(innerWnd, panel1.Handle);  
  121.   
  122.             // 除去窗體邊框.  
  123.             Int32 wndStyle = GetWindowLong(innerWnd, GWL_STYLE);  
  124.             wndStyle &= ~WS_BORDER;  
  125.             wndStyle &= ~WS_THICKFRAME;  
  126.             SetWindowLong(innerWnd, GWL_STYLE, wndStyle);  
  127.             SetWindowPos(innerWnd, IntPtr.Zero, 0, 0, 0, 0,  
  128.                 SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);  
  129.   
  130.             // 在Resize事件中更新目標(biāo)應(yīng)用程序的窗體尺寸.  
  131.             panel1_Resize(panel1, null);  
  132.         }  
  133. #endregion  
  134.     }  
  135.   
  136.   
  137. }  



然后在 窗口的 load事件中 加入

詳細(xì)代碼 如下:

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Linq;  
  7. using System.Text;  
  8. using System.Windows.Forms;  
  9. using System.Runtime;  
  10. using System.Runtime.InteropServices;  
  11. using System.Diagnostics;  
  12.   
  13. namespace 將程序窗口嵌入到任務(wù)欄中  
  14. {  
  15.     public partial class Form1 : Form  
  16.     {  
  17.         private System.Windows.Forms.Panel panel1;  
  18.         public Form1()  
  19.         {  
  20.             InitializeComponent();  
  21.             this.panel1 = new System.Windows.Forms.Panel();  
  22.             this.SuspendLayout();  
  23.             //   
  24.             // panel1  
  25.             //   
  26.             this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;  
  27.             this.panel1.Location = new System.Drawing.Point(0, 0);  
  28.             this.panel1.Name = "panel1";  
  29.             this.panel1.Size = new System.Drawing.Size(292, 273);  
  30.             this.panel1.TabIndex = 0;  
  31.             this.Controls.Add(this.panel1);  
  32.   
  33.             Load += new EventHandler(Form1_Load);  
  34.         }  
  35.   
  36.         private void Form1_Load(object sender, EventArgs e)  
  37.         {  
  38.             //string sPath = Environment.GetEnvironmentVariable("windir");//獲取系統(tǒng)變量 windir(windows)    
  39.             const string appFile =  
  40.                 "C:\\Program Files\\Windows NT\\Accessories\\wordpad.exe";  
  41.             InsertWindow insertwin = new InsertWindow(panel1, appFile);  
  42.   
  43.         }  
  44.   
  45.           
  46.     }  
  47. }  
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
c# 移動(dòng)拖動(dòng)無邊框窗體
用C#做一個(gè)懸浮窗口[含三種移動(dòng)無標(biāo)題窗體的辦法]
WPF中AllowsTransparency和WebBrowser兼容性問題
C#將exe運(yùn)行程序嵌入到自己的winform窗體中
設(shè)定unity3d執(zhí)行程序運(yùn)行后的屏幕大小和屏幕坐標(biāo) | unity3d中文網(wǎng)站,unity3d中文論壇,unity3d學(xué)習(xí)社區(qū),unity3d教程,unity3d專業(yè)論壇,unity3d教學(xué),uni
C# 調(diào)用 Google Earth Com API開發(fā)(二)
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服