Jump to content

Need another set of eyes to look at this


Dampe
 Share

Recommended Posts

Everytime I close a window, this will continue to loop the _AddWindows() Function, my head is in a spin :S

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <GuiButton.au3>
#include <ButtonConstants.au3>
#include <StaticConstants.au3>
#include <Array.au3>

Local $WinBtns[1]
Local $BarWinList = WinList()
Local $DesktopMin = False

Opt("GUIOnEventMode", 1)

_Draw()

While 1
    
    Sleep(10)
    _CheckWindows()
    
WEnd

Func _CheckWindows()
    
    For $i = 1 To $BarWinList[0][0]
        
        If Not WinExists($BarWinList[$i][0]) Then
            For $i = 1 to UBound ($WinBtns) -1 Step 1
                GUICtrlDelete ($WinBtns[$i])
            Next
            $BarWinList = ""
            _AddWindows()
            ExitLoop
        EndIf

    Next
    
EndFunc  ;==>_CheckWindows


Func _Draw()
    
    $GUI = GUICreate("", @DesktopWidth, 30, 0, @DesktopHeight - 30, BitOR($WS_POPUP, $WS_BORDER))
    
;//Background
    GUISetBkColor(0xBB6655)
    
;//Time
    $GUILblTime = GUICtrlCreateLabel(@MDAY & "/" & @MON & "/" & @YEAR & " - " & @HOUR & ":" & @MIN, @DesktopWidth - 110, 8, 160, 15)
    GUICtrlSetColor(-1, 0xFFFFFF)
;GUICtrlSetFont (-1, -1, 800)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    
    $GUIBtnDesktop = GUICtrlCreateButton("", 7, 4, 22, 22, BitOR($BS_ICON, $BS_FLAT))
    GUICtrlSetImage(-1, "shell32.dll", 35, 0)
    
    _AddWindows()
    
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
    
    GUICtrlSetOnEvent($GUIBtnDesktop, "_GoToDesktop")
    
    
    GUISetState(@SW_SHOW)
    WinSetOnTop($GUI, "", 1)
    
EndFunc  ;==>_Draw

Func _GoToDesktop()
    
    If $DesktopMin = True Then
        WinMinimizeAllUndo()
        $DesktopMin = False
    Else
        WinMinimizeAll()
        $DesktopMin = True
    EndIf
    
EndFunc  ;==>_GoToDesktop

Func _Exit()
    Exit 0
EndFunc  ;==>_Exit

Func _WinClick()

    WinActivate(_GUICtrlButton_GetText(@GUI_CtrlId))

EndFunc  ;==>_WinClick

Func _AddWindows()
    
    $var = WinList()
    $Tcount = 1
    $BarWinList = ""
    
    For $i = 1 To $var[0][0]
        If $var[$i][0] <> "" And IsVisible($var[$i][1]) Then
        ;$var[$i][0]
            ReDim $WinBtns[UBound($WinBtns) + 1]
            $tText = StringLeft($var[$i][0], 20)
            $WinBtns[$Tcount] = GUICtrlCreateButton($tText, ($Tcount * 155) - 120, 2, 150, 25, $BS_FLAT)
            GUICtrlSetBkColor(-1, 0xFFDDAA)
            
            GUICtrlSetOnEvent($WinBtns[$Tcount], "_WinClick")
            $Tcount += 1
        EndIf
    Next
    
    $BarWinList = ""
    $BarWinList = WinList()
;

EndFunc  ;==>_AddWindows

Func IsVisible($handle)
    If BitAND(WinGetState($handle), 2) Then
        Return 1
    Else
        Return 0
    EndIf

EndFunc  ;==>IsVisible
Link to comment
Share on other sites

It might have something to do with the fact you're using $i for two things at the same time.

Func _CheckWindows()

For $i = 1 To $BarWinList[0][0]

If Not WinExists($BarWinList[$i][0]) Then

For $i = 1 to UBound ($WinBtns) -1 Step 1

GUICtrlDelete ($WinBtns[$i])

Next

$BarWinList = ""

_AddWindows()

ExitLoop

EndIf

Next

EndFunc ;==>_CheckWindows

Link to comment
Share on other sites

It might have something to do with the fact you're using $i for two things at the same time.

Func _CheckWindows()

For $i = 1 To $BarWinList[0][0]

If Not WinExists($BarWinList[$i][0]) Then

For $i = 1 to UBound ($WinBtns) -1 Step 1

GUICtrlDelete ($WinBtns[$i])

Next

$BarWinList = ""

_AddWindows()

ExitLoop

EndIf

Next

EndFunc ;==>_CheckWindows

I also agree with him. :)

[font="Arial Black"][u]zero57[/u][/font]

Link to comment
Share on other sites

when you say I'm using $i twice, can I resolve that issue by using for example:

for $i = 1 to 50 step 1
    for $x = 1 to 30 step 1
    next
next

or should I change the loop to a do / while?

I tried changing $i to $x but it's still doing the same problem.

Link to comment
Share on other sites

What I found out by debugging your application, is that this happens:

Checking hWnd SciTE interface
Checking hWnd TF_FloatingLangBar_WndTitle
Checking hWnd CiceroUIWndFrame
Checking hWnd 
Checking hWnd Start Menu
Checking hWnd 
Checking hWnd 
Checking hWnd 
Checking hWnd

As you can see it checks the name of the application. However, a name is not a very good identifier for a window, because a name changes. To get around this problem we use the window handle (or known as hWnd) which is a unique identifier for any window.

I did also change the two for loops. You shouldn't use the same name, because it gives unexpected results.

Here's the fixed application using window handles, instead of names.

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <GuiButton.au3>
#include <ButtonConstants.au3>
#include <StaticConstants.au3>
#include <Array.au3>

Dim $WinBtns[1]
Dim $BarWinList = WinList()
Dim $DesktopMin = False

Opt("GUIOnEventMode", 1)

_Draw()

While 1
    
    Sleep(10)
    _CheckWindows()
    
WEnd

Func _CheckWindows()
    
    For $i = 1 To $BarWinList[0][0]
        If Not WinExists($BarWinList[$i][1]) Then
            For $x = 1 to UBound ($WinBtns) -1 Step 1
                GUICtrlDelete ($WinBtns[$x])
            Next
            $BarWinList = ""
            _AddWindows()
            ExitLoop
        EndIf

    Next
    
EndFunc  ;==>_CheckWindows


Func _Draw()
    
    $GUI = GUICreate("", @DesktopWidth, 30, 0, @DesktopHeight - 30, BitOR($WS_POPUP, $WS_BORDER))
    
;//Background
    GUISetBkColor(0xBB6655)
    
;//Time
    $GUILblTime = GUICtrlCreateLabel(@MDAY & "/" & @MON & "/" & @YEAR & " - " & @HOUR & ":" & @MIN, @DesktopWidth - 110, 8, 160, 15)
    GUICtrlSetColor(-1, 0xFFFFFF)
;GUICtrlSetFont (-1, -1, 800)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    
    $GUIBtnDesktop = GUICtrlCreateButton("", 7, 4, 22, 22, BitOR($BS_ICON, $BS_FLAT))
    GUICtrlSetImage(-1, "shell32.dll", 35, 0)
    
    _AddWindows()
    
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
    
    GUICtrlSetOnEvent($GUIBtnDesktop, "_GoToDesktop")
    
    
    GUISetState(@SW_SHOW)
    WinSetOnTop($GUI, "", 1)
    
EndFunc  ;==>_Draw

Func _GoToDesktop()
    
    If $DesktopMin = True Then
        WinMinimizeAllUndo()
        $DesktopMin = False
    Else
        WinMinimizeAll()
        $DesktopMin = True
    EndIf
    
EndFunc  ;==>_GoToDesktop

Func _Exit()
    Exit 0
EndFunc  ;==>_Exit

Func _WinClick()

    WinActivate(_GUICtrlButton_GetText(@GUI_CtrlId))

EndFunc  ;==>_WinClick

Func _AddWindows()
    
    $var = WinList()
    $Tcount = 1
    $BarWinList = ""
    
    For $i = 1 To $var[0][0]
        If $var[$i][0] <> "" And IsVisible($var[$i][1]) Then
        ;$var[$i][0]
            ReDim $WinBtns[UBound($WinBtns) + 1]
            $tText = StringLeft($var[$i][0], 20)
            $WinBtns[$Tcount] = GUICtrlCreateButton($tText, ($Tcount * 155) - 120, 2, 150, 25, $BS_FLAT)
            GUICtrlSetBkColor(-1, 0xFFDDAA)
            
            GUICtrlSetOnEvent($WinBtns[$Tcount], "_WinClick")
            $Tcount += 1
        EndIf
    Next
    
    $BarWinList = ""
    $BarWinList = WinList()
;

EndFunc  ;==>_AddWindows

Func IsVisible($handle)
    If BitAND(WinGetState($handle), 2) Then
        Return 1
    Else
        Return 0
    EndIf

EndFunc  ;==>IsVisible
Edited by Manadar
Link to comment
Share on other sites

What I found out by debugging your application, is that this happens:

Checking hWnd SciTE interface
Checking hWnd TF_FloatingLangBar_WndTitle
Checking hWnd CiceroUIWndFrame
Checking hWnd 
Checking hWnd Start Menu
Checking hWnd 
Checking hWnd 
Checking hWnd 
Checking hWnd

As you can see it checks the name of the application. However, a name is not a very good identifier for a window, because a name changes. To get around this problem we use the window handle (or known as hWnd) which is a unique identifier for any window.

I did also change the two for loops. You shouldn't use the same name, because it gives unexpected results.

Here's the fixed application using window handles, instead of names.

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <GuiButton.au3>
#include <ButtonConstants.au3>
#include <StaticConstants.au3>
#include <Array.au3>

Dim $WinBtns[1]
Dim $BarWinList = WinList()
Dim $DesktopMin = False

Opt("GUIOnEventMode", 1)

_Draw()

While 1
    
    Sleep(10)
    _CheckWindows()
    
WEnd

Func _CheckWindows()
    
    For $i = 1 To $BarWinList[0][0]
        If Not WinExists($BarWinList[$i][1]) Then
            For $x = 1 to UBound ($WinBtns) -1 Step 1
                GUICtrlDelete ($WinBtns[$x])
            Next
            $BarWinList = ""
            _AddWindows()
            ExitLoop
        EndIf

    Next
    
EndFunc  ;==>_CheckWindows


Func _Draw()
    
    $GUI = GUICreate("", @DesktopWidth, 30, 0, @DesktopHeight - 30, BitOR($WS_POPUP, $WS_BORDER))
    
;//Background
    GUISetBkColor(0xBB6655)
    
;//Time
    $GUILblTime = GUICtrlCreateLabel(@MDAY & "/" & @MON & "/" & @YEAR & " - " & @HOUR & ":" & @MIN, @DesktopWidth - 110, 8, 160, 15)
    GUICtrlSetColor(-1, 0xFFFFFF)
;GUICtrlSetFont (-1, -1, 800)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    
    $GUIBtnDesktop = GUICtrlCreateButton("", 7, 4, 22, 22, BitOR($BS_ICON, $BS_FLAT))
    GUICtrlSetImage(-1, "shell32.dll", 35, 0)
    
    _AddWindows()
    
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
    
    GUICtrlSetOnEvent($GUIBtnDesktop, "_GoToDesktop")
    
    
    GUISetState(@SW_SHOW)
    WinSetOnTop($GUI, "", 1)
    
EndFunc  ;==>_Draw

Func _GoToDesktop()
    
    If $DesktopMin = True Then
        WinMinimizeAllUndo()
        $DesktopMin = False
    Else
        WinMinimizeAll()
        $DesktopMin = True
    EndIf
    
EndFunc  ;==>_GoToDesktop

Func _Exit()
    Exit 0
EndFunc  ;==>_Exit

Func _WinClick()

    WinActivate(_GUICtrlButton_GetText(@GUI_CtrlId))

EndFunc  ;==>_WinClick

Func _AddWindows()
    
    $var = WinList()
    $Tcount = 1
    $BarWinList = ""
    
    For $i = 1 To $var[0][0]
        If $var[$i][0] <> "" And IsVisible($var[$i][1]) Then
        ;$var[$i][0]
            ReDim $WinBtns[UBound($WinBtns) + 1]
            $tText = StringLeft($var[$i][0], 20)
            $WinBtns[$Tcount] = GUICtrlCreateButton($tText, ($Tcount * 155) - 120, 2, 150, 25, $BS_FLAT)
            GUICtrlSetBkColor(-1, 0xFFDDAA)
            
            GUICtrlSetOnEvent($WinBtns[$Tcount], "_WinClick")
            $Tcount += 1
        EndIf
    Next
    
    $BarWinList = ""
    $BarWinList = WinList()
;

EndFunc  ;==>_AddWindows

Func IsVisible($handle)
    If BitAND(WinGetState($handle), 2) Then
        Return 1
    Else
        Return 0
    EndIf

EndFunc  ;==>IsVisible

Problem solved.

Thanks a bunch Manadar :)

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