Good Evening,
I'm developing a Visual Basic program to control another program
written in Visual C++.
The Visual C++ program is composed of four SysListView32 objects.
I can retrieve the handles of these controls and many messages works
greatly except the LVM_SETITEMSTATE one.
When I use this kind of message the Visual C++ application randomly
returns a fatal error about the file COMCTL32.OCX and hangs up! In the
same folder of Visual C++ executable file there is a file named
COMCTL32.OCX .
I said "randomly" because in other cases nothing happens but I don't
get the fatal error and in a very little number of cases I can select
all the elements of only one SysListView of four.
The code:
Type LVITEM
mask As Long
iItem As Long
iSubItem As Long
state As Long
stateMask As Long
pszText As Long
cchTextMax As Long
iImage As Long
lParam As Long
iIndent As Long
End Type
Private Const LVM_FIRST = &H1000
Private Const LVM_SETITEMSTATE = (LVM_FIRST + 43)
Private Const LVIS_SELECTED = &H2
Private Const LVIF_STATE = &H8
Public hSysListView32(3) As Long 'handles of SysListView32
Public SysListAttrib(3) As LVITEM
Sub TestButton()
hFound = FindWindowEx(0, 0, vbNullString, "Visual C++ Program")
If hFound > 0 Then
result = EnumChildWindows(hFound, AddressOf EnumChildProc,
ByVal 0&)
End If
End Sub
Public Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As
Long) As Long
Dim sClass As String
Dim ret&
Static i As Integer
sClass = Space$(64)
ret = GetClassName(hwnd, sClass, 64)
If InStr(Left(sClass, ret), "SysListView32") Then
hSysListView32(i) = hwnd
i = i + 1
End If
EnumChildProc = 1
End Function
Sub Select() 'called by a button on the form
Dim x
For x = 0 To 3
SysListAttrib(x).mask = LVIF_STATE
SysListAttrib(x).state = True
SysListAttrib(x).stateMask = LVIS_SELECTED
Call SendMessage(hSysListView32(x), LVM_SETITEMSTATE, -1,
SysListAttrib(x))
Call UpdateWindow(hSysListView32(x))
Next x
End Sub
Thank you so much, Emilio.
Juergen Thuemmler - 17 Mar 2008 23:12 GMT
> greatly except the LVM_SETITEMSTATE one.
> When I use this kind of message the Visual C++ application randomly
> returns a fatal error about the file COMCTL32.OCX and hangs up! In the
> same folder of Visual C++ executable file there is a file named
> COMCTL32.OCX .
LVM_SETITEMSTATE requires in lParam the *address* of an LVITEM structure.
When you pass an adress of your app to the foreign app, this address is not
valid in its address space. Depending on where the address points, it can
lead to any strong exception, but in every case, also if it doesn't crash,
it doesn't work as expected. To do what you want, you must hook into the
program to be controlled and call this message from inside the program. For
example, see www.winrobots.de. WinRobots is a VB program for controlling any
foreign program written in any language and does exactly what you want using
some DLLs for hooking into foreign apps (sorry; at the moment the website
and the programs help it is available only in german :().
Juergen.
Scott Seligman - 17 Mar 2008 23:51 GMT
>> greatly except the LVM_SETITEMSTATE one.
>> When I use this kind of message the Visual C++ application randomly
[quoted text clipped - 12 lines]
>some DLLs for hooking into foreign apps (sorry; at the moment the website
>and the programs help it is available only in german :().
Why do you need to hook into the other app? That seems like the hard
way to do it.

Signature
--------- Scott Seligman <scott at <firstname> and michelle dot net> ---------
We are the universe, trying to understand itself.
-- Delenn in Babylon 5:"Passing Through Gethsemane"
Juergen Thuemmler - 18 Mar 2008 10:50 GMT
> Why do you need to hook into the other app? That seems like the hard
> way to do it.
Ok, It is one way, but very flexible, and I use it all the time when I want
to get informations from foreign apps which are related to a structure or
when I want to process any code inside the app.
Juergen.
Mark Yudkin - 23 Mar 2008 10:01 GMT
> Why do you need to hook into the other app? That seems like the hard way
> to do it.
The common controls are not multi-tasking enabled; they reside in user
address space libraries.
>>> greatly except the LVM_SETITEMSTATE one.
>>> When I use this kind of message the Visual C++ application randomly
[quoted text clipped - 19 lines]
> Why do you need to hook into the other app? That seems like the hard
> way to do it.
Scott Seligman - 23 Mar 2008 10:31 GMT
>> Why do you need to hook into the other app? That seems like the hard way
>> to do it.
>The common controls are not multi-tasking enabled; they reside in user
>address space libraries.
That doesn't mean you need to install a hook in the target app.

Signature
--------- Scott Seligman <scott at <firstname> and michelle dot net> ---------
Clothes make the man. Naked people have little or no influence on
society. -- Mark Twain