Jump to content

Problem with ComboBox using EventMode


Recommended Posts

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.

#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)
Link to comment
Share on other sites

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)
Link to comment
Share on other sites

I have looked it over and tried alternate tests. It seems the control events are not working.

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

Link to comment
Share on other sites

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)
Link to comment
Share on other sites

  • Moderators

Had a similar issue, these links are courtesy of CyberSlug. Hope they help:

http://www.autoitscript.com/forum/index.php?showtopic=8842

and

http://www.autoitscript.com/forum/index.ph...wtopic=9303&hl=

I had to use the 2 together

Ron

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.

Link to comment
Share on other sites

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.

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

<{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 :):D:D:huh::(

#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

Link to comment
Share on other sites

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.
Link to comment
Share on other sites

Yee Ha :D 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)
Link to comment
Share on other sites

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.

#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 by Kerberuz

Kerby

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