Jump to content

Read ListBox from other process


toonboon
 Share

Recommended Posts

Hi,

I'm trying to get the current selection in a listbox from a gui which is from another process. So I've got the parent process with the GUI and the child process with the reading. Problem is I cant get the child to read the data =(

these are the two sources:

Parent:

#Include <GuiListView.au3>
$Debug_LV = False
$GUI = GUICreate("Parent GUI", 350, 550)
$UserList = GUICtrlCreateListView("Monkey Names", 8, 8, 164, 400)
$PassList = GUICtrlCreateListView("Food Types", 180, 8, 164, 400)
_GUICtrlListView_SetColumnWidth($Names, 0, 160)
_GUICtrlListView_SetColumnWidth($Food, 0, 160)
For $a = 65 To 125
    GUICtrlCreateListViewItem(Chr($a), $Names)
Next
For $a = 1 To 6
    GUICtrlCreateListViewItem($a, $Food)
Next
GUISetState()
$UserList = GUICtrlGetHandle($Names)
Run(@ComSpec & " /c " & "Child.exe " & GUICtrlGetHandle($Names), "", @SW_HIDE, 2)
_GUICtrlListView_SetItemSelected($Names, 0)
while 1
    $i = _GUICtrlListView_GetSelectedIndices($Names)
    ToolTip($i & "-" & _GUICtrlListView_GetItemText($Names, Number($i)), 0, 15)
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    sleep(100)
WEnd

Child:

#Include <GuiListView.au3>
#AutoIt3Wrapper_Run_Debug_Mode=y

If $CmdLine[0]=0 Then 
    $Handle = ClipGet()
Else
    $Handle = $CmdLine[1]
EndIf

while WinExists("Parent GUI")
    ToolTip("-" & _GUICtrlListView_GetSelectedIndices($Handle, False), 0, 0)
    sleep(100)
WEnd

[right]~What can I say, I'm a Simplistic person[/right]

Link to comment
Share on other sites

Are they part of the same script? If they aren't, that's going to be a problem.

Edited by Hawkwing

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Link to comment
Share on other sites

  • Moderators

Are they part of the same script? If they aren't, that's going to be a problem.

Why?

Anyway... This worked:

Main script (a random one grabbed from help file since you didn't provide a working example):

#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>

Opt('MustDeclareVars', 1)

$Debug_LV = False ; Check ClassName being passed to ListView functions, set to True and use a handle to another control to see it work

_Main()

Func _Main()
    Local $hListView
    
    GUICreate("ListView Set Item Text", 400, 300)
    $hListView = GUICtrlCreateListView("", 2, 2, 394, 268)
    GUISetState()

    ; Add columns
    _GUICtrlListView_AddColumn($hListView, "Items", 100)

    ; Add items
    _GUICtrlListView_AddItem($hListView, "Item 1")
    _GUICtrlListView_AddItem($hListView, "Item 2")
    _GUICtrlListView_AddItem($hListView, "Item 3")

    ; Set item 2 text
    _GUICtrlListView_SetItemText($hListView, 1, "New Item 2")
    MsgBox(4160, "Information", "Item 2 Text: " & _GUICtrlListView_GetItemText($hListView, 1))
    Run('"' & @ScriptDir & '\getlistviewtest.exe" ' & GUICtrlGetHandle($hListView))

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>_Main

Monitoring Exe (getlistviewtest.au3; compile as getlistviewtest.exe):

#Include <GuiListView.au3>

Global $s_hwnd = ClipGet()
If $cmdline[0] Then $s_hwnd = $cmdline[1]
Global $h_lvwnd = HWnd(Execute($s_hwnd))

While WinExists("ListView Set Item Text")
    Sleep(250)
    ToolTip("-" & _GUICtrlListView_GetSelectedIndices($h_lvwnd), 0, 0)
WEnd
Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Why?

Well, you learn something new every day. I thought that you could only get data from gui controls with the script that created the gui.

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...