Jump to content

Button Calling function twice.


Recommended Posts

I have a button created as follows:

$client_login_btn = GUICtrlCreateButton("Login", $login_offset_width + 115, $login_offset_height + 195, 100, 22, BitOR($BS_DEFPUSHBUTTON, $BS_FLAT))

The offsets are just to make the button dynamic to the screen size.

Now when I try call my function in a normal GUIGetMsg loop, it seems to always call the function 2 times. And I only click it once.

While 1
    $nMSG = GUIGetMsg(0)
    Select
        Case $nMSG = $GUI_EVENT_CLOSE
            Exit
        Case _IsFocused($client_gui, $client_login_password)
            If GUICtrlRead($client_login_password) == "Password" Then
                GUICtrlSetData($client_login_password, "")
            EndIf
        Case _IsFocused($client_gui, $client_login_username)
            If GUICtrlRead($client_login_username) == "Username" Then
                GUICtrlSetData($client_login_username, "")
            EndIf
        Case $nMSG = $client_login_btn
            ;Remake the GUI to show the loading screen.
                GUICtrlSetImage($client_gui_bkg, "images\theme2.jpg")
                GUICtrlSetState($client_login_btn, $GUI_DISABLE + $GUI_HIDE)
                GUICtrlSetState($client_login_password, $GUI_DISABLE + $GUI_HIDE)
                GUICtrlSetState($client_login_username, $GUI_DISABLE + $GUI_HIDE)
                GUICtrlSetState($client_gui_title, $GUI_DISABLE + $GUI_HIDE)
                GUICtrlSetState($client_gui_welcome, $GUI_DISABLE + $GUI_HIDE)
                GUICtrlSetState($client_status_label, $GUI_SHOW)
                _Login(GUICtrlRead($client_login_username), GUICtrlRead($client_login_password), 1)
    EndSelect
WEnd

You may recognise the _Login func from my other topic. It is the same thing :)

Is there anything I'm doing wrong? I couldn't find a fix. Maybe I'm not using the right search terms...

Link to comment
Share on other sites

Hi! Mayb problem here?

Case _IsFocused($client_gui, $client_login_password)
            If GUICtrlRead($client_login_password) == "Password" Then
                GUICtrlSetData($client_login_password, "")
            EndIf
        Case _IsFocused($client_gui, $client_login_username)
            If GUICtrlRead($client_login_username) == "Username" Then
                GUICtrlSetData($client_login_username, "")
            EndIf
Link to comment
Share on other sites

I think your problem is

Case $nMSG = $client_login_btn

Should be

Case $client_login_btn

For example:

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $test
            func()
        Case $button
            func2()
EndSwitch
Wend
Edited by Distrophy
Link to comment
Share on other sites

Hi! Mayb problem here?

Case _IsFocused($client_gui, $client_login_password)
            If GUICtrlRead($client_login_password) == "Password" Then
                GUICtrlSetData($client_login_password, "")
            EndIf
        Case _IsFocused($client_gui, $client_login_username)
            If GUICtrlRead($client_login_username) == "Username" Then
                GUICtrlSetData($client_login_username, "")
            EndIf
I don't think so, as that just sets the data of the input to be blank if it is focused, and the contents == what they should.

I think your problem is

Case $nMSG = $client_login_btn

Should be

Case $client_login_btn

For example:

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $test
            func()
        Case $button
            func2()
EndSwitch
Wend
Wrong. Look up SELECT...Case...Case Else...EndSelect and Switch...Case...Case Else...EndSwitch. You will find thy are 2 different things... :)
Link to comment
Share on other sites

I've seen this problem with a message loop gui I finished back in December.

I placed $msg = 0 after the problematic function(s) called in the Switch / Case / EndSwitch statements.

I have only seen this in 3.2.8.1, haven't re-tested the script to confirm the problem without those $msg = 0 lines

or updated and tested the script in 3.2.10.0

what the problematic functions had in common was disabling/hiding several controls, specifically the buttons that were just clicked.

e.g. GUICtrlSetState($n4, $GUI_DISABLE + $GUI_HIDE)

the script had many Switch/Case and Select/Case statements in the loop

it may have to do with the control being disabled and after the message loop resumes the same button code is reused.

use a ConsoleWrite to monitor $nMsg

try commenting out this line in your script:

;GUICtrlSetState($client_login_btn, $GUI_DISABLE + $GUI_HIDE)

; Pseudocode

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $n4 ; Extract Button
            _Extract()
            $msg = 0
    EndSwitch
WEnd

I see fascists...

Link to comment
Share on other sites

Hmmmmmmm... *looks at version* That could be the reason. I'll update then get back to you :)

In a related problem, it looks like it was fixed back around this beta.

From the 3.2.10.0 changelog:

3.2.9.2 (30th September, 2007) (Beta)

- Fixed: Extra notification on colored button. (Thanks livewire)

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

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

I tried the reproducer in the above post in 3.2.8.1 (still have it on one of my machines)

very twitchy behaviour from the message queue!

I see fascists...

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