现在的问题
在外部程序上,已知该控件hwnd,如何获取gridctrl中的所有内容
GirdCtrl控件的DLL文件我已上传到百度云
地址http://pan.baidu.com/s/1bo5FcS3
提取码zwub
现在的问题
在外部程序上,已知该控件hwnd,如何获取gridctrl中的所有内容
GirdCtrl控件的DLL文件我已上传到百度云
地址http://pan.baidu.com/s/1bo5FcS3
提取码zwub
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