日期:2014-05-20  浏览次数:20791 次

这个怎么出错了,返回句柄
using   System;
using   System.Collections.Generic;
using   System.ComponentModel;
using   System.Data;
using   System.Drawing;
using   System.Text;
using   System.Windows.Forms;
using   System.Runtime.InteropServices;

namespace   WindowsApplication1
{
        public   partial   class   Form1   :   Form
        {
                [DllImport( "User32.dll ")]
                public   static   extern   int   FindWindow(string   s);

                public   Form1()
                {
                        InitializeComponent();
                }  

                private   void   button1_Click(object   sender,   EventArgs   e)
                {
                        int   a;
                        a=FindWindow( "类名 ");
      textBox1.Text   =   a; //这样写说 无法将类型“int”隐式转换为“string”
                        textBox1.Text   =   Convert.ToString(a);//这样写能运行,但一点按钮就出一窗口说“无法处理的异常”,不明白
                }
        }
}

创建的是‘Windows应用程序’,功能很简单,就是用FindWindow查找一个窗体的类名,返回窗体的句柄。

------解决方案--------------------
textBox1.Text = a.ToString();


——————
btw , FindWindow 应该是两个参数的。