VC++外部程序获取ListView控件内容,详细见问题补充,求高手支招啊!

VC++外部程序获取ListView控件内容,详细见问题补充,求高手支招啊!,第1张

你说的CListCtrl?

如果这InsertColumn()添加的列标题,

添加的内容InsertItem(),和SetItem()/ SetItemText()函数;

InsertColumn()2过载:

诠释InsertColumn(NCOL,LPCTSTR lpszColumnHeading,

资源回收的事宜= LVCFMT_LEFT,nWidth = -1,nSubItem = -1);

诠释InsertColumn(NCOL,常量LVCOLUMN pColumn)

InsertItem()有三个重载:

诠释InsertItem(const字段LVITEM pItem);

诠释InsertItem(nItem项,LPCTSTR lpszItem);

>诠释InsertItem(nItem项,LPCTSTR lpszItem,INT n影像);

如果这个UserControl1是你自己做的,那么你可以参考下面的代码,在UserControl1里面加上相应的代码即可

123456789'注意!不要删除或修改下列被注释的行!'MappingInfo=Text1,Text1,-1,TextPublic Property Get Text() As String Text = Text1TextEnd PropertyPublic Property Let Text(ByVal New_Text As String) Text1Text() = New_Text PropertyChanged "Text"End Property

这样就相当于做好了一个只有Text属性的TextBox控件

引用方法UserControl1Text

如果这个UserControl1不是你自己做的,

而且没有源码,那么你只能通过Hwnd来获取它的值了。

有问题请追问,

方法很多: 1、如果原来的软件有用数据库存数据那就简单,直接读数据库 2、如果原来软件数据是临时的,那就试试用spyit!之类的软件看看能不能定位到原来软件的窗口上的控件上,如果可以,那你用C#的findwindow、findwindowex之类的

我有个实例:打开记事本+获得记事本的句柄+向记事本中写入字符串+更改记事本的标题+获得所有运行的程序的标题。代码如下:

VERSION 500

Begin VBForm Form1

Caption = "Form1"

ClientHeight = 5325

ClientLeft = 60

ClientTop = 450

ClientWidth = 7560

LinkTopic = "Form1"

LockControls = -1 'True

ScaleHeight = 5325

ScaleWidth = 7560

StartUpPosition = 2 '屏幕中心

Begin VBListBox List1

Height = 4380

Left = 360

TabIndex = 4

Top = 480

Width = 4095

End

Begin VBCommandButton Command4

Caption = "获得所有程序标题"

Height = 495

Left = 4800

TabIndex = 3

Top = 2400

Width = 2535

End

Begin VBCommandButton Command3

Caption = "打开写入记事本+改标题"

Height = 495

Left = 4800

TabIndex = 2

Top = 1800

Width = 2535

End

Begin VBCommandButton Command2

Caption = "运行记事本"

Height = 495

Left = 4800

TabIndex = 1

Top = 1200

Width = 2535

End

Begin VBCommandButton Command1

Caption = "打开写入记事本"

Height = 495

Left = 4800

TabIndex = 0

Top = 600

Width = 2535

End

End

Attribute VB_Name = "Form1"

Attribute VB_GlobalNameSpace = False

Attribute VB_Creatable = False

Attribute VB_PredeclaredId = True

Attribute VB_Exposed = False

'1

Private Declare Function WinExec Lib "kernel32" (ByVal lpCmdLine As String, ByVal nCmdShow As Long) As Long

'==========================================================

'3

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 WM_PASTE = &H302

'===========================================================

'4

Private Declare Function GetDesktopWindow Lib "user32" () As Long

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

Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long

Private Const GW_CHILD = 5

Private Const GW_HWNDNEXT = 2

'

Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long

Private Sub Command1_Click()

'1 打开 写入 记事本

Dim AppID As Integer

AppID = Shell("C:\WINDOWS\notepadexe", 1)

AppActivate AppID

SendKeys "-2356e+012年后光荣感如果好了" '"SendKeys--字符有误,速度慢"

End Sub

Private Sub Command2_Click()

WinExec "notepadexe", 5

End Sub

Private Sub Command3_Click()

'3 打开 写入 记事本+改标题

Dim TemphWnd As Long

AppID = Shell("C:\WINDOWS\notepadexe", 1)

TemphWnd = FindWindow("Notepad", vbNullString)

'--------------------------------------------

SetWindowText TemphWnd, "Welcome to VB" '

'--------------------------------------------

TemphWnd = FindWindowEx(TemphWnd, 0, "Edit", vbNullString)

If TemphWnd Then

'DebugPrint TemphWnd

VBClipboardSetText "-2356e+012年后光荣感如果好了" '"SendMessage--字符正确,速度快"

SendMessage TemphWnd, WM_PASTE, 0, ByVal 0&

End If

End Sub

Private Sub Command4_Click()

'4 获得所有程序标题

Dim ret As Long

Dim hwnd As Long

Dim str As String 256

ret = GetDesktopWindow()

hwnd = GetWindow(ret, GW_CHILD)

Do While hwnd <> 0

GetWindowText hwnd, str, Len(str)

hwnd = GetWindow(hwnd, GW_HWNDNEXT)

If Left$(str, 1) <> vbNullChar Then

Form1List1AddItem str

End If

Loop

End Sub

以上就是关于VC++外部程序获取ListView控件内容,详细见问题补充,求高手支招啊!全部的内容,包括:VC++外部程序获取ListView控件内容,详细见问题补充,求高手支招啊!、VB 如何获得用户控件里面某个控件的值、如何获取别的进程的TreeView控件的内容等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/10120786.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-05
下一篇 2023-05-05

发表评论

登录后才能评论

评论列表(0条)

保存