Sign in to follow this  
Followers 0
Realm

Need some assistance with Windows Command Messages

10 posts in this topic

#1 ·  Posted (edited)

What I am attempting to accomplish is that while editing an input, a button can be pushed to set some text in it. I tried working with Windows Messages to send the string to the input, unfortunately when the button is pushed, it loses focus of the input. Hoping someone has worked with something similar before and could give me some advice to point me in the correct direction to achieving this.

#include  $gui=GUICreate("My Gui") $input1 = GUICtrlCreateInput("First Example",10,10) $input2 = GUICtrlCreateInput("Second Example",10,30) $button1 = GUICtrlCreateButton("Insert 'Help'",20,50) $button2 = GUICtrlCreateButton("Insert 'Example'",130,50) GUISetState() While 1   $msg = GUIGetMsg()  IF $msg = $GUI_EVENT_CLOSE Then Exit WEnd Func MY_WM_COMMAND($hWnd, $Msg, $wParam, $lParam)     Local $nNotifyCode, $nID,$hCtrl, $winpos, $x, $y, $winpos   $nNotifyCode = BitShift($wParam, 16)    $nID = BitAND($wParam, 0x0000FFFF)  $hCtrl = $lParam    Switch $nID         Case $button1           Send("Help")        Case $button2           Send("Example")     EndSwitch   Return $GUI_RUNDEFMSG EndFunc ;==>MY_WM_COMMAND

Edited by Realm

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Try like this :

#include <GUIConstantsEx.au3>

$gui=GUICreate("My Gui")
$input1 = GUICtrlCreateInput("",10,10)
$input2 = GUICtrlCreateInput("",10,30)
$button1 = GUICtrlCreateButton("Insert 'Help",20,50)
$button2 = GUICtrlCreateButton("Insert 'Example",130,50)
GUISetState()

While 1
    $GUIMsg = GUIGetMsg()
    Switch $GUIMsg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $button1
            GUICtrlSetData ( $input1 , "Help" )
            GUICtrlSetState( $input1, $GUI_FOCUS )
        Case $button2
            GUICtrlSetData ($input2 , "Example" )
            GUICtrlSetState( $input2 , $GUI_FOCUS )
    EndSwitch
WEnd
Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Realm,

Or perhaps like this: ;)

#include <GUIConstantsEx.au3>
#include <WinAPI.au3>

$gui=GUICreate("My Gui")
$input1 = GUICtrlCreateInput("",10,10)
$hInput_1 = GUICtrlGetHandle(-1)
$input2 = GUICtrlCreateInput("",10,30)
$hInput_2 = GUICtrlGetHandle(-1)
$button1 = GUICtrlCreateButton("Insert 'Help",20,50)
$button2 = GUICtrlCreateButton("Insert 'Example",130,50)
GUISetState()

$hLastFocus = 0

While 1
    $GUIMsg = GUIGetMsg()
    Switch $GUIMsg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $button1
            GUICtrlSetState($hLastFocus, $GUI_FOCUS)
            Send("{END}")
            Send("Help")
        Case $button2
            GUICtrlSetState($hLastFocus, $GUI_FOCUS)
            Send("{END}")
            Send("Example")
    EndSwitch

    Switch _WinAPI_GetFocus()
        Case $hInput_1
            $hLastFocus = $input1
        Case $hInput_2
            $hLastFocus = $input2
    EndSwitch

WEnd

M23

Edit:

Of course, if you insist on using GUIRegisterMsg then you can also do it this way: :)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <WinAPI.au3>

$gui=GUICreate("My Gui")
$input1 = GUICtrlCreateInput("",10,10)
$hInput_1 = GUICtrlGetHandle(-1)
$input2 = GUICtrlCreateInput("",10,30)
$hInput_2 = GUICtrlGetHandle(-1)
$button1 = GUICtrlCreateButton("Insert 'Help",20,50)
$hButton_1 = GUICtrlGetHandle(-1)
$button2 = GUICtrlCreateButton("Insert 'Example",130,50)
$hButton_2 = GUICtrlGetHandle(-1)
GUISetState()

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

$hLastFocus = 0

While 1
    $GUIMsg = GUIGetMsg()
    Switch $GUIMsg
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch

    Switch _WinAPI_GetFocus()
        Case $hInput_1
            $hLastFocus = $input1
        Case $hInput_2
            $hLastFocus = $input2
    EndSwitch

WEnd

; React on a button click
Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    #forceref $hWnd, $Msg
    Switch BitShift($wParam, 16) ; Notify Code
        Case $BN_CLICKED
            Switch $lParam ; Ctrl
                Case $hButton_1
                    GUICtrlSetState($hLastFocus, $GUI_FOCUS)
                    Send("{END}")
                    Send("Help")
                Case $hButton_2
                    GUICtrlSetState($hLastFocus, $GUI_FOCUS)
                    Send("{END}")
                    Send("Example")
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

Enjoy! ;)

Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

@wakillon, Thanks for your reply, unfortunately your example, is not exactly what I was aiming for. the first button seems to lock to the first input, and the 2nd button to the 2nd input.

@Melba, your first example does almost the same thing as wakillon's, However, I was thinking that GUIRegisterMsg was best for the situation, for each button, should send to whatever input is active, and more than once in a rare occasion. However your second example is exactly the help I was looking for.

Thanks to both of you for giving me a moment of your time, to help me with this ;)


My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
Share on other sites

Realm,

Both my examples use exactly the same code to put the focus back into the last-active input - in neither case are the buttons linked to a specific input. That is the trick - not the use of GUIRegisterMsg. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Melba,

Sorry, I must of ran the wakillon's when I meant to runtest yours, I just tried again, and it works the same as your 2nd example.

code wise, it looks like less writing to go with the 1st example...especially since my code actually has 54 buttons and 15 different inputs.

Thanks again for your time ;)


My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
Share on other sites

Realm,

I would advise using the first method too. Leave GUIRegisterMsg until you really need it! ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

I ran accross another problems while trying to implement Melba23's First Example. This Gui I am creating has 4 tabs, and each tab is identical to the first. The buttons only place the text when the 4th tab is in focus, but will not work with the other three tabs. My orginal code is currently 1600+ lines in depth, so I wrote an example of what I have here, and the example is still giving me the same problems with the focus being stuck on the 4th tab.

#include <GUIConstantsEx.au3>
#include <WinAPI.au3>

Local $input1[4],$hInput_1[4],$input2[4],$hInput_2[4],$iTab[4]

$gui=GUICreate("My Gui")

$tab = GUICtrlCreateTab(10, 10, 380, 125)
For $tabNO=0 To 3
    Switch $tabNO
        Case 0
            $iTab[0] = GUICtrlCreateTabItem("1st Tab")
        Case 1
            $iTab[1] = GUICtrlCreateTabItem("2nd Tab")
        Case 2
            $iTab[2] = GUICtrlCreateTabItem("3rd Tab")
        Case 3
            $iTab[3] = GUICtrlCreateTabItem("4th Tab")
    EndSwitch
    $input1[$tabNO] = GUICtrlCreateInput("",20,50,300,17)
    $hInput_1[$tabNO] = GUICtrlGetHandle(-1)
    $input2[$tabNO] = GUICtrlCreateInput("",20,70,300,17)
    $hInput_2[$tabNO] = GUICtrlGetHandle(-1)
    $button1 = GUICtrlCreateButton("Insert 'Help",20,90)
    $button2 = GUICtrlCreateButton("Insert 'Example",130,90)
Next
GUICtrlCreateTabItem("")
GUISetState()

$hLastFocus = 0

While 1
    $GUIMsg = GUIGetMsg()
    Switch $GUIMsg
    Case $GUI_EVENT_CLOSE
    ExitLoop
    Case $button1
            _ButtonMacro("Help")
    Case $button2
    _ButtonMacro("Example")
    EndSwitch

    Switch _WinAPI_GetFocus()
    Case $hInput_1[0]
    $hLastFocus = $input1[0]
        Case $hInput_1[1]
    $hLastFocus = $input1[1]
        Case $hInput_1[2]
    $hLastFocus = $input1[2]
        Case $hInput_1[3]
    $hLastFocus = $input1[3]
    Case $hInput_2[0]
    $hLastFocus = $input2[0]
        Case $hInput_2[1]
    $hLastFocus = $input2[1]
        Case $hInput_2[2]
    $hLastFocus = $input2[2]
        Case $hInput_2[3]
    $hLastFocus = $input2[3]
    EndSwitch

WEnd

Func _ButtonMacro($textMacro)
    GUICtrlSetState($hLastFocus, $GUI_FOCUS)
    Send("{END}")
    Send($textMacro)
EndFunc ;==>_ButtonMacro()

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
Share on other sites

Realm,

Your problem stems from the fact that you are creating buttons on each tab, but only ever storing the ControlIds of the last created pair. ;) The 4th tab is created last, so it gets the active buttons. :)

You need to create the buttons OUTSIDE the tab definition structure so that the same buttons appear on each tab. Now you will find that they insert into the last selected input: ;)

#include <GUIConstantsEx.au3>
#include <WinAPI.au3>

Local $input1[4], $hInput_1[4], $input2[4], $hInput_2[4], $iTab[4]

$gui = GUICreate("My Gui")

$tab = GUICtrlCreateTab(10, 10, 380, 125)
For $tabNO = 0 To 3
    Switch $tabNO
        Case 0
            $iTab[0] = GUICtrlCreateTabItem("1st Tab")
        Case 1
            $iTab[1] = GUICtrlCreateTabItem("2nd Tab")
        Case 2
            $iTab[2] = GUICtrlCreateTabItem("3rd Tab")
        Case 3
            $iTab[3] = GUICtrlCreateTabItem("4th Tab")
    EndSwitch
    $input1[$tabNO] = GUICtrlCreateInput("", 20, 50, 300, 17)
    $hInput_1[$tabNO] = GUICtrlGetHandle(-1)
    $input2[$tabNO] = GUICtrlCreateInput("", 20, 70, 300, 17)
    $hInput_2[$tabNO] = GUICtrlGetHandle(-1)
Next
GUICtrlCreateTabItem("")

; Close the tab creation structure and create the buttons so they appear on each tab <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

$button1 = GUICtrlCreateButton("Insert 'Help", 20, 90)
$button2 = GUICtrlCreateButton("Insert 'Example", 130, 90)

GUISetState()

$hLastFocus = 0

While 1
    $GUIMsg = GUIGetMsg()
    Switch $GUIMsg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $button1
            _ButtonMacro("Help")
        Case $button2
            _ButtonMacro("Example")
    EndSwitch

    Switch _WinAPI_GetFocus()
        Case $hInput_1[0]
            $hLastFocus = $input1[0]
        Case $hInput_1[1]
            $hLastFocus = $input1[1]
        Case $hInput_1[2]
            $hLastFocus = $input1[2]
        Case $hInput_1[3]
            $hLastFocus = $input1[3]
        Case $hInput_2[0]
            $hLastFocus = $input2[0]
        Case $hInput_2[1]
            $hLastFocus = $input2[1]
        Case $hInput_2[2]
            $hLastFocus = $input2[2]
        Case $hInput_2[3]
            $hLastFocus = $input2[3]
    EndSwitch

WEnd

Func _ButtonMacro($textMacro)
    GUICtrlSetState($hLastFocus, $GUI_FOCUS)
    Send("{END}")
    Send($textMacro)
EndFunc   ;==>_ButtonMacro

Could I suggest reading the Tabs tutorial I put on the Wiki a few days ago - I think it will help clarify what I explained above. But if it does not, please ask! :P

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

That is excellent. And it makes complete sense. When I originally created the script, the buttons were a late idea addition. Being Lazy, I assumed their wasn't much documentation on multiple tabs with the same button configuration, so I didn't check, just gave it a whirl. I was also assuming that the buttons would have to be created on each tab individually to show. Thanks to you showing me it works with one creation, this actually opens up some possibilities for another project I have been working on. I will definately read up on your Tabs wiki, now that I am aware of one that exists. My other project will be another tab heavy project!

Thanks again Melba23! ;)

Realm


My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

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