Elemente in fremden Prozess / Form innerhalb einer SysListView32 An / Abhaken

  • VB.NET
  • .NET (FX) 4.0

Es gibt 1 Antwort in diesem Thema. Der letzte Beitrag () ist von RodFromGermany.

    Elemente in fremden Prozess / Form innerhalb einer SysListView32 An / Abhaken

    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 :thumbsup:

    Was ich Steuern muss: i.kinsi.me/96688aaa.png

    Jenes Control in Spy++: i.kinsi.me/baf5e14b.png

    VB.NET-Quellcode

    1. Public NotInheritable Class Win32
    2. Private Const LVM_FIRST As Long = &H1000
    3. Private Const LVIS_SELECTED = &H2
    4. Private Const LVM_SETITEMSTATE = (LVM_FIRST + 43)
    5. Private Const LVIF_STATE = &H8&
    6. Private Const LVIS_STATEIMAGEMASK As Long = &HF000
    7. <StructLayoutAttribute(LayoutKind.Sequential)> _
    8. Private Structure LVITEM
    9. Public mask As UInteger
    10. Public iItem As Integer
    11. Public iSubItem As Integer
    12. Public state As UInteger
    13. Public stateMask As UInteger
    14. Public pszText As IntPtr
    15. Public cchTextMax As Integer
    16. Public iImage As Integer
    17. Public lParam As IntPtr
    18. End Structure
    19. Public Shared Sub ListView_SetItemState(ByVal hWndLV As IntPtr, ByVal i As Long, ByVal nData As UInteger, ByVal mask As UInteger)
    20. Dim LVI As New LVITEM
    21. LVI.stateMask = mask
    22. LVI.state = nData
    23. LVI.mask = LVIF_STATE
    24. Dim ptrLvi As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(LVI))
    25. Marshal.StructureToPtr(LVI, ptrLvi, False)
    26. SendMessageA(hWndLV, LVM_SETITEMSTATE, New IntPtr(i), ptrLvi)
    27. End Sub
    28. Public Shared Sub ListView_SetCheckState(ByVal hWndLV As IntPtr, ByVal i As Long, ByVal fCheck As Integer)
    29. ListView_SetItemState(hWndLV, i, CUInt(&H1000& * (1 - fCheck)), LVIS_STATEIMAGEMASK)
    30. End Sub
    31. <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
    32. Public Shared Function FindWindowEx(ByVal parentHandle As IntPtr, ByVal childAfter As IntPtr, ByVal lclassName As String, ByVal windowTitle As String) As IntPtr
    33. End Function
    34. <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
    35. Private Shared Function SendMessageA(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
    36. End Function
    37. End Class
    38. Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
    39. Dim p As Process = System.Diagnostics.Process.GetProcessesByName("OBS")(0)
    40. Dim notepadHwnd As IntPtr = p.MainWindowHandle
    41. Dim editHwnd2 As IntPtr = Win32.FindWindowEx(notepadHwnd, IntPtr.Zero, "SysListView32", Nothing)
    42. Win32.ListView_SetCheckState(editHwnd2, -1, 1)
    43. End Sub

    Gelöschter Benutzer schrieb:

    Jenen Thread habe ich gefunden
    diesen hier auch?
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!