Jump to content

Quick question about CommandSend() with combo.


Recommended Posts

If a combo box has Item1="<>" and Item2="<" and I use ControlCommand(.,.,.,"SelectString" , "<") to select Item2, ControlCommand selects Item1 instead ..... :whistle:

How can I go around that?

Here is my code:

$SELECT_STRING = "<"

$hwnd  = GUICreate( "testing" , 200 , 150 )
$combo = GUICtrlCreateCombo( "" , 20 , 20 , 100 , 200 )
GUICtrlSetData( -1 , "none|=|<>|<|>|regex" , "none" )

GUISetState()
$first = True
While( GUIGetMsg() <> -3 )
    If $first Then
        ControlCommand( $hwnd , "" , $combo , "SelectString" , $SELECT_STRING )
        If @error Then
            ConsoleWrite( "-- ControlCommand() failed   >Error: " & @error & @CRLF )
        Else
            ConsoleWrite( "ControlCommand() successful" & @CRLF )
        EndIf
        $first = False
    EndIf
WEnd

Note:

I can't change the GUI....

Thanks,

RK

Edited by rbhkamal

"When the power of love overcomes the love of power, the world will know peace"-Jimi Hendrix

Link to comment
Share on other sites

the SelectString option is obviously using some kind of regular expression..

in your case, the first instance of < that it is finding, is the <>, and so it is assuming that is the correct answer..

it isn't finding a literal string, it is finding any occurence of THAT string

to see what i mean, try this:

GUICtrlSetData( -1 , "none|=|<|<>|>|regex" , "none" )

i have moved the < to be before the <> , the ControlCommand will select this as it is the first occurrence in the combo box

Link to comment
Share on other sites

the SelectString option is obviously using some kind of regular expression..

in your case, the first instance of < that it is finding, is the <>, and so it is assuming that is the correct answer..

it isn't finding a literal string, it is finding any occurence of THAT string

to see what i mean, try this:

GUICtrlSetData( -1 , "none|=|<|<>|>|regex" , "none" )

i have moved the < to be before the <> , the ControlCommand will select this as it is the first occurrence in the combo box

Thanks, but do you know how to go around this without changing the GUI?

Regards,

RK

"When the power of love overcomes the love of power, the world will know peace"-Jimi Hendrix

Link to comment
Share on other sites

Found it!

$SELECT_STRING = "<"

$hwnd  = GUICreate( "testing" , 200 , 150 )
$combo = GUICtrlCreateCombo( "" , 20 , 20 , 100 , 200 )
GUICtrlSetData( -1 , "none|=|<>|<|>|regex" , "none" )
$comboHwnd = ControlGetHandle( $hwnd , "" , $combo )

GUISetState()
$first = True
While( GUIGetMsg() <> -3 )
    If $first Then
        ;$ret = ControlCommand( $hwnd , "" , $combo , "SETCURSEL" , $SELECT_STRING )
        $index = DllCall("user32.dll", "int", "SendMessage", "hwnd", $comboHwnd, "int", 0x158 , "int", 0 , "str", $SELECT_STRING  )
        $ret   = DllCall("user32.dll", "int", "SendMessage", "hwnd", $comboHwnd, "int", 0x14E , "int", $index[0] , "int", 0 )
        If @error Then
            ConsoleWrite( "-- ControlCommand() failed   >Error: " & @error & @CRLF )
        Else
            ConsoleWrite( "ControlCommand() successful , return: "&$ret[0] & @CRLF )
        EndIf
        $first = False
    EndIf
WEnd

Regards,

RK

"When the power of love overcomes the love of power, the world will know peace"-Jimi Hendrix

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