stipulate0909 2017-03-03 08:19 采纳率: 33.3%
浏览 1974
已结题

如何用VB获取外部程序中GridCtrl中的所有内容

图片说明
GRIDCTRL这个控件可以加载到VB里,如图.

现在的问题
在外部程序上,已知该控件hwnd,如何获取gridctrl中的所有内容

GirdCtrl控件的DLL文件我已上传到百度云
地址http://pan.baidu.com/s/1bo5FcS3
提取码zwub

  • 写回答

1条回答 默认 最新

  • dabocaiqq 2017-03-03 08:17
    关注
     Imports System.Runtime.InteropServices
    Imports System
    Imports System.IO
    Imports System.Text
    Imports System.Math
    Public Class Form1
        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 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, ByVal 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 GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Integer) As Integer
        Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Integer, ByVal wCmd As Integer) As Integer
        Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Integer, ByVal lpString As String, ByVal cch As Integer) As Integer
        Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpsz1 As String, ByVal lpsz2 As String) As Integer
        Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Integer, ByVal lpClassName As String, ByVal nMaxCount As Integer) As Integer
        Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
        Private Const GW_CHILD = 5
        Private Const GW_HWNDNEXT = 2
        Private Const WM_GETTEXT As Integer = &HD
        Private Const LB_GETCOUNT = &H18B
        Private Const WM_close = 16
        Private Const EM_GETLINECOUNT As Integer = (&H1000 + 4)
        Public Function GetHandle() As Long
            Dim hwnd As Long
            Dim hChild As Long
            Dim Handle As IntPtr = Marshal.AllocHGlobal(104)
            hwnd = FindWindow(vbNullString, "刀具路径列表")
            hChild = FindWindowEx(hwnd, 0, "SysListView32", vbNullString)
            SendMessage(hChild, WM_GETTEXT, 50, Handle)
            Dim Text As String = Marshal.PtrToStringUni(Handle) '获取内容,只有一个list1
            MsgBox(Text)
            Dim intCount As Integer = SendMessage(hChild, EM_GETLINECOUNT, 0, 0) '获取行数,成功
            MsgBox(intCount)
            Dim RetVal As Long = SendMessage(hwnd, WM_close, 0&, 0&) '关闭窗口,成功
        End Function
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            GetHandle()
        End Sub
    End Class
    
    评论

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献