文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>跨进程设置模式窗口的父窗体:(关于IWin32Window)..

跨进程设置模式窗口的父窗体:(关于IWin32Window)..

时间:2010-05-17  来源:wesudo

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

namespace WindowsFormsApplication4
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        public class WindowWrapper : System.Windows.Forms.IWin32Window
        {
            public WindowWrapper(IntPtr handle)
            {
                _hwnd = handle;
            }
            public IntPtr Handle
            {
                get { return _hwnd; }
            }
            private IntPtr _hwnd;
        }
        private void button1_Click(object sender, EventArgs e)
        {
            Form3 form3 = new Form3();
            form3.ShowDialog(); // 等价于 form3.ShowDialog(this);
        }
        private void button2_Click(object sender, EventArgs e)
        {
            Form2 form2 = new Form2();
            form2.Show();
            Form3 form3 = new Form3();
            form3.ShowDialog(form2); //指定父窗体
        }
        private void button3_Click(object sender, EventArgs e)
        {
            //需要引入System.Diagnostics命名空间
            Process[] procs = Process.GetProcessesByName("Notepad");
            if (procs.Length != 0)
            {
                IntPtr hwnd = procs[0].MainWindowHandle;
                Form3 form3 = new Form3();
                //WindowWrapper类见下面
                form3.ShowDialog(new WindowWrapper(hwnd)); //指定记事本为父窗体
            }
        }
    }
}
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载