Sign in to follow this  
Followers 0
BitRot

GUICtrlCreateInput and GUICtrlSetOnEvent : Same

6 posts in this topic

A small(?) problem : I'm using the GUI in event-mode, and have an input-control. Both pressing the "enter"-key and the GUI(/control ?) loosing focus generate an event (so far, so good), but both with GUI_CTRLID = 8 .

I do not see any way to, in the event-code, differ between the two causes (which is not-so-good).

Did I miss/overlook something ?

Share this post


Link to post
Share on other sites



A small(?) problem : I'm using the GUI in event-mode, and have an input-control. Both pressing the "enter"-key and the GUI(/control ?) loosing focus generate an event (so far, so good), but both with GUI_CTRLID = 8 .

I do not see any way to, in the event-code, differ between the two causes (which is not-so-good).

Did I miss/overlook something ?

Clicking or pressing on a control generates the same event related to the related GUI control.

Share this post


Link to post
Share on other sites

Clicking or pressing on a control generates the same event related to the related GUI control.

I'm sorry, but that was/is not my question/problem.

What I have a problem with is not being able to distinguish between a "loose focus" and an "enter pressed" -cause for an input-control.

Share this post


Link to post
Share on other sites

Would probably help if you posted some code to look at.

Here's something for you to look at:

#include <GuiConstants.au3>

Opt("GUIOnEventMode", 1)

Global Const $WM_COMMAND = 0x0111
Global Const $DebugIt = 1

GUICreate(" My GUI", 320, 120)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Terminate")

$input = GUICtrlCreateInput("", 10, 5, 300, 20)
GUICtrlSetOnEvent($input, "_MyInput")

$btn = GUICtrlCreateButton("Ok", 40, 75, 60, 20)
GUICtrlSetOnEvent($btn, "OKPressed")
GUICtrlSetState($btn, $GUI_DEFBUTTON)


GUISetState()
GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")

; Just idle around
While 1
    Sleep(10)
WEnd


; END

Func _Terminate()
    Exit
EndFunc   ;==>_Terminate

Func OKPressed()
    ;----------------------------------------------------------------------------------------------
    If $DebugIt Then _DebugPrint("OK Pressed" & @LF & "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle & " CtrlHandle=" & @GUI_CtrlHandle)
    ;----------------------------------------------------------------------------------------------
EndFunc   ;==>OKPressed

Func _MyInput()
    ;----------------------------------------------------------------------------------------------
    If $DebugIt Then _DebugPrint("_MyInput")
    ;----------------------------------------------------------------------------------------------
EndFunc   ;==>_MyInput

Func _Input_Changed()
    ;----------------------------------------------------------------------------------------------
    If $DebugIt Then _DebugPrint("Input Changed:" & GUICtrlRead($input))
    ;----------------------------------------------------------------------------------------------
EndFunc   ;==>_Input_Changed

Func _Input_LostFocus()
    ;----------------------------------------------------------------------------------------------
    If $DebugIt Then _DebugPrint("_Input_LostFocus")
    ;----------------------------------------------------------------------------------------------
EndFunc   ;==>_Input_LostFocus

Func _Input_GotFocus()
    ;----------------------------------------------------------------------------------------------
    If $DebugIt Then _DebugPrint("_Input_GotFocus")
    ;----------------------------------------------------------------------------------------------
EndFunc   ;==>_Input_GotFocus

Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam)
    Local $nNotifyCode = _HiWord($wParam)
    Local $nID = _LoWord($wParam)
    Local $hCtrl = $lParam
    Local Const $EN_CHANGE = 0x300
    Local Const $EN_KILLFOCUS = 0x200
    Local Const $EN_SETFOCUS = 0x100

    Switch $nID
        Case $input
            Switch $nNotifyCode
                Case $EN_CHANGE
                    _Input_Changed()
                Case $EN_SETFOCUS
                    _Input_GotFocus()
                Case $EN_KILLFOCUS
                    _Input_LostFocus()
                    
            EndSwitch
    EndSwitch
    ; Proceed the default Autoit3 internal message commands.
    ; You also can complete let the line out.
    ; !!! But only 'Return' (without any value) will not proceed
    ; the default Autoit3-message in the future !!!
    Return $GUI_RUNDEFMSG
EndFunc   ;==>MY_WM_COMMAND

Func _DebugPrint($s_text)
    $s_text = StringReplace($s_text, @LF, @LF & "-->")
    ConsoleWrite("!===========================================================" & @LF & _
            "+===========================================================" & @LF & _
            "-->" & $s_text & @LF & _
            "+===========================================================" & @LF)
EndFunc   ;==>_DebugPrint


Func _HiWord($x)
    Return BitShift($x, 16)
EndFunc   ;==>_HiWord

Func _LoWord($x)
    Return BitAND($x, 0xFFFF)
EndFunc   ;==>_LoWord

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Would probably help if you posted some code to look at.

Here's something for you to look at:

<snip code>

Thanks :)

As I'm quite a novice with AutoIt I would never have thought of registering the WM_COMMAND" message.

Now the only thing I need to do is to see how to incoorporate it in my own code. But that should not be too difficult, being able to look at the full example you gave me. :P

[edit]

P.s.

My code was quite basic :

$hInput = GUICtrlCreateInput ("", 10,  170, 480, 20)    ;, $WS_DISABLED) 
GUICtrlSetOnEvent($hInput, "MainInputSignalled")

....

;----------------------------
func MainInputSignalled()
    _DebugPrint ("MainInputSignalled:[ID="&@GUI_CTRLID&"][hWnd="&@GUI_WINHANDLE&"][hCtrl="&@GUI_CTRLHANDLE&"]"&@crlf)
...
EndFunc
Edited by BitRot

Share this post


Link to post
Share on other sites

Hi,

didnt want to start a new topic for this noob question :)

I have 3 buttons with 3 functions, all work fine until i press the button wich leads to a function wich is a loop and within this i cant capture the another buttons anymore. For example the "start" is a countdown function, and i cant stop it or quit at all.

Thanks for any help

Seszi

$Button1 = GUICtrlCreateButton("&Start", 166, 496, 43, 25, 0)
GUICtrlSetOnEvent(-1, "Start")
$Button2 = GUICtrlCreateButton("&Exit", 214, 496, 43, 25, 0)
GUICtrlSetOnEvent(-1, "Quit")
$Button3 = GUICtrlCreateButton("&Help", 264, 496, 43, 25, 0)
GUICtrlSetOnEvent(-1, "HELP")

Share this post


Link to post
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
Sign in to follow this  
Followers 0