Jump to content

Two problems with a list control


Info
 Share

Recommended Posts

Hi,

here's my script:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$ListForm = GUICreate("Process List", 201, 185, 192, 124, -1, BitOR($WS_EX_TOOLWINDOW,$WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))
$ProcessListCtrl = GUICtrlCreateList("", 0, 0, 201, 136)
$Checkbox = GUICtrlCreateCheckbox("Auto refresh",2,141,75,15)
GUISetState()

$ProcessList = ProcessList()
GUICtrlSetState($ProcessListCtrl,$GUI_HIDE)
For $i = 1 To $ProcessList[0][0]
    GUICtrlSetData($ProcessListCtrl,$ProcessList[$i][0])
Next
GUICtrlSetState($ProcessListCtrl,$GUI_SHOW)

$timer = TimerInit();start timer
While 1
    If GUICtrlRead($Checkbox) = 1 Then ;if the checkbox is checked
        If StringIsInt(Int(TimerDiff($timer))/500) = 1 Then ;supposes to be every 0.5sec but it isn't
            GUICtrlSetData($ProcessListCtrl,"")
            $ProcessList = ProcessList()
            GUICtrlSetState($ProcessListCtrl,$GUI_HIDE)
            For $i = 1 To $ProcessList[0][0]
                GUICtrlSetData($ProcessListCtrl,$ProcessList[$i][0])
            Next
            GUICtrlSetState($ProcessListCtrl,$GUI_SHOW)
        EndIf
    EndIf
    Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
        GUIDelete()
        Exit
    EndSwitch
WEnd

My first problem is that the process list does not get updated every 500.

My second problem is that when it does get updated, the scroll bar goes upward and it's a bit annoying when I try to choose an item from the list.

Thanks! >_<

Edit:

By the way, is there a way to delete the the timer from the memory so the program will have less CPU usage?

Edited by Info
Link to comment
Share on other sites

I think that for the first problem you can use AdlibEnable()/_Timer_SetTimer() as they're more suited for such a task, you can test within the handler if the checkbox is checked.

For the second problem you can look the control from visualization updating by sending it $WM_SETREDRAW specifying False to unset the flag and reset it with true to allow visualization updating, it should make it faster. Make sure you're not destroying the list content because it's how it works. Try instead to update the items rather than deleting them or use behind-listview mechanism to show the visible updated listview while keep updating the behind-listview...

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