111,115
社区成员




平台vs2008 开发语言c# 运行时需要.net framework 3.5支持
好啦,源码在下面啦:
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;
using System.Runtime.InteropServices;
namespace 灰色按钮终结者
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
public delegate bool CallBack(int hwnd, int lParam); //定义托管回调函数;
[DllImport("user32.dll", EntryPoint = "EnumWindows")]
public static extern int EnumWindows( //枚举顶层窗体;
CallBack lpEnumFunc,
int lParam
);
[DllImport("user32.dll", EntryPoint = "EnumChildWindows")]
public static extern int EnumChildWindows( //枚举子窗体;
int hWndParent,
CallBack lpEnumFunc,
int lParam
);
[DllImport("user32.dll", EntryPoint = "IsWindowEnabled")]
public static extern int IsWindowEnabled( //判断子窗体;
int hwnd
);
[DllImport("user32.dll", EntryPoint = "EnableWindow")]
public static extern int EnableWindow ( //使能子窗体;
int hwnd,
int fEnable
);
list<int> hwndlst=new list<int>(); //定义泛型集合用于存储顶层窗体的句柄;
public static bool EnumWindowsHandle(int hwnd, int lParam) //回调函数hwnd是enumwindows函数传过来的句柄;
{
hwndlst.Add(hwnd);
return true;
}
public void EnumChiledWindowsHandle() //定义啦一个方法,调用进行啦;
{
CallBack mycallback = new CallBack(MainForm.EnabledWindow); //定义回调函数,MainForm即为此窗体的名字;
for (int i = 0; i < hwndlst.Count; i++)
{
EnumChildWindows(hwndlst, mycallback, 0);
}
}
public static bool EnabledWindow(int hwnd, int lp) //这里又是一个回调函数,是给enumchildwindows定义的;hwnd即是子窗体的句柄;
{
try
{
if (IsWindowEnabled(hwnd) == 0) //如果窗体不能用,即enabled=false;
{
EnableWindow(hwnd, 1); //用api函数使能窗体;
return true;
}
}
catch { }
return true;
}
}
}