当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > 激活程序的disabled的按钮

ASP.NET
asp.net服务器上几种常见异常的解决方案.
Asp.net 下载功能的解决方案
asp.net 页面传值的几个方法
asp.net Cookie跨域、虚拟目录等设置方法
aspnet_isapi.dll设置图文方法.net程序实现伪静态
ASP.NET Web应用程序的安全解决方案浅析
asp.net 图片的读写入库实现代码
asp.net cookie的读写实例
浅析ASP.NET生成随机密码函数
asp.net 防止用户通过后退按钮重复提交表单
ASP.NET 调用百度搜索引擎的代码
asp.net用url重写URLReWriter实现任意二级域名 新
asp.net用url重写URLReWriter实现任意二级域名 高级篇
asp.net 下载文件时根据MIME类型自动判断保存文件的扩展名
asp.net 文件上传 实时进度
asp.net+jquery Gridview的多行拖放, 以及跨控件拖放
ASP.NET 页面之间传递值方式优缺点比较
asp.net 页面转向 Response.Redirect, Server.Transfer, Server.Execute的区别
ASP.NET 返回随机数实现代码
asp.net FreeTextBox配置详解

ASP.NET 中的 激活程序的disabled的按钮


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 84 ::
收藏到网摘: n/a

有些软件如果你不输入正确的注册吗,那该死的“下一步”按钮就一直disable。这个disable按钮使用WindowFromPoint, FindWindowEx均无法得到.不过,使用EnumChildWindows,GetWindow去可以枚举到每一个窗口中的所有控件,包括disabled的控件,找到了句柄,我们就可以操作了 测试环境:WINXP+VB6具体的API函数请参考MSDN. 新建工程,在form中任意添加两个按钮,两个文本框。其中按钮2的Enabled属性为falseform的Caption设为” 激活程序的disabled的按钮”.编译后,运行。 1. 我们先看看使用GetWindow枚举句柄的我们先用FindWindow找到form窗口,然后找到窗口中所有的子控件句柄,然后使用EnableWindow函数激活添加1个按钮,2个list控件。Option Explicit Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPrivate Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As LongPrivate Declare Function EnableWindow Lib "user32.dll" (ByVal hwnd As Long, ByVal fEnable As Long) As LongPrivate Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long Const GW_CHILD = 5Const GW_HWNDNEXT = 2Const WM_GETTEXT = &HDConst WM_ENABLE As Long = &HA Private Sub Command2_Click()Dim tWnd As LongDim bWnd As LongDim lpClassName As StringDim RetVal As LongDim i As IntegerDim mName As String tWnd = FindWindow(vbNullString, "激活程序的disabled的按钮")bWnd = GetWindow(tWnd, GW_CHILD) Do While bWnd <> 0lpClassName = Space(256)‘这里得到类名主要是为了可以看出bWnd所对应的控件RetVal = GetClassName(bWnd, lpClassName, 256)i = InStr(1, lpClassName, Chr(0))mName = Left(lpClassName, i - 1)List1.AddItem bWnd & " " & mName;list2主要是为了方便操作List2.AddItem bWnd‘继续寻找下一个控件bWnd = GetWindow(bWnd, GW_HWNDNEXT)LoopEnd Sub‘单击要激活的句柄Private Sub List2_Click()EnableWindow List2.List(List2.ListIndex), TrueEnd Sub 好了,运行后,点击按钮,窗口中所有的控件句柄填充到列表框中,然后点击列表框,可以发现disabled的按钮被激活,可以运行了 2. 使用EnumChildWindows来枚举函数功能:为指定的父窗口枚举子窗口Private Declare Function EnumChildWindows Lib "user32" Alias "EnumChildWindows" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long【参数表】 hWndParent ----- Long,欲枚举子窗口的父窗口的句柄 lpEnumFunc ----- Long,为每个子窗口调用的函数的指针。用AddressOf运算符获得函数在一个标准模块中的地址 代码如下:窗口Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPrivate Declare Function EnableWindow Lib "user32.dll" (ByVal hwnd As Long, ByVal fEnable As Long) As LongPrivate Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long Const WM_ENABLE As Long = &HA Private Sub Command1_Click()Dim twnd As Longtwnd = FindWindow(vbNullString, "激活程序的disabled的按钮")EnumChildWindows twnd, AddressOf EnumChildProc, ByVal 0&End Sub Private Sub List1_Click()EnableWindow List1.List(List1.ListIndex), TrueEnd Sub模块Option Explicit Public Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long Form1.List1.AddItem hwnd '继续枚举 EnumChildProc = 1End Function 好了,运行后,点击按钮,窗口中所有的控件句柄填充到列表框中,然后点击列表框,可以发现disabled的按钮被激活,可以运行了