Jump to content

AdlibEnable() Not functioning properly...


Recommended Posts

Alrighty,

So I've got this little app that moves windows around for me and I'm trying to keep a list of certain windows to look for for my layouts. I've got it working, but when I tried to add a little debug window that would show me what windows are active, it just craps out on me. I'm using AdlibEnable() to check for new windows and/or non-existant windows and update the list appropriately. The goofy part is the _CheckForNewWindows() function is called by AdlibEnable(), but the _ClearDeadWindows() function is NEVER called... Why??? Here's my code:

#include <GuiConstants.au3>

Opt("MouseCoordMode",1)     ;By screen
Opt("WinTitleMatchMode",3)  ;Exact Match

AdlibEnable("_ClearDeadWindows",1000)
AdlibEnable("_CheckForNewWindows",3000)

HotKeySet("{F9}","_LayoutOne")
HotKeySet("{F10}","_LayoutTwo")
HotKeySet("{F11}","_LayoutThree")

Global $MAX_WINDOWS = 3
Global $MAX_PRESETS = 3

Global $a_Windows[$MAX_WINDOWS] = [0,0,0]

Global $a_WindowPreset[$MAX_PRESETS][4]
;Preset for window 1 (1288x852)
$a_WindowPreset[0][0] = 0       ;Xpos
$a_WindowPreset[0][1] = 0       ;Ypos
$a_WindowPreset[0][2] = 1288    ;Width
$a_WindowPreset[0][3] = 768     ;Height
;Preset for window 2 (644x256)
$a_WindowPreset[1][0] = 0
$a_WindowPreset[1][1] = 768
$a_WindowPreset[1][2] = 640
$a_WindowPreset[1][3] = 256
;Preset for window 3 (644x256)
$a_WindowPreset[2][0] = 640
$a_WindowPreset[2][1] = 768
$a_WindowPreset[2][2] = 640
$a_WindowPreset[2][3] = 256

$GUI = GUICreate("Layout Manager",640,256)
$lst_Windows = GUICtrlCreateList("",0,0,640,265)
GUISetState(@SW_SHOW)

While 1
    If (GUIGetMsg() == $GUI_EVENT_CLOSE) Then Exit
WEnd

Func _SetWindowToPreset($Window,$Preset)
    If (Not WinExists($a_Windows[$Window])) Then
        Return
    EndIf
    
    WinMove($a_Windows[$Window], "",$a_WindowPreset[$Preset][0],$a_WindowPreset[$Preset][1],$a_WindowPreset[$Preset][2],$a_WindowPreset[$Preset][3])
EndFunc

Func _LayoutOne()
    _SetWindowToPreset(0,0)
    _SetWindowToPreset(1,1)
    _SetWindowToPreset(2,2) 
EndFunc

Func _LayoutTwo()
    _SetWindowToPreset(1,0)
    _SetWindowToPreset(0,1)
    _SetWindowToPreset(2,2) 
EndFunc

Func _LayoutThree()
    _SetWindowToPreset(2,0)
    _SetWindowToPreset(1,1)
    _SetWindowToPreset(0,2)
EndFunc

Func _IsWindowInList($hWnd)
    Local $iter_Windows
    For $iter_Windows = 0 To $MAX_WINDOWS-1
        If ($a_Windows[$iter_Windows] == $hWnd) Then Return True
    Next ;End MAX_WINDOWS
    Return False
EndFunc

Func _CheckForNewWindows()
    Local $iter_WList = 0, $iter_Windows = 0
    
    ;Check for new windows:
    $Window_List = WinList("Wordpad")
    For $iter_WList = 1 To $Window_List[0][0]
        For $iter_Windows = 0 To $MAX_WINDOWS-1         
            If (_IsWindowInList($Window_List[$iter_WList][1])) Then ExitLoop
            
            ;Add new window into our list
            If (Not $a_Windows[$iter_Windows]) Then
                $a_Windows[$iter_Windows] = $Window_List[$iter_WList][1]    ;Handle
                GUICtrlSetData($lst_Windows,WinGetTitle($a_Windows[$iter_Windows]) & " (" & $a_Windows[$iter_Windows] & ")|")
                Return
            EndIf
        Next ; End MAX_WINDOWS
    Next ;End Window_List
EndFunc

Func _ClearDeadWindows()
    MsgBox(0,"ClearDeadWindows","Called.")
    Local $iter_Windows
    GUICtrlSetData($lst_Windows,"")
     For $iter_Windows = 0 To $MAX_WINDOWS-1
        If (WinExists($a_Windows[$iter_Windows])) Then
            GUICtrlSetData($lst_Windows,WinGetTitle($a_Windows[$iter_Windows]) & " (" & $a_Windows[$iter_Windows] & ")|")
        Else
            $a_Windows[$iter_Windows] = 0
        EndIf
    Next ;End MAX_WINDOWS
EndFunc

As you can see, I added a MsgBox to _ClearDeadWindows() and it never pops up. Am I missing something?

Just in case this is a computer specific problem, here's what I'm running:

Windows XP Professional 64-Bit SP2

AMD Athlon 64 FX-60

8GB Ram

AutoIt 3.2.10.0

SciTE 1.75

-CMR

Edited by CodeMaster Rapture
Link to comment
Share on other sites

Alrighty,

So I've got this little app that moves windows around for me and I'm trying to keep a list of certain windows to look for for my layouts. I've got it working, but when I tried to add a little debug window that would show me what windows are active, it just craps out on me. I'm using AdlibEnable() to check for new windows and/or non-existant windows and update the list appropriately. The goofy part is the _CheckForNewWindows() function is called by AdlibEnable(), but the _ClearDeadWindows() function is NEVER called... Why??? Here's my code:

#include <GuiConstants.au3>

Opt("MouseCoordMode",1)     ;By screen
Opt("WinTitleMatchMode",3)  ;Exact Match

AdlibEnable("_ClearDeadWindows",1000)
AdlibEnable("_CheckForNewWindows",3000)

HotKeySet("{F9}","_LayoutOne")
HotKeySet("{F10}","_LayoutTwo")
HotKeySet("{F11}","_LayoutThree")

Global $MAX_WINDOWS = 3
Global $MAX_PRESETS = 3

Global $a_Windows[$MAX_WINDOWS] = [0,0,0]

Global $a_WindowPreset[$MAX_PRESETS][4]
;Preset for window 1 (1288x852)
$a_WindowPreset[0][0] = 0       ;Xpos
$a_WindowPreset[0][1] = 0       ;Ypos
$a_WindowPreset[0][2] = 1288    ;Width
$a_WindowPreset[0][3] = 768     ;Height
;Preset for window 2 (644x256)
$a_WindowPreset[1][0] = 0
$a_WindowPreset[1][1] = 768
$a_WindowPreset[1][2] = 640
$a_WindowPreset[1][3] = 256
;Preset for window 3 (644x256)
$a_WindowPreset[2][0] = 640
$a_WindowPreset[2][1] = 768
$a_WindowPreset[2][2] = 640
$a_WindowPreset[2][3] = 256

$GUI = GUICreate("Layout Manager",640,256)
$lst_Windows = GUICtrlCreateList("",0,0,640,265)
GUISetState(@SW_SHOW)

While 1
    If (GUIGetMsg() == $GUI_EVENT_CLOSE) Then Exit
WEnd

Func _SetWindowToPreset($Window,$Preset)
    If (Not WinExists($a_Windows[$Window])) Then
        Return
    EndIf
    
    WinMove($a_Windows[$Window], "",$a_WindowPreset[$Preset][0],$a_WindowPreset[$Preset][1],$a_WindowPreset[$Preset][2],$a_WindowPreset[$Preset][3])
EndFunc

Func _LayoutOne()
    _SetWindowToPreset(0,0)
    _SetWindowToPreset(1,1)
    _SetWindowToPreset(2,2) 
EndFunc

Func _LayoutTwo()
    _SetWindowToPreset(1,0)
    _SetWindowToPreset(0,1)
    _SetWindowToPreset(2,2) 
EndFunc

Func _LayoutThree()
    _SetWindowToPreset(2,0)
    _SetWindowToPreset(1,1)
    _SetWindowToPreset(0,2)
EndFunc

Func _IsWindowInList($hWnd)
    Local $iter_Windows
    For $iter_Windows = 0 To $MAX_WINDOWS-1
        If ($a_Windows[$iter_Windows] == $hWnd) Then Return True
    Next ;End MAX_WINDOWS
    Return False
EndFunc

Func _CheckForNewWindows()
    Local $iter_WList = 0, $iter_Windows = 0
    
    ;Check for new windows:
    $Window_List = WinList("Wordpad")
    For $iter_WList = 1 To $Window_List[0][0]
        For $iter_Windows = 0 To $MAX_WINDOWS-1         
            If (_IsWindowInList($Window_List[$iter_WList][1])) Then ExitLoop
            
            ;Add new window into our list
            If (Not $a_Windows[$iter_Windows]) Then
                $a_Windows[$iter_Windows] = $Window_List[$iter_WList][1]    ;Handle
                GUICtrlSetData($lst_Windows,WinGetTitle($a_Windows[$iter_Windows]) & " (" & $a_Windows[$iter_Windows] & ")|")
                Return
            EndIf
        Next ; End MAX_WINDOWS
    Next ;End Window_List
EndFunc

Func _ClearDeadWindows()
    MsgBox(0,"ClearDeadWindows","Called.")
    Local $iter_Windows
    GUICtrlSetData($lst_Windows,"")
     For $iter_Windows = 0 To $MAX_WINDOWS-1
        If (WinExists($a_Windows[$iter_Windows])) Then
            GUICtrlSetData($lst_Windows,WinGetTitle($a_Windows[$iter_Windows]) & " (" & $a_Windows[$iter_Windows] & ")|")
        Else
            $a_Windows[$iter_Windows] = 0
        EndIf
    Next ;End MAX_WINDOWS
EndFunc

As you can see, I added a MsgBox to _ClearDeadWindows() and it never pops up. Am I missing something?

Just in case this is a computer specific problem, here's what I'm running:

Windows XP Professional 64-Bit SP2

AMD Athlon 64 FX-60

8GB Ram

AutoIt 3.2.10.0

SciTE 1.75

-CMR

You can only have 1 function for AdlibEnable. As soon as you specify one function any previous function is replaced. To have more than one function you simply need something like this

AdlibEnable("_ClearDeadWindows",1000)
Global $dw=0


Func _ClearDeadWindows()
        
    MsgBox(0,"ClearDeadWindows","Called.")
    Local $iter_Windows
    GUICtrlSetData($lst_Windows,"")
     For $iter_Windows = 0 To $MAX_WINDOWS-1
        If (WinExists($a_Windows[$iter_Windows])) Then
            GUICtrlSetData($lst_Windows,WinGetTitle($a_Windows[$iter_Windows]) & " (" & $a_Windows[$iter_Windows] & ")|")
        Else
            $a_Windows[$iter_Windows] = 0
        EndIf
    Next;End MAX_WINDOWS

      $dw += 1
      if $dw = 3 then
        _CheckForNewWindows()
        $dw = 0
      endif
EndFunc
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
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...