上一题下一题
跳转到
 
 
  世界如此多姿,发展如此迅速,窥一斑未必还能知全豹。但正如万花筒一样,每一个管窥都色彩斑斓。  
 
 
  知识通道 | 学习首页 | 教师首页 | PK首页 | 知识创造首页 | 企业首页 | 登录
 
本文对应知识领域
VB取得窗口的句柄.类.名称
作者:未知 申领版权
2010年11月15日 共有 1151 次访问 【添加到收藏夹】 【我要附加题目
受欢迎度:

    
    取得窗口的句柄.类.名称等
    
    建立三个label1/label2/lebel3/
    名称分别为窗口句柄/类/标题/
    建立一个text窗口
    建立二个command按钮,一为开始抓取。一为退出
    还需要意义个 timer控件
    
    声明:
    Private Type POINTAPI
    x As Long
    y As Long
    End Type
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
    Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
    Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    
    Private Sub Command1_Click()
    If Command1.Caption = "开始抓取(&S)" Then
    Timer1.Enabled = True
    Command1.Caption = "停止抓取(&S)"
    Else
    Timer1.Enabled = False
    Command1.Caption = "开始抓取(&S)"
    End If
    End Sub
    
    Private Sub Command2_Click()
    End
    End Sub
    
    Private Sub Form_Load()
    SetWindowPos Me.hwnd, -1, 0, 0, 0, 0, &H1 Or &H2   '使窗体位于最顶端
    End Sub
    
    Private Sub Timer1_Timer()
    On Error Resume Next
    Dim tPoint As POINTAPI
    Dim hWin As Long
    Dim str As String * 255
    Dim Abc As String * 64000
    Dim Txt(64000) As Byte
    GetCursorPos tPoint   '获得当前鼠标位置
    hWin = WindowFromPoint(tPoint.x, tPoint.y)   '获得窗口名柄
    If hWin = Me.hwnd Or hWin = Command1.hwnd Or hWin = Command2.hwnd Or hWin = Text1.hwnd Then Exit Sub   '确定窗口不在 Form1 中
    GetClassName hWin, str, 255   '获得窗口类
    SendMessage hWin, &HD, 64000, Txt(0)   '获得窗口标题(也可使用 API 函数:GetWindowText,但效果不佳)
    Label1.Caption = "窗口名柄: " & hWin
    Label2.Caption = "窗口类: " & str
    Text1.Text = StrConv(Txt, vbUnicode)
    End Sub 
    

    

 

相关新闻

您可能对这些感兴趣  

用VB做定时断线程序
VisualBasic中的界面设计原则和编程技巧
VB6.0与Windows API 间的呼叫技巧
制作可以自动隐藏的弹出式菜单
ListBox中的字符串超长显示的解决方法
VB中的Unicode 和 Ansi 格式
优化程序显示速度
Visual Basic 产生渐层的 Form 背景
用VB实现客户——服务器(TCP/IP)
用VB制作注册软件的方法

题目筛选器
日期:
类型:
状态:
得分: <=
分类:
作者:
职业:
关键字:
搜索

 
 
 
  焦点事件
 
  知识体系
 
  职业列表
 
 
  最热文章
 
 
  最多引用文章
 
 
  最新文章
 
 
 
 
网站介绍 | 广告服务 | 招聘信息 | 保护隐私权 | 免责条款 | 法律顾问 | 意见反馈
版权所有 不得转载
沪ICP备 10203777 号 联系电话:021-54428255
  帮助提示    
《我的太学》是一种全新的应用,您在操作中遇到疑问或者问题,请拨打电话13564659895,15921448526。
《我的太学》