精华内容
下载资源
问答
  • VB获取窗口句柄

    2018-03-12 01:27:05
    VB获取窗口句柄最容易看明白的代码。先看明白取窗口句柄后再学习取控件句柄。
  • vb 获取窗口句柄 并发信息

    万次阅读 2011-11-29 08:23:22
    (本文中部分使用繁体字,如果在简体系统下请将第三部实例...Public Declare Function ShowWindow Lib"user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long (根据句柄控制某一窗体显示状态) Public Decla

    (本文中部分使用繁体字,如果在简体系统下请将第三部实例程序记事本标题换成相对应的简体名称)

    第一部分:

    常用的与窗体相关的API函数

    Public Declare Function ShowWindow Lib"user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long (根据句柄控制某一窗体显示状态)

    Public Declare Function EnableWindow Lib"user32" (ByVal hwnd As Long, ByVal fEnable As Long) As Long(使能窗口事件)

    Public Declare Function FindWindow Lib"user32" Alias "FindWindowA" (ByVal lpClassName As String,ByVal lpWindowName As String) As Long(根据标题找主窗口句柄)

    Public Declare Function EnumWindows Lib"user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long(找到窗口组)

    Public Declare Function FindWindowEx Lib"user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByValhWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long(找子窗口部件)

     

     

    Public Declare Function GetParent Lib"user32" (ByVal hwnd As Long) As Long

    Public Declare Function GetWindow Lib"user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long

    Public Declare Function GetWindowText Lib"user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVallpString As String, ByVal cch As Long) As Long(获取窗口标题)

    Public Declare Function GetClassName Lib"user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVallpClassName As String, ByVal nMaxCount As Long) As Long(获取窗口类)

     

    Public Declare Function SendMessage Lib"user32" Alias "SendMessageA" (ByVal hwnd As Long, ByValwMsg As Long, ByVal wParam As Long, lParam As Any) As Long(发送信息)

    Private Declare Function PostMessage Lib"user32" Alias "PostMessageA" (ByVal hwnd As Long, ByValwMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long(发送信息)

     

    Public Declare Sub Sleep Lib "kernel32"(ByVal dwMilliseconds As Long) (延时用)

    Public Declare Sub keybd_event Lib"user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags AsLong, ByVal dwExtraInfo As Long)(键盘事件)

    第二部分

    按键编码

    Public Const VK_LBUTTON = &H1

    Public Const VK_RBUTTON = &H2

    Public Const VK_CANCEL = &H3

    Public Const VK_MBUTTON = &H4

    Public Const VK_BACK = &H8

    Public Const VK_TAB = &H9

    Public Const VK_CLEAR = &HC

    Public Const VK_RETURN = &HD

    Public Const VK_SHIFT = &H10

    Public Const VK_CONTROL = &H11

    Public Const VK_MENU = &H12

    Public Const VK_PAUSE = &H13

    Public Const VK_CAPITAL = &H14

    Public Const VK_ESCAPE = &H1B

    Public Const VK_SPACE = &H20

    Public Const VK_PRIOR = &H21

    Public Const VK_NEXT = &H22

    Public Const VK_END = &H23

    Public Const VK_HOME = &H24

    Public Const VK_LEFT = &H25

    Public Const VK_UP = &H26

    Public Const VK_RIGHT = &H27

    Public Const VK_DOWN = &H28

    Public Const VK_Select = &H29

    Public Const VK_PRINT = &H2A

    Public Const VK_EXECUTE = &H2B

    Public Const VK_SNAPSHOT = &H2C

    Public Const VK_Insert = &H2D

    Public Const VK_Delete = &H2E

    Public Const VK_HELP = &H2F

    Public Const VK_0 = &H30

    Public Const VK_1 = &H31

    Public Const VK_2 = &H32

    Public Const VK_3 = &H33

    Public Const VK_4 = &H34

    Public Const VK_5 = &H35

    Public Const VK_6 = &H36

    Public Const VK_7 = &H37

    Public Const VK_8 = &H38

    Public Const VK_9 = &H39

    Public Const VK_A = &H41

    Public Const VK_B = &H42

    Public Const VK_C = &H43

    Public Const VK_D = &H44

    Public Const VK_E = &H45

    Public Const VK_F = &H46

    Public Const VK_G = &H47

    Public Const VK_H = &H48

    Public Const VK_I = &H49

    Public Const VK_J = &H4A

    Public Const VK_K = &H4B

    Public Const VK_L = &H4C

    Public Const VK_M = &H4D

    Public Const VK_N = &H4E

    Public Const VK_O = &H4F

    Public Const VK_P = &H50

    Public Const VK_Q = &H51

    Public Const VK_R = &H52

    Public Const VK_S = &H53

    Public Const VK_T = &H54

    Public Const VK_U = &H55

    Public Const VK_V = &H56

    Public Const VK_W = &H57

    Public Const VK_X = &H58

    Public Const VK_Y = &H59

    Public Const VK_Z = &H5A

    Public Const VK_STARTKEY = &H5B

    Public Const VK_CONTEXTKEY = &H5D

    Public Const VK_NUMPAD0 = &H60

    Public Const VK_NUMPAD1 = &H61

    Public Const VK_NUMPAD2 = &H62

    Public Const VK_NUMPAD3 = &H63

    Public Const VK_NUMPAD4 = &H64

    Public Const VK_NUMPAD5 = &H65

    Public Const VK_NUMPAD6 = &H66

    Public Const VK_NUMPAD7 = &H67

    Public Const VK_NUMPAD8 = &H68

    Public Const VK_NUMPAD9 = &H69

    Public Const VK_MULTIPLY = &H6A

    Public Const VK_ADD = &H6B

    Public Const VK_SEPARATOR = &H6C

    Public Const VK_SUBTRACT = &H6D

    Public Const VK_DECIMAL = &H6E

    Public Const VK_DIVIDE = &H6F

    Public Const VK_F1 = &H70

    Public Const VK_F2 = &H71

    Public Const VK_F3 = &H72

    Public Const VK_F4 = &H73

    Public Const VK_F5 = &H74

    Public Const VK_F6 = &H75

    Public Const VK_F7 = &H76

    Public Const VK_F8 = &H77

    Public Const VK_F9 = &H78

    Public Const VK_F10 = &H79

    Public Const VK_F11 = &H7A

    Public Const VK_F12 = &H7B

    Public Const VK_F13 = &H7C

    Public Const VK_F14 = &H7D

    Public Const VK_F15 = &H7E

    Public Const VK_F16 = &H7F

    Public Const VK_F17 = &H80

    Public Const VK_F18 = &H81

    Public Const VK_F19 = &H82

    Public Const VK_F20 = &H83

    Public Const VK_F21 = &H84

    Public Const VK_F22 = &H85

    Public Const VK_F23 = &H86

    Public Const VK_F24 = &H87

    Public Const VK_NUMLOCK = &H90

    Public Const VK_OEM_SCROLL = &H91

    Public Const VK_OEM_1 = &HBA

    Public Const VK_OEM_PLUS = &HBB

    Public Const VK_OEM_COMMA = &HBC

    Public Const VK_OEM_MINUS = &HBD

    Public Const VK_OEM_PERIOD = &HBE

    Public Const VK_OEM_2 = &HBF

    Public Const VK_OEM_3 = &HC0

    Public Const VK_OEM_4 = &HDB

    Public Const VK_OEM_5 = &HDC

    Public Const VK_OEM_6 = &HDD

    Public Const VK_OEM_7 = &HDE

    Public Const VK_OEM_8 = &HDF

    Public Const VK_ICO_F17 = &HE0

    Public Const VK_ICO_F18 = &HE1

    Public Const VK_OEM102 = &HE2

    Public Const VK_ICO_HELP = &HE3

    Public Const VK_ICO_00 = &HE4

    Public Const VK_ICO_CLEAR = &HE6

    Public Const VK_OEM_RESET = &HE9

    Public Const VK_OEM_JUMP = &HEA

    Public Const VK_OEM_PA1 = &HEB

    Public Const VK_OEM_PA2 = &HEC

    Public Const VK_OEM_PA3 = &HED

    Public Const VK_OEM_WSCTRL = &HEE

    Public Const VK_OEM_CUSEL = &HEF

    Public Const VK_OEM_ATTN = &HF0

    Public Const VK_OEM_FINNISH = &HF1

    Public Const VK_OEM_COPY = &HF2

    Public Const VK_OEM_AUTO = &HF3

    Public Const VK_OEM_ENLW = &HF4

    Public Const VK_OEM_BACKTAB = &HF5

    Public Const VK_ATTN = &HF6

    Public Const VK_CRSEL = &HF7

    Public Const VK_EXSEL = &HF8

    Public Const VK_EREOF = &HF9

    Public Const VK_PLAY = &HFA

    Public Const VK_ZOOM = &HFB

    Public Const VK_NONAME = &HFC

    Public Const VK_PA1 = &HFD

    Public Const VK_OEM_CLEAR = &HFE

    第三部分:

    实例打开记事本---并发送信息

    (上面的声明放在一个模块中即可)

     

    Option Explicit

    Private StartTime As Long

     

    Private Declare Function SendMessage& Lib"user32" Alias "SendMessageA" (ByVal hwnd As Long, ByValwMsg As Long, ByVal wParam As Long, lParam As Any)

    Private Declare Function PostMessage Lib"user32" Alias "PostMessageA" (ByVal hwnd As Long, ByValwMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

    Private Declare Function FindWindow Lib"user32" Alias "FindWindowA" (ByVal lpClassName As String,ByVal lpWindowName As String) As Long

    Private Const WM_KEYDOWN = &H100

    Private Const VK_F1 = &H70

    Private Const WM_KEYUP = &H101

     

    Public Sub Delay(mSec As Long)

        DimTStart As Single

        TStart =Timer

        While(Timer - TStart) < (mSec / 1000)

           DoEvents

        Wend

    End Sub

     

    Private Sub Command1_Click()

        DimReturnValue

       ReturnValue = Shell("notepad.exe", vbNormalFocus) '打开记事本

       AppActivate ReturnValue                            '激活窗口

        Dim hwndAs Long

       

        hwnd =FindWindow(vbNullString, "未命名-记事本")  '窗口标题

        SendKeys"= ", True

        SendKeys"I am ok", True

        SendKeys"{ENTER}", True

           SendKeys "{TAB}", True

       PostMessage hwnd, WM_KEYDOWN, VK_RETURN, 0

        Delay(1000)

       PostMessage hwnd, WM_KEYUP, VK_RETURN, 0

        Delay(1000)

           SendKeys "5", True

    End Sub

     

     

    Private Sub Command2_Click()

    End

    End Sub



     第四部分

    总结

    获取句柄的方法

    1主窗体(可参考上面的方法)

    如果是多个窗体要查找某一个

    '用 FindWindowEx 查找第一个,再用找到的窗口句柄作为参数再次调用 FindWindowEx,查找第二个,直到返回 0 为止
    '得到句柄后,用 GetWindowText 得到标题,分析它提取出你需要的窗口
    Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    Private Sub Command1_Click()
    Dim dl As Long, winHwnd As Long, nStr As String, nSize As Long
    
    nSize = 128
    Do
       winHwnd = FindWindowEx(0, winHwnd, vbNullString, vbNullString) '得到一个窗口句柄
       If winHwnd = 0 Then Exit Do
       nStr = String(nSize, vbNullChar)
       dl = GetWindowText(winHwnd, nStr, nSize)       '得到窗口标题
       nStr = Left(nStr, InStr(nStr, vbNullChar) - 1) '去掉后面的无用字符
       If LCase(Right(nStr, 5)) = "1.exe" Then MsgBox winHwnd & vbCrLf & nStr '提取出符合条件的标题
    Loop


    2子窗体(部件),窗体组

    `控件需要知道类名可以用spy++查看

    private Sub Command1_Click()  
    Dim Phwnd As Long  
    Dim ChildHwnd As Long  
    Phwnd = FindWindow(vbNullString, "计算器")  
    If Phwnd <> 0 Then  
     ChildHwnd = FindWindowEx(Phwnd, 0, "Edit", vbNullString)  
     If ChildHwnd <> 0 Then  
     SendMessage ChildHwnd, WM_SETTEXT, 0, ByVal "我是计算器"  
     Else  
     MsgBox "找不到相关控件"  
     End If  
    Else  
     MsgBox "计算器程序没有运行"  
    End If  
    End Sub  


    发送信息的方法

    1--------------

    先获取窗口句柄(方法同上),然后用sendmessage发信息

    Private Const WM_SETTEXT = &HC
    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 GetDlgItem Lib "user32" (ByVal hDlg As Long, ByVal nIDDlgItem As Long) As Long

    Dim s As String
    Dim FT_hWnd As Long
    Dim ID_Control_hWnd As Long
    s = "test" & vbCrLf & "找到你了"
     
    

     ID_Control_hWnd = GetDlgItem(你得到的句柄值, &HF)
    SendMessage ID_Control_hWnd, WM_SETTEXT, 0, ByVal s


    2------------------------------

    用 SendKeys 语句
    AppActivate "接收键盘事件的窗口标题" ' 激活指定窗口
    SendKeys "A", True '发送字符 A

    '  SendKeys "I am ok", True
     '   SendKeys "{ENTER}", True
     '   PostMessage hwnd, WM_KEYDOWN, VK_RETURN, 0
     '   Delay (1000)
     '   PostMessage hwnd, WM_KEYUP, VK_RETURN, 0
     '   Delay (1000)

     


    展开全文
  • VB2010编写的一个 窗口句柄信息动态获取工具源码,新手可以参考学习,不知道的可以留言,里面还有一个vb6的也是源码.一起奉上.有可以学习的是图片鼠标的代替
  • vb 获取任意程序窗体句柄

    热门讨论 2011-08-13 04:12:15
    可以获取正常情况下无法获取窗口句柄,某些网络游戏会有屏蔽正常获取游戏窗口句柄,用此代码可以正常
  • vb.net】获取窗口控件句柄笔记

    千次阅读 2020-03-07 23:04:24
    使用FindWindow和FindWindowEx找出路径文本框和保存按钮的句柄 使用SendMessage和SendMessageEX将自定义路径字符串输入至上述的文本框,并后台模拟点击保存按钮。 基本的思路是没有问题的,如文本编辑器的另存为...

    近期在做一个【在文件另存为窗口快速输入自定义路径字符串】的功能,一开始基本的思路是:

    • 研究分类各种软件的另存为窗口的控件类型、标题
    • 使用FindWindowFindWindowEx找出路径文本框和保存按钮的句柄
    • 使用SendMessageSendMessageEX将自定义路径字符串输入至上述的文本框,并后台模拟点击保存按钮。

    基本的思路是没有问题的,如文本编辑器的另存为窗口,使用如下代码可以获取另存为窗口的文本框句柄:

    myhwnd = FindWindow(vbNullString, "另存为")
    myhwnd = FindWindowEx(myhwnd, 0&, "DirectUIHWND", vbNullString)
    myhwnd = FindWindowEx(myhwnd, 0&, "FloatNotifySink", vbNullString) 
    myhwnd = FindWindowEx(myhwnd, 0&, "ComboBox", vbNullString)
    myhwnd = FindWindowEx(myhwnd, 0&, "Edit", vbNullString)
    

    但各种各种的另存为窗口,目标文本框和按钮需要清楚父子窗口的控件类名,效率将变得十分低下,而且通用性也不强,例如ps的另存为窗口标题是“存储为”,而不是“另存为”,很多软件的文本框也不是这种非常具体的父子窗口。
    因此急需使用另外一种高效的算法来遍历/枚举某一个桌面直接子窗口的所有控件,根据条件(类名标题)找出所需的控件。
    【未完待续】
    另,使用Spy++参看窗口和控件句柄。
    ‘--------------以上记录于2020/3/7 23:00--------------

    在研究了一晚后,最终使用GetNextWindow遍历全部桌面直接子窗口,再使用EnumChildWindows配合回调函数EnumChildProcCallback实现【遍历桌面全部直接子窗口,再遍历某个子窗口的全部控件】,只要找到目标文本框和保存按钮,已基本实现目标功能【在文件另存为窗口快速输入自定义路径字符串】,而中间遇到几个小问题:

    • 隐藏的子窗口或者控件(Spy++显示为灰色)可以使用GetWindowLongWS_VISIBLE(&H10000000)判断过滤掉,提高效率。
    • 窗口和控件标题本来使用GetWindowText获取,但未知原因常出现获取不到,所以使用SendMessage获得。

    至于另外一个子程序,获得最近打开的资源管理器路径,实现过程大致相同,放在下次笔记中。
    ‘--------------以上记录于2020/3/8 09:30--------------

    这段时间主要忙于复工复产,所以没有太多时间更新。

    上次讲到获得最近打开的资源管理器路径,由于【最近打开的资源管理器路径】其实是第一个CabinetWClass类窗口,层次关系清楚,所以没有使用上文所述的EnumChildWindows获得,可暴力使用以下代码获得:

    myhwnd = FindWindow("CabinetWClass", vbNullString)
    fhwnd = myhwnd
    myhwnd = FindWindowEx(myhwnd, 0&, "WorkerW", vbNullString)
    myhwnd = FindWindowEx(myhwnd, 0&, "ReBarWindow32", vbNullString)
    myhwnd = FindWindowEx(myhwnd, 0&, "Address Band Root", vbNullString)
    myhwnd = FindWindowEx(myhwnd, 0&, "msctls_progress32", vbNullString)
    myhwnd = FindWindowEx(myhwnd, 0&, "Breadcrumb Parent", vbNullString)
    myhwnd = FindWindowEx(myhwnd, 0&, "ToolbarWindow32", vbNullString)
    

    如果myhwnd 为0,代表还存在另外一种可能,使用如下代码获得:

    myhwnd = FindWindow("CabinetWClass", vbNullString)
    fhwnd = myhwnd
    myhwnd = FindWindowEx(myhwnd, 0&, "WorkerW", vbNullString)
    myhwnd = FindWindowEx(myhwnd, 0&, "ReBarWindow32", vbNullString)
    myhwnd = FindWindowEx(myhwnd, 0&, "Address Band Root", vbNullString)
    myhwnd = FindWindowEx(myhwnd, 0&, "msctls_progress32", vbNullString)
    myhwnd = FindWindowEx(myhwnd, 0&, "ComboBoxEx32", vbNullString)
    

    至此
    【在文件另存为窗口快速输入自定义路径字符串】功能得以实现,总结实现过程:

    1. 使用**Spy++**参看窗口和控件句柄,分析其层次关系、类名、标题。
    2. 使用GetNextWindow遍历全部桌面直接子窗口,再使用EnumChildWindows配合回调函数EnumChildProcCallback基本可以找到任何你想取得的控件、窗口句柄。
    3. 合理使用FindWindowFindWindowExSendMessageSendMessageEX等API获得类名、标题,模拟输入。


    ‘--------------以上记录于2020/3/24 22:49--------------

    展开全文
  • 可以获取程序窗体句柄并编辑文本和触发事件
  • VB 适时获得当前窗口句柄,当前窗口由你的鼠标决定,你把鼠标移到哪个窗口上,就会得到哪个窗口句柄,不论当前窗口是否是活动的。
  • ' 通过进程ID获得该进程的窗口句柄 Public Function InstanceToWnd(ByVal target_pid As Long) As Long Dim test_hwnd As Long Dim test_pid As Long Dim test_thread_id As Long InstanceToWnd = 0 'On Error ...
    Option Explicit
    Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal Hwnd As Long, lpdwProcessId As Long) As Long
    Private Declare Function GetParent Lib "user32" (ByVal Hwnd As Long) As Long
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Long, ByVal lpWindowName As Long) As Long
    Private Declare Function GetWindow Lib "user32" (ByVal Hwnd As Long, ByVal wCmd As Long) As Long
    Const GW_HWNDNEXT = 2
    ' 通过进程ID获得该进程的窗口句柄
    Public Function InstanceToWnd(ByVal target_pid As Long) As Long
        Dim test_hwnd As Long
        Dim test_pid As Long
        Dim test_thread_id As Long
        InstanceToWnd = 0
        'On Error Resume Next
        ' 获得首个handle.
        test_hwnd = FindWindow(ByVal 0&, ByVal 0&)
    
        ' 循环查找直到找到为给定进程ID的窗口句柄
        Do While test_hwnd <> 0
            '检查窗口句柄是否为顶级窗口
            If GetParent(test_hwnd) = 0 Then
                ' 是顶级窗口
                ' 取该窗口所属的进程ID
                test_thread_id = GetWindowThreadProcessId(test_hwnd, test_pid)
    
                If test_pid = target_pid Then
                    ' 是我们指定进程的窗口,则将该窗口的句柄返回到函数名,并退出
                    InstanceToWnd = test_hwnd
                    Exit Do
                End If
            End If
    
            ' 取下一个窗口的句柄
            test_hwnd = GetWindow(test_hwnd, GW_HWNDNEXT)
        Loop
    End Function
    展开全文
  • 获取窗口句柄 通过标题来获取窗口句柄的名称 可以制成模块 随时可以调用代码很简单
  • 请各位朋友帮忙,有重谢!!!,知道了一个窗口句柄,怎么获得IHTMLDOCUMENT接口, 进而可以获得网页的内容?
  • VB6.0拖动获取窗口句柄.zip
  • vb查看窗口句柄

    千次阅读 2011-11-28 15:36:48
    WinAPI: FindWindow、FindWindowEx - 查找窗口 http://www.cnblogs.com/del/archive/2008/02/28/1085432.html FindWindow(  lpClassName, {窗口的类名}  lpWindowName: PChar {窗口的标题} ): HWND;
     
    
    FindWindow(
      lpClassName,        {窗口的类名}
      lpWindowName: PChar {窗口的标题}
    ): HWND;              {返回窗口的句柄; 失败返回 0}
    
    //FindWindowEx 比 FindWindow 多出两个句柄参数:
    FindWindowEx(
      Parent: HWND;     {要查找子窗口的父窗口句柄}
      Child: HWND;      {子窗口句柄}
      ClassName: PChar; {}
      WindowName: PChar {}
    ): HWND;
    {
    如果 Parent 是 0, 则函数以桌面窗口为父窗口, 查找桌面窗口的所有子窗口;
    如果  是 HWND_MESSAGE, 函数仅查找所有消息窗口;
    子窗口必须是 Parent 窗口的直接子窗口;
    如果 Child 是 0, 查找从 Parent 的第一个子窗口开始;
    如果 Parent 和 Child 同时是 0, 则函数查找所有的顶层窗口及消息窗口.
    }
    
       
    //测试1: 试着找找新建程序主窗口的句柄 var   h: HWND; begin   {现在我们知道窗口的标题是: Form1、窗口的类名是: TForm1}   h := FindWindow('TForm1', 'Form1');   ShowMessage(IntToStr(h));      {656180; 这是随机, 每次启动窗口肯定不一样}   {假如不知道类名}   h := FindWindow(nil, 'Form1');   ShowMessage(IntToStr(h));      {656180}   {假如不知道标题名}   h := FindWindow('TForm1', nil);   ShowMessage(IntToStr(h));      {656180}   {其实这个窗口的句柄不就是 Self.Handle 吗}   ShowMessage(IntToStr(Handle)); {656180} end;
    //测试2: 找计算器窗口的句柄(先打开计算器) var   h: HWND; begin   {如果不是简体中文系统, 这样可能不灵}   h := FindWindow(nil, '计算器');   ShowMessage(IntToStr(h)); {1508334}   {最好这样, 但你得提前知道计算器窗口的类名是: SciCalc}   h := FindWindow('SciCalc', nil);   ShowMessage(IntToStr(h)); {1508334} end;
       

    VB查找子窗口句柄代码  

    2010-10-21 15:55:29|  分类: 程序编程|字号 订阅

    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long  '找窗口列表中第一个符合指定条件的窗口

    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long  '在窗口列表中寻找与指定条件相符的第一个子窗口

    'FindWindowEx函数一般跟 FindWindow 一起使用,先用 FindWindow 查找程序父窗体句柄,在根据找到的父窗体句柄用FindWindowEx查找子窗体句柄。

    Private Declare Function EnableWindow Lib "user32" (ByVal hwnd As Long, ByVal fEnable As Long) As Long  '在指定的窗口里允许或禁止所有鼠标及键盘输入

    Private Sub Command1_Click()  Dim WindowHandle As Long, ChildWindowHandle As Long     '用于储存获取的句柄 WindowHandle = FindWindow(vbNullString, "无标题 - 记事本")     If WindowHandle Then      '如果获取句柄成功  ChildWindowHandle = FindWindowEx(WindowHandle, 0, "Edit", vbNullString)  If ChildWindowHandle Then '如果成功获取子句柄  EnableWindow ChildWindowHandle, False '禁用子窗口  Else  MsgBox "无法获取子窗口"  End If  End If  End Sub

    展开全文
  • 上次传的一个VB2010 窗口句柄信息动态获取里面有些错误,后来想撤回的,发现已经撤不回了,这次修改后再发一次,Vb仿SPY获取和查找当前程序句柄,查找出当前支持的程序窗口句柄,并显示出窗口信息。VB2010编写的一个 ...
  • VB6 根据进程ID(PID)获取窗体句柄

    千次阅读 2017-02-21 08:49:49
    模块代码:   Option Explicit Private Const GW_HWNDNEXT = 2 Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long Private Declare Function GetWindow Lib "user32" (ByVal ...
  • vb获取句柄

    2018-07-04 10:22:42
    vb获取鼠标指定位置窗口句柄句柄内容关联 vb获取鼠标指定位置窗口句柄句柄内容关联 vb获取鼠标指定位置窗口句柄句柄内容关联 vb获取鼠标指定位置窗口句柄句柄内容关联
  • VB快速获取程序句柄

    2014-08-18 13:21:02
    快速获取程序句柄,为sendmessage做前期工作,校验所获句柄正确性
  • 已知窗口句柄,获取标题.不知道有没有人需要
  • VB6.0获取鼠标位置下的控件的句柄及类名,按组合键 Ctrl Alt K 暂停或开始捕获,获得窗口标题(也可使用 API 函数:GetWindowText,但效果不佳),你可了解下设置热键和删除热键。
  • vb获取窗体上的控件句柄

    热门讨论 2011-09-26 11:58:09
    vb获取窗体上的控件句柄的例子程序,相当的不错。
  • j As Long, s As String i = GetWindow(hwnd, 0&) Do Until i = 0 If IsWindowVisible(i) Then s = Trim(GetWinText(i)) If instr(s,"Client Ver :") Then '这时候i就是该程序的句柄,你可以在此发送按键消息了 '...
  • Function GetWindowHwnd(ByVal WindowClassVsWindowText As String) As Long '获窗口句柄 可以是: 窗口名 或者是 窗口类名 Dim stro As String stro = WindowClassVsWindowText Dim chwnd As Long chwnd = ...
  • VB.NET通过窗口句柄获取webbrowser控件HTML内容通过Sendmessage获取IE浏览器内容 webbrowser控件内容获取Class Win32API _Public Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As...
  • VBA示例之 求人不如自已动手 取得当前激活窗口句柄及标题,供初学者参考,大牛勿进~~~~~~~
  • ' 功能: 通过窗口句柄得到模块名称 '******************************************************************************** ' Public Function GetModuleFileNameByHwnd(ByVal hWindow As Long) As String Dim ...
  • VB遍历桌面所有的窗口句柄(包括父窗口和子窗口类名)
  • vb-EnumChildWindows所有窗口及子窗口句柄是一款vb枚举窗口枚举出所有父窗口和其对应的子窗口句柄信息获取查看工具,每个子窗口控件都具有一个在其兄弟中唯一的窗口句柄和ID值。对于句柄和ID这两者,知道其中的一个...
  • VB遍历桌面所有的窗口句柄(包括父窗口和子窗口类名)
  • VB.NET 获取当前活动窗体句柄

    千次阅读 2020-05-09 14:48:50
    VB.NET 获取当前活动窗体标题 添加以下 API 声明 Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As IntPtr, ByVal lpString As String, ByVal cch As Integer) As ...
  • 根据窗口句柄截取任意窗口图片 VS2008

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 4,395
精华内容 1,758
关键字:

vb获取窗口句柄