igmeou Posted March 9, 2005 Posted March 9, 2005 Hi, I'm trying to write a script that will change to a selected window title in a combobox that list all the visible windows available. But I can't get the selection to be directed to my function so that I could make that selected window title active. expandcollapse popup#include <GUIConstants.au3> #include <Array.au3> Opt("GUIOnEventMode", 1) ; Change to OnEvent mode $mainwindow = GUICreate("Window Selecter",200,20,760,0) GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") WinSetOnTop($mainwindow, "", 1) $var = WinList() $combo = GUICtrlCreateCombo (WinGetTitle($mainwindow), 0,0); create first item GUICtrlSetData($combo,itemList($var)) GUISetOnEvent($combo, "SwitchWindow") GUISetState () ; Run the GUI until the dialog is closed While 1 Sleep(1000) Wend Func itemList(ByRef $array) Dim $str For $i = 1 to $var[0][0] If $var[$i][0] <> "" AND IsVisible($var[$i][1]) Then $str = $str & $var[$i][0] & "|" EndIf Next $str = StringTrimRight($str, 1) Return $str EndFunc Func IsVisible($handle) If BitAnd( WinGetState($handle), 2 ) Then Return 1 Else Return 0 EndIf EndFunc Func SwitchWindow() WinActivate(GUICtrlRead($combo)) EndFunc Func CLOSEClicked() Exit EndFunc Can someone please help me through this problem. Thanks in advance. [font="Arial"]Thanks[/font]If @error = me Then $sorry Else Do $clarifyMe Until $meClear EndIF MsgBox(0,"Special Message!","Special Thanks to " & $allHadReplied,$Forever)
igmeou Posted March 10, 2005 Author Posted March 10, 2005 Can anyone help me please. Is it anything to do with my coding? [font="Arial"]Thanks[/font]If @error = me Then $sorry Else Do $clarifyMe Until $meClear EndIF MsgBox(0,"Special Message!","Special Thanks to " & $allHadReplied,$Forever)
jdickens Posted March 10, 2005 Posted March 10, 2005 I have looked it over and tried alternate tests. It seems the control events are not working. expandcollapse popup#include <GUIConstants.au3> #include <Array.au3> Opt("GUIOnEventMode", 1); Change to OnEvent mode $mainwindow = GUICreate("Window Selecter",200,50,760,0) GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") WinSetOnTop($mainwindow, "", 1) $var = WinList() $combo = GUICtrlCreateCombo (WinGetTitle($mainwindow), 0,0); create first item $testcheck = GUICtrlCreateCheckbox ("test",0,21) ;GUISetOnEvent($combo, "testme") GUISetOnEvent($testcheck, "testme") ;GUISetOnEvent($GUI_EVENT_PRIMARYUP, "testme") GUICtrlSetData($combo,itemList($var)) GUISetState () $SelectionOWin = "" ; Run the GUI until the dialog is closed While 1 Sleep(1000) Wend Func itemList(ByRef $array) Dim $str For $i = 1 to $var[0][0] If $var[$i][0] <> "" AND IsVisible($var[$i][1]) Then $str = $str & $var[$i][0] & "|" EndIf Next $str = StringTrimRight($str, 1) Return $str EndFunc Func IsVisible($handle) If BitAnd( WinGetState($handle), 2 ) Then Return 1 Else Return 0 EndIf EndFunc Func testme() MsgBox(0, "", "triggered") if $SelectionOWin <> GUICtrlRead($combo) Then if WinExists(GUICtrlRead($combo)) Then WinActivate(GUICtrlRead($combo)) $SelectionOWin = (GUICtrlRead($combo)) EndIf EndIf EndFunc Func CLOSEClicked() MsgBox(0, "Closed", "Close event") Exit EndFunc J If I am too verbose, just say so. You don't need to run on and on.
igmeou Posted March 10, 2005 Author Posted March 10, 2005 Thanks jdickens, for spending the time looking through. I'm wondering is this a bug or my coding is having a problem. [font="Arial"]Thanks[/font]If @error = me Then $sorry Else Do $clarifyMe Until $meClear EndIF MsgBox(0,"Special Message!","Special Thanks to " & $allHadReplied,$Forever)
Moderators SmOke_N Posted March 10, 2005 Moderators Posted March 10, 2005 Had a similar issue, these links are courtesy of CyberSlug. Hope they help:http://www.autoitscript.com/forum/index.php?showtopic=8842andhttp://www.autoitscript.com/forum/index.ph...wtopic=9303&hl=I had to use the 2 togetherRon 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.
Holger Posted March 10, 2005 Posted March 10, 2005 Do you think GUISetOnEvent is for using on a _control_ or could it be just GUICtrlSetOnEvent ? Old project:GUI/Tray menu with icons and colors Other old stuff:IconFileScanner, TriState/ThreeState GUI TreeView, GUI ContextMenu created out of a TreeView
Kerberuz Posted March 10, 2005 Posted March 10, 2005 Hi,I'm trying to write a script that will change to a selected window title in a combobox that list all the visible windows available.But I can't get the selection to be directed to my function so that I could make that selected window title active.expandcollapse popup#include <GUIConstants.au3> #include <Array.au3> Opt("GUIOnEventMode", 1); Change to OnEvent mode $mainwindow = GUICreate("Window Selecter",200,20,760,0) GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") WinSetOnTop($mainwindow, "", 1) $var = WinList() $combo = GUICtrlCreateCombo (WinGetTitle($mainwindow), 0,0); create first item GUICtrlSetData($combo,itemList($var)) GUISetOnEvent($combo, "SwitchWindow") GUISetState () ; Run the GUI until the dialog is closed While 1 Sleep(1000) Wend Func itemList(ByRef $array) Dim $str For $i = 1 to $var[0][0] If $var[$i][0] <> "" AND IsVisible($var[$i][1]) Then $str = $str & $var[$i][0] & "|" EndIf Next $str = StringTrimRight($str, 1) Return $str EndFunc Func IsVisible($handle) If BitAnd( WinGetState($handle), 2 ) Then Return 1 Else Return 0 EndIf EndFunc Func SwitchWindow() WinActivate(GUICtrlRead($combo)) EndFunc Func CLOSEClicked() Exit EndFuncCan someone please help me through this problem.Thanks in advance.<{POST_SNAPBACK}>Your code looks great, I played with it and changed it only slightly and I believe it now has the desired effect. I have no clue why it wouldn't work as you had it. I guess you could report it as a bug see if they can get to the bottom of the issue.ronsrules seems to have the same problem, but I never got his code to work the way I thought it should.GL expandcollapse popup#include <GUIConstants.au3> #include <Array.au3> $mainwindow = GUICreate("Window Selecter", 200, 20, 760, 0) GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") WinSetOnTop($mainwindow, "", 1) $var = WinList() $combo = GUICtrlCreateCombo(WinGetTitle($mainwindow), 0, 0); create first item GUICtrlSetData($combo, itemList($var)) GUISetOnEvent($combo, "SwitchWindow") GUISetState() ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE CLOSEClicked() Case $msg = $combo SwitchWindow() EndSelect WEnd Func itemList(ByRef $array) Dim $str For $i = 1 To $var[0][0] If $var[$i][0] <> "" And IsVisible($var[$i][1]) Then $str = $str & $var[$i][0] & "|" EndIf Next $str = StringTrimRight($str, 1) Return $str EndFunc ;==>itemList Func IsVisible($handle) If BitAND( WinGetState($handle), 2) Then Return 1 Else Return 0 EndIf EndFunc ;==>IsVisible Func SwitchWindow() WinActivate(GUICtrlRead($combo)) EndFunc ;==>SwitchWindow Func CLOSEClicked() Exit EndFunc ;==>CLOSEClicked Kerby
therks Posted March 10, 2005 Posted March 10, 2005 Do you think GUISetOnEvent is for using on a _control_ or could it be just GUICtrlSetOnEvent ? <{POST_SNAPBACK}>Nobody seems to have noticed your post here Holger.Even Kerberuz's post doesn't work the way it's supposed to. But, if you take his script, and change the line:GUISetOnEvent($combo, "SwitchWindow")To this:GUICtrlSetOnEvent($combo, "SwitchWindow")It works perfectly.Could perhaps be the fault of the Help file, as the description for both functions is similar:Defines a user-defined function to be called when a control is clicked.RIGHT!Defines a user function to be called when a control is clicked.WRONG! This defines a user function to be called when a GUI SPECIAL EVENT happens (like CLOSE, MINIMIZE, RESTORE, MOUSEMOVE). That's it. It's not for a control. My AutoIt Stuff | My Github
igmeou Posted March 11, 2005 Author Posted March 11, 2005 Yee Ha Thanks guys. It's working! working! So can I conclude that: GUISetOnEvent ------------------ - for handling GUI windows events only. Eg. $GUI_EVENT_CLOSE, $GUI_EVENT_MAXIMIZE, etc... GUICtrlSetOnEvent ---------------------- - for handling user define GUI controls only. Eg. Buttons, ComboBoxes, Menus, etc... [font="Arial"]Thanks[/font]If @error = me Then $sorry Else Do $clarifyMe Until $meClear EndIF MsgBox(0,"Special Message!","Special Thanks to " & $allHadReplied,$Forever)
Kerberuz Posted March 11, 2005 Posted March 11, 2005 (edited) Nobody seems to have noticed your post here Holger.Even Kerberuz's post doesn't work the way it's supposed to. But, if you take his script, and change the line:GUISetOnEvent($combo, "SwitchWindow")To this:GUICtrlSetOnEvent($combo, "SwitchWindow")It works perfectly.Could perhaps be the fault of the Help file, as the description for both functions is similar:RIGHT!Defines a user function to be called when a control is clicked.WRONG! This defines a user function to be called when a GUI SPECIAL EVENT happens (like CLOSE, MINIMIZE, RESTORE, MOUSEMOVE). That's it. It's not for a control.<{POST_SNAPBACK}>That is good to know, I'm still learning and I'm having a great time doing it. It's easy to over look something like that in the beginning. This is how I will get better in my eyes. I try to find someone with a problem and I play with their code to see if I can find/fix the problem. Also I added 3 more lines of code so that the Program Manager would not be included in the list since it's for the desktop icons and you will not be able to switch to the desktop. Well you can, but it would require some additional code.expandcollapse popup#include <GUIConstants.au3> #include <Array.au3> $mainwindow = GUICreate("Window Selecter", 200, 20, 760, 0) GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") WinSetOnTop($mainwindow, "", 1) $var = WinList() $combo = GUICtrlCreateCombo(WinGetTitle($mainwindow), 0, 0); create first item GUICtrlSetData($combo, itemList($var)) GUICtrlSetOnEvent($combo, "SwitchWindow") GUISetState() ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE CLOSEClicked() Case $msg = $combo SwitchWindow() EndSelect WEnd Func itemList(ByRef $array) Dim $str For $i = 1 To $var[0][0] If $var[$i][0] <> "" And IsVisible($var[$i][1]) Then If $var[$i][0] <> "Program Manager" Then $str = $str & $var[$i][0] & "|" EndIf EndIf Next $str = StringTrimRight($str, 1) Return $str EndFunc ;==>itemList Func IsVisible($handle) If BitAND( WinGetState($handle), 2) Then Return 1 Else Return 0 EndIf EndFunc ;==>IsVisible Func SwitchWindow() WinActivate(GUICtrlRead($combo)) EndFunc ;==>SwitchWindow Func CLOSEClicked() Exit EndFunc ;==>CLOSEClicked Edited March 11, 2005 by Kerberuz Kerby
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now