[DllImport("user32.dll", EntryPoint="EnableWindow")]
public static extern int EnableWindow (int hwnd,int fEnable);

解决方案 »

  1.   

    楼主可以搜索一下ApiViewer,是个不错的工具!
      

  2.   

    API精灵,lz可以留下mail,我发给你。
      

  3.   

    这样来用:[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);
    }
      

  4.   

    因为可能取不到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);
    }
    }
      

  5.   

    谢谢两位答复我,api精灵我有里面提供的只有
    [DllImport("user32.dll", EntryPoint="EnableWindow")]
    public static extern int EnableWindow (int hwnd,int fEnable);
    这,但没有一个有效的使用方法
      

  6.   

    实际上你的使用错了,
    EnableWindow((int)xt,1);应是
    EnableWindow((int)xt,0);再有就是xt应定义为IntPtr类型.
      

  7.   

    不行的,我用过了,依然没用,反回值是false.
    句柄可以不用担心我肯定没错
      

  8.   

    我一开始就是定义的IntPtr型的不行我才换了一下
      

  9.   


    用反了,不会吧,说明上说的是>0的值=0不就是false了吗
      

  10.   

    EnableWindow返回值为False不是说没有执行成功.
    这个值是这样的,如果原来Enable为False,则返回值是非0值,
    如果原来
    Enable是True,则返回值是0,
    如果要获取出错代码,要使用GetLastError.
      

  11.   

    设置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);
    }
    }
      

  12.   

    试过了button1是true
    button2是false
      

  13.   

    但无论怎么使都无法改变button3的Enable状态
      

  14.   

    学习中... 欢迎加入ASP.NET(C#)学习交流QQ群号:①32801051(已满) ②23222074(请不要两个群都加)
      

  15.   

    http://blogs.msdn.com/jfoscoding/articles/480808.aspx
      

  16.   

    看了你的代码,我觉得,是 
    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系统中。
      

  17.   

    支持hbxtlhx(平民百姓) ( ) 信誉:112
      

  18.   

    如果是 .net 的不可以
    因为 那是 class: "WindowsForms10.BUTTON.app.0.3b95145"
    不是 win32 下的 button
     EnableWindow对win32 下的 button 可以
    建议你用AccExplorer32.exe 看看
      

  19.   

    用Spy++  这个工具是VS自带的。要察看什么都可以阿
      

  20.   

    AccExplorer32.exe 和 Spy++  各有所长
    例如AccExplorer32.exe  对html页面支持好
    还有 msn 的 有个版本 可以 用AccExplorer32.exe 直接读密码
     //msn的 一个漏洞
    Spy++ 的消息监控好