首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

这个如何出错了,返回句柄

2012-01-13 
这个怎么出错了,返回句柄usingSystemusingSystem.Collections.GenericusingSystem.ComponentModelusing

这个怎么出错了,返回句柄
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 应该是两个参数的。



热点排行