Jump to content

Gui List


Recommended Posts

Hey, how to make that ListBox to go down to last added entry. I am writting a program that will add info to that list box while it finishes some parts of program. The lines added will exceed number of lines visible in ListBox and scrolling down will be needed. It doesn't happen thou by default when new things are added so user can't realy see whats happening. I would like to add autoscrolling but couldn't find one for ListBox. Lemme know how i can make it happen.

$LogBox = GuiCtrlCreateList("", 5, 220, 440, 150,BitOR($WS_BORDER, $WS_VSCROLL, $LBS_NOTIFY,$LBS_DISABLENOSCROLL))
GuiCtrlSetData($LogBox,"Starting program.|")
GUICtrlSetData($LogBox,"Detecting number of unknown devices in system.|")
GuiCtrlSetData($LogBox,"Detecting number of all devices in system.|")
GUICtrlSetData($LogBox,"You clicked button No1|")
GUICtrlSetData($LogBox,"You clicked button No1|")
GUICtrlSetData($LogBox,"You clicked button No1|")
GUICtrlSetData($LogBox,"You clicked button No1|")
GUICtrlSetData($LogBox,"You clicked button No1|")
GUICtrlSetData($LogBox,"You clicked button No1|")
GUICtrlSetData($LogBox,"You clicked button No1|")
GUICtrlSetData($LogBox,"You clicked button No1|")
GUICtrlSetData($LogBox,"You clicked button No1|")
GUICtrlSetData($LogBox,"You clicked button No1|")
GUICtrlSetData($LogBox,"You clicked button No1|")
GUICtrlSetData($LogBox,"You clicked button No1|")
GUICtrlSetData($LogBox,"You clicked button No1|")
GUICtrlSetData($LogBox,"You clicked button No1|")

My little company: Evotec (PL version: Evotec)

Link to comment
Share on other sites

Well it's not quite what i wanted since to work i would have to add that line everytime i add something to ListBox. Also i had to use _GUICtrlListSelectIndex($LogBox, _GUICtrlListCount($LogBox)-1), otherwise it wasn't working. I would prefer some way that you set it like $autoscrolltolastline. So if anything is added to listbox it's shown right away.

My little company: Evotec (PL version: Evotec)

Link to comment
Share on other sites

  • Moderators

Well it's not quite what i wanted since to work i would have to add that line everytime i add something to ListBox. Also i had to use _GUICtrlListSelectIndex($LogBox, _GUICtrlListCount($LogBox)-1), otherwise it wasn't working. I would prefer some way that you set it like $autoscrolltolastline. So if anything is added to listbox it's shown right away.

Well, I guess you could cheat until someone comes up with a different idea:
#include <guiconstants.au3>
$Main = GUICreate('', 600)
$LogBox = GuiCtrlCreateList("", 5, 220, 440, 150,BitOR($WS_BORDER, $WS_VSCROLL, $LBS_NOTIFY, $LBS_DISABLENOSCROLL))
GuiCtrlSetData($LogBox,"Starting program.|")
GUICtrlSetData($LogBox,"Detecting number of unknown devices in system.|")
GuiCtrlSetData($LogBox,"Detecting number of all devices in system.|")
For $i = 1 To 14
    _CtrlSetDataAndPos($Main, $LogBox, "You clicked button No1|")
Next

GUISetState()
While 1
    If GUIGetMsg() = - 3 Then Exit
WEnd
    
Func _CtrlSetDataAndPos($i_Win, $i_Ctrl, $v_Data, $i_Pos = 1)
    GUICtrlSetData($i_Ctrl, $v_Data)
    If $i_Pos = 1 Then ControlSend($i_Win, '', $i_Ctrl, '{END}')
EndFunc

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

  • Moderators

@Smoke_N: hehe :think: Tnx, already solved. jackyyll idea seems to be simpler :(

No problem, I was looking at it when I guess ya'll were talking about it, I decided to just make it like it was the thing making the data... I've never had a need for it, but I think this would work for most control options.

Only difference between the 2 I think, Is that your calling 2 other functions within a function, I don't know how large your scripts are going to be or how much data you will be setting at one time, but that may cause an issue, as with the solution I was thinking of, was the quickest method I could think of. But I'm glad you have your issue worked out.

Edit:

After looking at the 2, I have to agree, that I think the DLLCall is more efficient here, and less likely to cause problems (like if you have a hotkey set for 'end' lol)... But I don't understand the "simpler" part:

The code your suggesting:

#include <guiconstants.au3>
#include <date.au3>
Global Const $LB_SETCURSEL = 0x186
Global Const $LB_GETCOUNT = 0x18B

$Main = GUICreate('', 600)
$LogBox = GuiCtrlCreateList("", 5, 220, 440, 150,BitOR($WS_BORDER, $WS_VSCROLL, $LBS_NOTIFY, $LBS_DISABLENOSCROLL))
GuiCtrlSetData($LogBox,"Starting program.|")
GUICtrlSetData($LogBox,"Detecting number of unknown devices in system.|")
GuiCtrlSetData($LogBox,"Detecting number of all devices in system.|")
For $i = 1 To 14
    _AddLineBox("You clicked button No1|")
Next

GUISetState()
While 1
    If GUIGetMsg() = - 3 Then Exit
WEnd

Func _AddLineBox($Text)
    GuiCtrlSetData($LogBox,"["& _NowTime(5) & "] - " & $Text & "|")
    _GUICtrlListSelectIndex($LogBox, _GUICtrlListCount($LogBox)-1)
EndFunc

Func _GUICtrlListSelectIndex($h_listbox, $i_index)
    If IsHWnd($h_listbox) Then
        Local $a_ret = DllCall("user32.dll", "int", "SendMessage", "hwnd", $h_listbox, "int", $LB_SETCURSEL, "int", $i_index, "int", 0)
        Return $a_ret[0]
    Else
        Return GUICtrlSendMsg($h_listbox, $LB_SETCURSEL, $i_index, 0)
    EndIf
EndFunc;==>_GUICtrlListSelectIndex

Func _GUICtrlListCount($h_listbox)
   If IsHWnd($h_listbox) Then
      Local $a_ret = DllCall("user32.dll", "int", "SendMessage", "hwnd", $h_listbox, "int", $LB_GETCOUNT, "int", 0, "int", 0)
      Return $a_ret[0]
   Else
      Return GUICtrlSendMsg($h_listbox, $LB_GETCOUNT, 0, 0)
   EndIf
EndFunc  ;==>_GUICtrlListCount

The code I was:

#include <guiconstants.au3>
#include <date.au3>
$Main = GUICreate('', 600)
$LogBox = GuiCtrlCreateList("", 5, 220, 440, 150,BitOR($WS_BORDER, $WS_VSCROLL, $LBS_NOTIFY, $LBS_DISABLENOSCROLL))
GuiCtrlSetData($LogBox,"Starting program.|")
GUICtrlSetData($LogBox,"Detecting number of unknown devices in system.|")
GuiCtrlSetData($LogBox,"Detecting number of all devices in system.|")

For $i = 1 To 14
    _CtrlSetDataAndPos($Main, $LogBox, "["& _NowTime(5) & "] - " & "You clicked button No1|")
Next

GUISetState()
While 1
    If GUIGetMsg() = - 3 Then Exit
WEnd
    
Func _CtrlSetDataAndPos($i_Win, $i_Ctrl, $v_Data, $i_Pos = 1)
    GUICtrlSetData($i_Ctrl, $v_Data)
    If $i_Pos = 1 Then ControlSend($i_Win, '', $i_Ctrl, '{END}')
EndFunc
Ironically, I actually think the 1st is faster, but I didn't do much testing... So as stated before, glad you found a viable solution.

After thinking about this, I wonder why none of us used GUICtrlSendMsg()

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

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...