100分求一api函数在C#中的有效使用方法~! [DllImport("user32.dll", EntryPoint="EnableWindow")]public static extern int EnableWindow (int hwnd,int fEnable); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 楼主可以搜索一下ApiViewer,是个不错的工具! API精灵,lz可以留下mail,我发给你。 这样来用:[DllImport("user32.dll", CharSet = CharSet.Auto)]public static extern IntPtr FindWindowEx(IntPtr handParent, IntPtr hwndChildAfter, string className, string windowName);[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]public static extern bool EnableWindow(IntPtr hWnd, bool enable);private void button1_Click(object sender, EventArgs e){ IntPtr wnd = FindWindowEx(this.Handle, IntPtr.Zero, null, "button3"); EnableWindow(wnd, false);} 因为可能取不到Button3的句柄,所以最好判断一下,把如下的代码放到窗体中运行就可以了:[DllImport("user32.dll", CharSet = CharSet.Auto)]public static extern IntPtr FindWindowEx(IntPtr handParent, IntPtr hwndChildAfter, string className, string windowName);[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]public static extern bool EnableWindow(IntPtr hWnd, bool enable);private void button1_Click(object sender, EventArgs e){ IntPtr wnd = FindWindowEx(this.Handle, IntPtr.Zero, null, "button3"); if (wnd != IntPtr.Zero) { EnableWindow(wnd, false); }} 谢谢两位答复我,api精灵我有里面提供的只有[DllImport("user32.dll", EntryPoint="EnableWindow")]public static extern int EnableWindow (int hwnd,int fEnable);这,但没有一个有效的使用方法 实际上你的使用错了,EnableWindow((int)xt,1);应是EnableWindow((int)xt,0);再有就是xt应定义为IntPtr类型. 不行的,我用过了,依然没用,反回值是false.句柄可以不用担心我肯定没错 我一开始就是定义的IntPtr型的不行我才换了一下 用反了,不会吧,说明上说的是>0的值=0不就是false了吗 EnableWindow返回值为False不是说没有执行成功.这个值是这样的,如果原来Enable为False,则返回值是非0值,如果原来Enable是True,则返回值是0,如果要获取出错代码,要使用GetLastError. 设置0值是把按钮设置为了无效状态,设置非值是把铵钮设置为了有效状态你可以用如下的代码测试一下:public static extern bool EnableWindow(IntPtr hWnd, int enable);//用一个整数private void button1_Click(object sender, EventArgs e){ IntPtr wnd = FindWindowEx(this.Handle, IntPtr.Zero, null, "button3"); if (wnd != IntPtr.Zero) { bool b = EnableWindow(wnd, 1); System.Console.WriteLine(b); }}private void button2_Click(object sender, EventArgs e){ IntPtr wnd = FindWindowEx(this.Handle, IntPtr.Zero, null, "button3"); if (wnd != IntPtr.Zero) { bool b = EnableWindow(wnd, 0); System.Console.WriteLine(b); }} 试过了button1是truebutton2是false 但无论怎么使都无法改变button3的Enable状态 学习中... 欢迎加入ASP.NET(C#)学习交流QQ群号:①32801051(已满) ②23222074(请不要两个群都加) http://blogs.msdn.com/jfoscoding/articles/480808.aspx 看了你的代码,我觉得,是 1。你应该确定找到Form 的 handle 了吗?IntPtr xt=(IntPtr)FindWindowEx((int)FindWindow(null,"form1"),0,null,"button3");这种写法,我第一次见。一般来说,FindWindow(null,"form1")这个函数,需要自己写个循环调用它,因为有时候并不能第一次就找到Form1这个form。所以需要循环一定的次数来查找。2。如果能用 intptr就不要用int,这样更纯粹。3。对于FindWindow和FindWindowEx的 class 类型那个参数,能给就给。4。看看是否存在重名的form和button。5。有些API确实不能起作用了在有些windows系统中。 支持hbxtlhx(平民百姓) ( ) 信誉:112 如果是 .net 的不可以因为 那是 class: "WindowsForms10.BUTTON.app.0.3b95145"不是 win32 下的 button EnableWindow对win32 下的 button 可以建议你用AccExplorer32.exe 看看 用Spy++ 这个工具是VS自带的。要察看什么都可以阿 AccExplorer32.exe 和 Spy++ 各有所长例如AccExplorer32.exe 对html页面支持好还有 msn 的 有个版本 可以 用AccExplorer32.exe 直接读密码 //msn的 一个漏洞Spy++ 的消息监控好 关于winform登录窗口记住密码的问题 C#Form设计的问题(最大化) GridView隐藏列怎么做。 C#中使用jmail组件 接收html邮件 奇怪,这有什么不同吗? C#链表中LinkedList中Link字段 100分:谁详细讲一下静态方法在何处使用?静态方法在何处使用?有什么好处? MS Agent困扰很久 关于工厂设计模式的疑惑 请问C#r有一点小问题,请高手指点 滚动条上的拖动条的长度怎样改变 ListView
public static extern IntPtr FindWindowEx(IntPtr handParent, IntPtr hwndChildAfter, string className, string windowName);[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern bool EnableWindow(IntPtr hWnd, bool enable);
private void button1_Click(object sender, EventArgs e)
{
IntPtr wnd = FindWindowEx(this.Handle, IntPtr.Zero, null, "button3");
EnableWindow(wnd, false);
}
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr FindWindowEx(IntPtr handParent, IntPtr hwndChildAfter, string className, string windowName);
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern bool EnableWindow(IntPtr hWnd, bool enable);
private void button1_Click(object sender, EventArgs e)
{
IntPtr wnd = FindWindowEx(this.Handle, IntPtr.Zero, null, "button3");
if (wnd != IntPtr.Zero)
{
EnableWindow(wnd, false);
}
}
[DllImport("user32.dll", EntryPoint="EnableWindow")]
public static extern int EnableWindow (int hwnd,int fEnable);
这,但没有一个有效的使用方法
EnableWindow((int)xt,1);应是
EnableWindow((int)xt,0);再有就是xt应定义为IntPtr类型.
句柄可以不用担心我肯定没错
用反了,不会吧,说明上说的是>0的值=0不就是false了吗
这个值是这样的,如果原来Enable为False,则返回值是非0值,
如果原来
Enable是True,则返回值是0,
如果要获取出错代码,要使用GetLastError.
设置非值是把铵钮设置为了有效状态你可以用如下的代码测试一下:public static extern bool EnableWindow(IntPtr hWnd, int enable);//用一个整数
private void button1_Click(object sender, EventArgs e)
{
IntPtr wnd = FindWindowEx(this.Handle, IntPtr.Zero, null, "button3");
if (wnd != IntPtr.Zero)
{
bool b = EnableWindow(wnd, 1);
System.Console.WriteLine(b);
}
}
private void button2_Click(object sender, EventArgs e)
{
IntPtr wnd = FindWindowEx(this.Handle, IntPtr.Zero, null, "button3");
if (wnd != IntPtr.Zero)
{
bool b = EnableWindow(wnd, 0);
System.Console.WriteLine(b);
}
}
button2是false
1。你应该确定找到Form 的 handle 了吗?
IntPtr xt=(IntPtr)FindWindowEx((int)FindWindow(null,"form1"),0,null,"button3");
这种写法,我第一次见。一般来说,FindWindow(null,"form1")这个函数,需要自己写个循环调用它,因为有时候并不能第一次就找到Form1这个form。所以需要循环一定的次数来查找。
2。如果能用 intptr就不要用int,这样更纯粹。
3。对于FindWindow和FindWindowEx的 class 类型那个参数,能给就给。
4。看看是否存在重名的form和button。
5。有些API确实不能起作用了在有些windows系统中。
因为 那是 class: "WindowsForms10.BUTTON.app.0.3b95145"
不是 win32 下的 button
EnableWindow对win32 下的 button 可以
建议你用AccExplorer32.exe 看看
例如AccExplorer32.exe 对html页面支持好
还有 msn 的 有个版本 可以 用AccExplorer32.exe 直接读密码
//msn的 一个漏洞
Spy++ 的消息监控好