读书人

这个如何出错了返回句柄

发布时间: 2012-01-13 22:43:29 作者: rapoo

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



读书人网 >C#

热点推荐