Chinaunix首页 | 论坛 | 博客
  • 博客访问: 95758
  • 博文数量: 29
  • 博客积分: 1160
  • 博客等级: 少尉
  • 技术积分: 321
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-29 15:48
文章分类

全部博文(29)

文章存档

2010年(29)

我的朋友

分类: C/C++

2010-05-17 16:39:23

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)); //指定记事本为父窗体
            }
        }
    }
}
阅读(1896) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~