Realm Posted September 18, 2010 Share Posted September 18, 2010 (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 September 21, 2010 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. Link to comment Share on other sites More sharing options...
wakillon Posted September 18, 2010 Share Posted September 18, 2010 (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 September 18, 2010 by wakillon AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 18, 2010 Moderators Share Posted September 18, 2010 (edited) Realm,Or perhaps like this: expandcollapse popup#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 WEndM23Edit:Of course, if you insist on using GUIRegisterMsg then you can also do it this way: expandcollapse popup#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_COMMANDEnjoy! Edited September 18, 2010 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Realm Posted September 19, 2010 Author Share Posted September 19, 2010 @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. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 19, 2010 Moderators Share Posted September 19, 2010 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Realm Posted September 19, 2010 Author Share Posted September 19, 2010 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. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 19, 2010 Moderators Share Posted September 19, 2010 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Realm Posted September 21, 2010 Author Share Posted September 21, 2010 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. expandcollapse popup#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. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 21, 2010 Moderators Share Posted September 21, 2010 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: expandcollapse popup#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 ;==>_ButtonMacroCould 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! M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Realm Posted September 21, 2010 Author Share Posted September 21, 2010 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now