Jump to content

Desktop Refresh


this
 Share

Recommended Posts

Hello

I am trying to loop through an array returned by winlist() while creating listview items and attaching context menus to them.

However, I have noticed that each time it does this, the desktop refreshes. I was wondering if this was normal.

The following is the snippet of code that creates the ListView items.

Func _getWindows()
    Local $itemText = ""
    If _GUICtrlListView_GetSelectedCount($listView)>0 Then
        $selected = _GUICtrlListView_GetSelectedIndices($listView,False)
        $itemText = _GUICtrlListView_GetItemText($listView,Int($selected),1)
    EndIf
    GUISetState(@SW_LOCK)
    _GUICtrlListView_DeleteAllItems($listView)
    $winList = WinList()
    For $x=1 To UBound($winList)-1
        If BitAND(WinGetState($winList[$x][1]),2) And $winList[$x][0]<>"" Then
            Local $lvi = GUICtrlCreateListViewItem(StringReplace($winList[$x][0],"|","")&"|"&$winList[$x][1],$listView)
            $contextmenu = GUICtrlCreateContextMenu($lvi)
                    GUICtrlCreateMenuItem("Set Opacity",$contextMenu)
                    GUICtrlSetOnEvent(-1,"_setOpacity")
                    GUICtrlCreateMenuItem("Bring To Front",$contextMenu)
                    GUICtrlSetOnEvent(-1,"_BringToFront")
                    GUICtrlCreateMenuItem("Kill Window",$contextMenu)
                    GUICtrlSetOnEvent(-1,"_KillWindow")
        EndIf
    Next
    GUISetState(@SW_UNLOCK)
    If $itemText <> "" Then
        For $x=0 To _GUICtrlListView_GetItemCount($listView)
            If _GUICtrlListView_GetItemText($listView,$x,1) = $itemText Then
                _GUICtrlListView_SetItemSelected($listView,$x)
            EndIf
        Next
    EndIf
EndFunc

Thanks in advance!

Edited by this
UDFsWinSineInOutResize () - Resize a window smoothly based on a sine curve.
Link to comment
Share on other sites

I'm trying to make a window opacity changer. It doesn't refresh reliably, just now and then.

Also, I've noticed that some other things flicker as well, such as an open notepad window.

Not sure if it's just my box.

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>

Opt("GUIOnEventMode",1)

$mainGUI = GUICreate("Opacity Changer",350,300)
    GUISetOnEvent($GUI_EVENT_CLOSE,"_exit")
    
$listView = GUICtrlCreateListView("Title|Handle",5,0,340,240,-1)
    GUICtrlSetBkColor(-1,$GUI_BKCOLOR_LV_ALTERNATE)
    _GUICtrlListView_SetColumnWidth($listView, 0, 160)
    _GUICtrlListView_SetColumnWidth($listView, 1, 160)


GUISetState(@SW_SHOW)

While 1
    Sleep(1000)
    _getWindows()
WEnd

Func _getWindows()
    Local $itemText = ""
    If _GUICtrlListView_GetSelectedCount($listView)>0 Then
        $selected = _GUICtrlListView_GetSelectedIndices($listView,False)
        $itemText = _GUICtrlListView_GetItemText($listView,Int($selected),1)
    EndIf
    GUISetState(@SW_LOCK)
    _GUICtrlListView_DeleteAllItems($listView)
    $winList = WinList()
    For $x=1 To UBound($winList)-1
        If BitAND(WinGetState($winList[$x][1]),2) And $winList[$x][0]<>"" Then
            ;_CreateMenu(GUICtrlCreateListViewItem(StringReplace($winList[$x][0],"|","")&"|"&$winList[$x][1],$listView))
            Local $lvi = GUICtrlCreateListViewItem(StringReplace($winList[$x][0],"|","")&"|"&$winList[$x][1],$listView)
            $contextmenu = GUICtrlCreateContextMenu($lvi)
                    GUICtrlCreateMenuItem("Set Opacity",$contextMenu)
                    GUICtrlCreateMenuItem("Bring To Front",$contextMenu)
        EndIf
    Next
    GUISetState(@SW_UNLOCK)
    If $itemText <> "" Then
        For $x=0 To _GUICtrlListView_GetItemCount($listView)
            If _GUICtrlListView_GetItemText($listView,$x,1) = $itemText Then
                _GUICtrlListView_SetItemSelected($listView,$x)
            EndIf
        Next
    EndIf
    $winList = ""
EndFunc

Func _exit()
    GUIDelete($mainGUI)
    Exit
EndFunc
UDFsWinSineInOutResize () - Resize a window smoothly based on a sine curve.
Link to comment
Share on other sites

Hi,

I haven't bothered with the context menu on the listview items as I'm sure you don't want me to write a script for you. :)

But what the example does is update a listview with items almost in realtime.

In other words you open or close a window in the listview will show it..

If a window title changes then the listview will update the title. eg: web browser changing pages changes the title.

The window Title column in the listview auto sizes to accommodate new or changed titles.

If an item in the list is selected it stays selected till the item is not there :lmao:

It does this without excess fickering or cpu usage.

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)

Global $aFilter = StringSplit("|Program Manager|Start Menu", "|")
Global $hGui, $LV, $sHwnd = ''

$hGui = GUICreate("List of windows", 600, 300, -1, -1, -1, $WS_EX_TOPMOST)
GUISetOnEvent($GUI_EVENT_CLOSE, "Event", $hGui)
$LV = GUICtrlCreateListView("Title|Handle", 5, 5, 590, 290)
GUISetState(@SW_SHOW, $hGui)

AdlibEnable("_getWindows", 250)

While 1
    Sleep(100)
WEnd

Func Event()
    Switch @GUI_CtrlId
        Case $GUI_EVENT_CLOSE
            AdlibDisable()
            Exit
    EndSwitch
EndFunc

Func _getWindows()
    Local $aWL = WinList()
    For $x=1 To $aWL[0][0]
        If BitAND(WinGetState($aWL[$x][1]), 2) And $aWL[$x][0] <> Filter($aWL[$x][0]) Then
            If Not StringInStr($sHwnd, $aWL[$x][1]) Then
                $sHwnd &=  $aWL[$x][1] & "|"
                GUICtrlCreateListViewItem(StringReplace($aWL[$x][0], "|","") & "|" & $aWL[$x][1], $LV)
                _GUICtrlListView_SetColumnWidth($LV, 0, $LVSCW_AUTOSIZE)
            ElseIf StringInStr($sHwnd, $aWL[$x][1]) Then
                Local $Check = _GUICtrlListView_FindInText($LV, $aWL[$x][1])
                If _GUICtrlListView_GetItemText($LV, $Check) <> $aWL[$x][0] Then 
                    _GUICtrlListView_SetItemText($LV, $Check, $aWL[$x][0])
                    _GUICtrlListView_SetColumnWidth($LV, 0, $LVSCW_AUTOSIZE)
                EndIf   
            EndIf
        EndIf
    Next
    For $h = 0 To _GUICtrlListView_GetItemCount($LV) -1
        Local $LVI_Hwnd = _GUICtrlListView_GetItemText($LV, $h, 1)
        If StringInStr($sHwnd, $LVI_Hwnd) And Not WinExists(HWnd($LVI_Hwnd)) Then 
            _GUICtrlListView_DeleteItem($LV, $h)
            $sHwnd = StringReplace($sHwnd, $LVI_Hwnd & "|", "")
            _GUICtrlListView_SetColumnWidth($LV, 0, $LVSCW_AUTOSIZE)
        EndIf
    Next
EndFunc

Func Filter($sTitle)
    For $i = 1 To $aFilter[0]
        If $sTitle = $aFilter[$i] Then Return $sTitle
    Next
    Return $sTitle & "1"
EndFunc

Cheers

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