Hallo,
nach meiner langen Abstinenz bin ich mit ner Frage wieder da. Muss aus meiner VB App in einem frenden Programm (OBS) in einer Listview mit Checkboxen jene an / abhaken können.
Da Sendmessage ein Djungel ist, und oftmals in einem "Warum funktioniert das?" oder "Warum funktioniert das nicht?" (Letzteres ist der Fall momentan bei mir) endet, frage ich hier mal nach.
Jenen Thread habe ich gefunden: vbforums.com/showthread.php?71…43&viewfull=1#post4389443
Code ist leider VB6, meine Übersetzung nach VB folgt am ende des Posts (Welche nicht funktioabel ist, ohne Fehlermeldung).
Kann mir jemand Helfen? Thx
Was ich Steuern muss: i.kinsi.me/96688aaa.png
Jenes Control in Spy++: i.kinsi.me/baf5e14b.png
nach meiner langen Abstinenz bin ich mit ner Frage wieder da. Muss aus meiner VB App in einem frenden Programm (OBS) in einer Listview mit Checkboxen jene an / abhaken können.
Da Sendmessage ein Djungel ist, und oftmals in einem "Warum funktioniert das?" oder "Warum funktioniert das nicht?" (Letzteres ist der Fall momentan bei mir) endet, frage ich hier mal nach.
Jenen Thread habe ich gefunden: vbforums.com/showthread.php?71…43&viewfull=1#post4389443
Code ist leider VB6, meine Übersetzung nach VB folgt am ende des Posts (Welche nicht funktioabel ist, ohne Fehlermeldung).
Kann mir jemand Helfen? Thx
Was ich Steuern muss: i.kinsi.me/96688aaa.png
Jenes Control in Spy++: i.kinsi.me/baf5e14b.png
VB.NET-Quellcode
- Public NotInheritable Class Win32
- Private Const LVM_FIRST As Long = &H1000
- Private Const LVIS_SELECTED = &H2
- Private Const LVM_SETITEMSTATE = (LVM_FIRST + 43)
- Private Const LVIF_STATE = &H8&
- Private Const LVIS_STATEIMAGEMASK As Long = &HF000
- <StructLayoutAttribute(LayoutKind.Sequential)> _
- Private Structure LVITEM
- Public mask As UInteger
- Public iItem As Integer
- Public iSubItem As Integer
- Public state As UInteger
- Public stateMask As UInteger
- Public pszText As IntPtr
- Public cchTextMax As Integer
- Public iImage As Integer
- Public lParam As IntPtr
- End Structure
- Public Shared Sub ListView_SetItemState(ByVal hWndLV As IntPtr, ByVal i As Long, ByVal nData As UInteger, ByVal mask As UInteger)
- Dim LVI As New LVITEM
- LVI.stateMask = mask
- LVI.state = nData
- LVI.mask = LVIF_STATE
- Dim ptrLvi As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(LVI))
- Marshal.StructureToPtr(LVI, ptrLvi, False)
- SendMessageA(hWndLV, LVM_SETITEMSTATE, New IntPtr(i), ptrLvi)
- End Sub
- Public Shared Sub ListView_SetCheckState(ByVal hWndLV As IntPtr, ByVal i As Long, ByVal fCheck As Integer)
- ListView_SetItemState(hWndLV, i, CUInt(&H1000& * (1 - fCheck)), LVIS_STATEIMAGEMASK)
- End Sub
- <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
- Public Shared Function FindWindowEx(ByVal parentHandle As IntPtr, ByVal childAfter As IntPtr, ByVal lclassName As String, ByVal windowTitle As String) As IntPtr
- End Function
- <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
- Private Shared Function SendMessageA(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
- End Function
- End Class
- Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
- Dim p As Process = System.Diagnostics.Process.GetProcessesByName("OBS")(0)
- Dim notepadHwnd As IntPtr = p.MainWindowHandle
- Dim editHwnd2 As IntPtr = Win32.FindWindowEx(notepadHwnd, IntPtr.Zero, "SysListView32", Nothing)
- Win32.ListView_SetCheckState(editHwnd2, -1, 1)
- End Sub