如题。
您的qq号码:401041 拒绝任何人加入加不了您。十分感谢“北冥之巅”这位朋友的回答,但不是我要的结果。我具体描述一下吧。例如我VB建立了一个 listbox1,里面放了3行内容:
1111
2222
3333
然后生成123.exe
要达到的效果是:
建立另一个程序,去读取123.exe里面的listbox1的数值直接保存为一个文本在C盘即可。或者这程序里也有一个list1(也就是listbox1),他的值用list1.additem XXX 增加123.exe的list的全部内容 :)
用VB获取外部程序List1的item内容
答案:2 悬赏:10 手机版
解决时间 2021-03-09 02:35
- 提问者网友:战皆罪
- 2021-03-08 18:53
最佳答案
- 五星知识达人网友:末日狂欢
- 2021-03-08 19:48
累死
真TM难搞
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
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 Const LB_GETCOUNT = &H18B
Private Const LB_GETTEXT = &H189
Private Const LB_GETTEXTLEN = &H18A
Private Sub Command1_Click()
Dim hWindow As Long, hList As Long
hWindow = FindWindow("ThunderFormDC", "我的窗口标题")
'Debug.Print hWindow
If hWindow = 0 Then Exit Sub
hList = FindWindowEx(hWindow, 0, "ThunderListBox", vbNullString)
'Debug.Print hList
If hList = 0 Then Exit Sub
Dim ListCount As Long
ListCount = SendMessage(hList, LB_GETCOUNT, 0, 0)
'Debug.Print ListCount
If ListCount = 0 Then Exit Sub
Dim i As Long, ItemText As String, ItemLen As Long, AllText As String
For i = 0 To ListCount - 1
ItemLen = SendMessage(hList, LB_GETTEXTLEN, i, 0)
ItemText = Space(ItemLen)
SendMessage hList, LB_GETTEXT, i, ByVal ItemText
'Debug.Print ItemText
AllText = AllText & ItemText & vbCrLf
Next
Text1.Text = AllText
End Sub
Private Sub Form_Load()
For i = 1 To 9
List1.AddItem String(i, CStr(i))
Next
End Sub
窗体上放一个listbox一个textbox一个commandbutton
textbox的MultiLine设为True
原理是先用findwindow按窗口标题找到窗口句柄,然后用findwindoex找到该窗体的listbox控件句柄(必须是VB程序,类名不对找不到的),然后sendmesssage给它,把内容传回来
我给楼主害惨了,说让写成txt文件,我懒得写,那就按楼主次要求写进自己的listbox,这可晕死,我就是放了第二个listbox才搞到现在啊,findwindowex先找到第二个,里面空的,当然失败啦,晕死我了这一晚上
现在是写进textbox里了,其他部分自己改吧
===============
晕了晕了,记得把窗体caption改成“我的窗口标题”,因为是靠窗体名字找的嘛
你用时就要把代码中的“我的窗口标题”改成你要得到list内容的那个窗口的标题了
真TM难搞
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
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 Const LB_GETCOUNT = &H18B
Private Const LB_GETTEXT = &H189
Private Const LB_GETTEXTLEN = &H18A
Private Sub Command1_Click()
Dim hWindow As Long, hList As Long
hWindow = FindWindow("ThunderFormDC", "我的窗口标题")
'Debug.Print hWindow
If hWindow = 0 Then Exit Sub
hList = FindWindowEx(hWindow, 0, "ThunderListBox", vbNullString)
'Debug.Print hList
If hList = 0 Then Exit Sub
Dim ListCount As Long
ListCount = SendMessage(hList, LB_GETCOUNT, 0, 0)
'Debug.Print ListCount
If ListCount = 0 Then Exit Sub
Dim i As Long, ItemText As String, ItemLen As Long, AllText As String
For i = 0 To ListCount - 1
ItemLen = SendMessage(hList, LB_GETTEXTLEN, i, 0)
ItemText = Space(ItemLen)
SendMessage hList, LB_GETTEXT, i, ByVal ItemText
'Debug.Print ItemText
AllText = AllText & ItemText & vbCrLf
Next
Text1.Text = AllText
End Sub
Private Sub Form_Load()
For i = 1 To 9
List1.AddItem String(i, CStr(i))
Next
End Sub
窗体上放一个listbox一个textbox一个commandbutton
textbox的MultiLine设为True
原理是先用findwindow按窗口标题找到窗口句柄,然后用findwindoex找到该窗体的listbox控件句柄(必须是VB程序,类名不对找不到的),然后sendmesssage给它,把内容传回来
我给楼主害惨了,说让写成txt文件,我懒得写,那就按楼主次要求写进自己的listbox,这可晕死,我就是放了第二个listbox才搞到现在啊,findwindowex先找到第二个,里面空的,当然失败啦,晕死我了这一晚上
现在是写进textbox里了,其他部分自己改吧
===============
晕了晕了,记得把窗体caption改成“我的窗口标题”,因为是靠窗体名字找的嘛
你用时就要把代码中的“我的窗口标题”改成你要得到list内容的那个窗口的标题了
全部回答
- 1楼网友:封刀令
- 2021-03-08 20:12
Option Explicit
Private Sub Command1_Click()
Command1.Enabled = False
WebBrowser1.Navigate2 Text1.Text
End Sub
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Dim x As Long
List1.Clear
For x = 0 To WebBrowser1.Document.Links.length - 1
List1.AddItem WebBrowser1.Document.Links.Item(x)
Next x
Command1.Enabled = True
End Sub
Private Sub WebBrowser1_StatusTextChange(ByVal Text As String)
Label3 = Text
End Sub
QQ 401041
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯