打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
VB Windows API 获取窗口句柄
userphoto

2011.01.25

关注

由于一个特殊问题和一个特殊目的,我打算写一个比较“evil”的程序(不许联想 -__-),虽然以前并没有搞过类似的东东,但凭直觉判断(可能相当不准)使用 VB 和 Windows API 搞起来会比较容易。

这个东东的第一步需要获取某个窗口的句柄,在网上找了相关资料,先照家猫画华南虎写了个可以获取鼠标所指的窗口句柄的小程序,现将代码分享如下,这么短注释我就不写了,相信都能看得懂:

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 GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function WindowFromPointXY Lib "user32" Alias "WindowFromPoint" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function GetFocus Lib "user32" () As Long
Private Declare Sub GetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)
Private Type POINTAPI
x As Long
y As Long
End Type
Private Sub Form_Load()
    SetWindowPos Me.hwnd, -1, 0, 0, 200, 0, conSwpNoActivate Or conSwpShowWindow
End Sub
Private Sub Timer1_Timer()
    Dim xy As POINTAPI
    GetCursorPos xy
    ahwnd = WindowFromPointXY(xy.x, xy.y)
    Me.Caption = "Handler : " & ahwnd
End Sub
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
VB中利用Windows API实现文件操作,VB教程,VB案例,VB实例
用VB6编写强力的windows隐藏引擎
在VBA中使用WINDOWS API
什么是API
VB使用API的简明教程
在VB 中调用动态连接库
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服