以前的一个问题(使窗体成为系统模态窗体)
我在以前的帖子上看到下面的回答,说这样就可以使窗体成为系统模态窗体了!
因为这个代码不是我写的,而大多数地方看的我是头昏昏的,想找位大大给我写点注释!
using System;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
namespace Class1
{
/// <summary>
/// WinAPI 的摘要说明。
/// </summary>
public class SetWindow
{
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
private static extern IntPtr GetForegroundWindow(); //WINAPI 获取当前活动窗体的句柄
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
private static extern bool SetForegroundWindow(IntPtr hWnd); //WINAPI 设置当前活动窗体的句柄
private Thread Th;
private IntPtr MainInt;
public SetWindow(IntPtr MainIntPrt)
{
MainInt=MainIntPrt;
}
/// <summary>
/// 开始线程
/// </summary>
public void Star()
{
Th=new Thread(new ThreadStart(SetForm));
Th.Start();
}
private void SetForm()
{
while(true)
{
if(MainInt!=GetForegroundWindow())SetForegroundWindow(MainInt);
Thread.Sleep(1);
}
}
/// <summary>
/// 关闭线程
/// </summary>
public void Close()
{
Th.Abort();
}
}
}
SetWin =new Class1.SetWindow(this.Handle);
SetWin.Star();
↑不知道这个是调用语句么? --------------------编程问答-------------------- 调用方法就如你所说那样,我看这个代码应该是在进行一个比较费时的操作时,用来加个模态窗体来提示个信息!
如果是这样,请看鄙人的一篇文章:http://blog.csdn.net/yulinlover/archive/2009/02/10/3875260.aspx
补充:.NET技术 , C#