Get selected GUICtrlCreateInput

4 posts in this topic

As the title states, is there a way to detect which inputbox is "selected"


if IsSelectedForWritingEtc($MyInputBox) then xxxx

i was searching some without success, all my results were like how to read or and write to a inputbox. 





TeenyScript 2016-09-05 - A new  way of programming in AutoIt

UDFs created\updated 2016
_IEEmbedded2 UDF - A _IECreateEmbedded() decedent
miniSQL - A simple Standalone PDO-syntax-like MySQL-library with AutoitObject
Advanced DllCall and DllStruct AutoIt Code Generator - Automatically generates code for DllCall and more.


Share this post

Link to post
Share on other sites


 I use _WinAPI_GetFocus to do this.


1 person likes this

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


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

Thanks for the answers, just what i was looking for :)


TeenyScript 2016-09-05 - A new  way of programming in AutoIt

UDFs created\updated 2016
_IEEmbedded2 UDF - A _IECreateEmbedded() decedent
miniSQL - A simple Standalone PDO-syntax-like MySQL-library with AutoitObject
Advanced DllCall and DllStruct AutoIt Code Generator - Automatically generates code for DllCall and more.


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

  • Similar Content

    • Comboku
      By Comboku
      Hi Guys,
      i am working on a translation app. There are a couple of regular input fields with text that the user is supposed to change to a new language. 
      I want to change the color of the input field  as soon as the user leaves the input field. Is there a way to do that? 
      I know how to do this with a button, but i don't know how i can work with focus. Has any of you done something like this before?
    • Trolleule
      By Trolleule
      i did some researchs how to set the font and the only way is to overwrite the subclass with WM_DRAWITEM. With WM_SETFONT i can only change the font for all tab pages, but i want to change the font for a specific page.
      So i have to set the $TCS_OWNERDRAWFIXED style to the tab control to send the WM_DRAWITEM message to the parent window. When i set this style, i can change the fonts, but sadly the tab looses the nice and simple "AutoIt style". I created two child guis, the first is the owner draw tab and the second the "Normal" tab.
      My questions is, how to create this special "AutoIt style"???
      #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiTab.au3> #include <ColorConstants.au3> Global Const $ODT_TAB = 101 Global Const $ODS_SELECTED = 0x0001 Global Const $ODA_DRAWENTIRE = 0x1 Global Const $ODS_FOCUS = 0x0010 $hStrikeOutDefaultFont = _WinAPI_CreateFont(14, 0, 0, 0, 400, False, False, True) ; see system apps module $hGUI = GUICreate("Draw Tab", 500, 600) ; Create child GUIs to hold tabs $hTab_Win0 = GUICreate("", 400, 200, 50, 20, $WS_POPUP, $WS_EX_MDICHILD, $hGUI) $hTab_0 = GUICtrlCreateTab(10, 10, 380, 180, $TCS_OWNERDRAWFIXED);BitOR($TCS_OWNERDRAWFIXED, $TCS_TOOLTIPS, $WS_TABSTOP, $WS_CLIPSIBLINGS)) $hTab_00 = GUICtrlCreateTabitem("00") GUICtrlCreateButton("00", 160, 90, 80, 30) $hTab_01 = GUICtrlCreateTabitem("01") GUICtrlCreateButton("01", 160, 90, 80, 30) GUICtrlCreateTabitem ("") GUISetState() $hTab_Win1 = GUICreate("", 400, 200, 50, 250, $WS_POPUP, $WS_EX_MDICHILD, $hGUI) $hTab_1 = GUICtrlCreateTab(10, 10, 380, 180) $hTab_10 = GUICtrlCreateTabitem("10") GUICtrlCreateButton("10", 160, 90, 80, 30) $hTab_11 = GUICtrlCreateTabitem("11") GUICtrlCreateButton("11", 160, 90, 80, 30) GUICtrlCreateTabitem ("") GUISetState() GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM") ;~ GUIRegisterMsg($WM_SETFONT, "WM_SETFONT") ;~ GUICtrlSendMsg ( $hTab_1, $WM_SETFONT , $hStrikeOutDefaultFont, 1 ) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func WM_SETFONT($hWnd, $Msg, $wParam, $lParam) ConsoleWrite("$hWnd: " & $hWnd & " $Msg: " & $Msg & " $wParam: " & $wParam & " $lParam: " & $lParam & @CRLF) EndFunc Func WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam) Local $DRAWITEMSTRUCT $DRAWITEMSTRUCT = DllStructCreate("uint cType;uint cID;uint itmID;uint itmAction;uint itmState;" & _ "hwnd hItm;hwnd hDC;dword itmRect[4];dword itmData", $lParam) If DllStructGetData($DRAWITEMSTRUCT, "cType") <> $ODT_TAB Then Return $GUI_RUNDEFMSG Local $cID = DllStructGetData($DRAWITEMSTRUCT, "cID") Local $itmID = DllStructGetData($DRAWITEMSTRUCT, "itmID") Local $itmAction = DllStructGetData($DRAWITEMSTRUCT, "itmAction") Local $itmState = DllStructGetData($DRAWITEMSTRUCT, "itmState") Local $hItm = DllStructGetData($DRAWITEMSTRUCT, "hItm") Local $hDC = DllStructGetData($DRAWITEMSTRUCT, "hDC") If $itmAction <> $ODA_DRAWENTIRE Then Return $GUI_RUNDEFMSG Local $iTextColor, $itmText $iTextColor = 0xFFFFFF Switch $itmID Case 0 $iBrushColor = 0x11AADD Case 1 $iBrushColor = 0xEEBB99 EndSwitch _WinAPI_SetBkMode($hDC, $TRANSPARENT) Local $iBrush = _WinAPI_CreateSolidBrush($iBrushColor) Local $iBrushOld = _WinAPI_SelectObject($hDC, $iBrush) $g_tRECT = DllStructCreate($tagRect, DllStructGetPtr($DRAWITEMSTRUCT, "itmRect")) DllStructSetData($g_tRECT, "Left", DllStructGetData($g_tRECT, "Left")) DllStructSetData($g_tRECT, "Top", DllStructGetData($g_tRECT, "Top")) DllStructSetData($g_tRECT, "Right", DllStructGetData($g_tRECT, "Right")) DllStructSetData($g_tRECT, "Bottom", DllStructGetData($g_tRECT, "Bottom")+10) _WinAPI_FillRect ( $hDC, $g_tRECT, $iBrush ) _WinAPI_SetTextColor($hDC, $iTextColor) _WinAPI_DrawText($hDC, "Item " & $itmID, $g_tRECT, $DT_LEFT) _WinAPI_SelectObject($hDC, $iBrushOld) _WinAPI_DeleteObject($iBrush) Return $GUI_RUNDEFMSG EndFunc ;==>WM_DRAWITEM Thanks in advance
    • Trolleule
      By Trolleule
      iam not able to "activate" (the blue border of the edit control should be displayed) the created input control when clicking on a listview item. All i want is, when the edit control is created, it's active (blue border displayed) and you can directly write in it (cursor at the end), but i can't get it work. Can someone help?
      #include <GuiConstantsEx.au3> #include <GuiListView.au3> #include <GuiImageList.au3> #include <WindowsConstants.au3> #include <GuiEdit.au3> #include <Misc.au3> Global $Debug_LV = False ; Check ClassName being passed to ListView functions, set to True and use a handle to another control to see it work Global $bChanged = False, $hDLL = DllOpen("user32.dll") Global $aClick_Info[2] Global $hListView, $hTmp_Edit Global $GUI, $hImage $GUI = GUICreate("(UDF Created) ListView Create", 400, 300) $hListView = _GUICtrlListView_Create($GUI, "", 2, 2, 394, 268) _GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)) GUISetState() GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ; Load images $hImage = _GUIImageList_Create() _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0xFF0000, 16, 16)) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x00FF00, 16, 16)) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x0000FF, 16, 16)) _GUICtrlListView_SetImageList($hListView, $hImage, 1) ; Add columns _GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 100) _GUICtrlListView_InsertColumn($hListView, 1, "Column 2", 100) _GUICtrlListView_InsertColumn($hListView, 2, "Column 3", 100) ; Add items _GUICtrlListView_AddItem($hListView, "Row 1: Col 1", 0) _GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 2", 1) _GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 3", 2) _GUICtrlListView_AddItem($hListView, "Row 2: Col 1", 1) _GUICtrlListView_AddSubItem($hListView, 1, "Row 2: Col 2", 1) _GUICtrlListView_AddItem($hListView, "Row 3: Col 1", 2) ; Loop until user exits Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo $hWndListView = $hListView If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button Local $iIndex, $iSubItem, $sTmp_Text, $aRect, $aPos $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam) $iIndex = DllStructGetData($tInfo, "Index") $iSubItem = DllStructGetData($tInfo, "SubItem") ; make sure user clicks on the listview & only the activate If $iIndex <> -1 And Not $bChanged Then $bChanged = True Local $iTimer = TimerInit() Local $iCounter = 1 Local $DOUBLE_CLICK_TIME_DELTA = 1200 While 1 If _IsPressed("01", $hDLL) Then $iCounter+=1 ConsoleWrite("_IsPressed - clicked." & @CRLF) ; Wait until key is released. While _IsPressed("01", $hDLL) WEnd ConsoleWrite("counter: " & $iCounter & " timer: " & TimerDiff($iTimer) & @CRLF) EndIf If $iCounter = 2 And TimerDiff($iTimer) < $DOUBLE_CLICK_TIME_DELTA Then ConsoleWrite("yes." & @CRLF) ExitLoop EndIf If TimerDiff($iTimer) > $DOUBLE_CLICK_TIME_DELTA Then ConsoleWrite("over." & @CRLF) $bChanged = False Return 1 EndIf WEnd GUICtrlDelete($hTmp_Edit) $aClick_Info[0] = $iIndex $aClick_Info[1] = $iSubItem ;~ GUISetAccelerators($aAccelKeys) $sTmp_Text = _GUICtrlListView_GetItemText($hWndListView, $iIndex, $iSubItem) ConsoleWrite("item: " & $iIndex & " subitem: " & $iSubItem & " text: " & $sTmp_Text & @CRLF) If $iSubItem = 0 Then $aRect = _GUICtrlListView_GetItemRect($hWndListView, $iIndex, 2) Else $aRect = _GUICtrlListView_GetSubItemRect($hWndListView, $iIndex, $iSubItem) EndIf $aPos = ControlGetPos("", "", $hWndListView) ConsoleWrite("Information :" & StringFormat("Item 2 Rectangle : [%d, %d, %d, %d]", $aRect[0]+ $aPos[0], $aRect[1]+ $aPos[1], $aRect[2], $aRect[3]) & @CRLF) $hTmp_Edit = GUICtrlCreateEdit($sTmp_Text, $aRect[0] + $aPos[0], $aRect[1] + $aPos[1], $aRect[2] - $aRect[0], $aRect[3] - $aRect[1], 0) GUICtrlSetState($hTmp_Edit, $GUI_FOCUS+$GUI_SHOW+$Gui_ontop) _GUICtrlEdit_SetSel(GUICtrlGetHandle($hTmp_Edit), 2, 15) EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY  
    • Anas
      By Anas
      I've a problem and a few questions about list view.
      When I expand/collapse a group that causes the list view to add/remove a scrolling bar, the list view contents disappears and minimizing/restoring the window fix it.
      - How can I fix the list view content disappearing without removing $LVS_EX_FULLROWSELECT.
      Also, How can I:
      - expand a collapsed group without applying $LVGS_NORMAL and $LVGS_COLLAPSIBLE separately (without calling  _GUICtrlListView_SetGroupInfo twice)
      - remove the empty space at the end of the list view when scrolled to the end.
      - place the groups expand arrow on the left side.
      #include <GuiListView.au3> #include <GUIConstants.au3> Example() Func Example() GUICreate("ListView in a Tab", 400, 250) GUICtrlCreateTab(1, 1, 400, 200) GUICtrlCreateTabItem('Tab') $LV = GUICtrlCreateListView("Column", 15, 35, 370, 150) ;$LV = GUICtrlCreateListView("Column", 15, 35, 370, 150, Default, $WS_EX_CLIENTEDGE) ;Works, $LVS_EX_FULLROWSELECT removed. $BT1 = GUICtrlCreateButton("Expand 1", 50, 210, 100, 30) $BT2 = GUICtrlCreateButton("Expand 2", 250, 210, 100, 30) GUISetState() _GUICtrlListView_EnableGroupView($LV) _GUICtrlListView_InsertGroup($LV, -1, 1, "") _GUICtrlListView_SetGroupInfo($LV, 1, "Group", 1, BitOR($LVGS_COLLAPSED, $LVGS_COLLAPSIBLE)) For $i = 1 To 10 GUICtrlCreateListViewItem("Item " & $i, $LV) ;_GUICtrlListView_AddItem($LV, "Item " & $i) ;Same problem _GUICtrlListView_SetItemGroupID($LV, $i-1, 1) Next While 1 $msg = GUIGetMsg() Switch $msg Case $BT1 _GUICtrlListView_SetGroupInfo($LV, 1, "Group", 1, BitOR($LVGS_NORMAL, $LVGS_COLLAPSIBLE)) Case $BT2 _GUICtrlListView_SetGroupInfo($LV, 1, "Group", 1, $LVGS_NORMAL) _GUICtrlListView_SetGroupInfo($LV, 1, "Group", 1, $LVGS_COLLAPSIBLE) Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd GUIDelete() EndFunc  
    • crazyjts
      By crazyjts
      Hi all,
      I have the following snippet of code that sort of works but isn’t doing exactly what I want.
      expand popup #include <GuiConstants.au3> Global $gGUIWidth = 250 Global $gGUIHeight = 150 Initial() Func Initial()    ; Create the initial GUI    $BaseGUI = GUICreate("", $gGUIWidth, $gGUIHeight, -1, -1, -1, $WS_EX_TOPMOST + $WS_EX_TOOLWINDOW)    GUISetState(@SW_SHOW, $BaseGUI)    ; Create a field for entering the current value    GUICtrlCreateLabel("Current Value:",  10, 10)    $CurrentValueFld = GUICtrlCreateInput("", 10, 40, 215, 20, $ES_NUMBER)    GUICtrlSetState($CurrentValueFld, $GUI_FOCUS)    ; Create Calculate button    Local $CalculateButton = GUICtrlCreateButton("Calculate", 10, 70, 75, 25)    GUICtrlSetState($CalculateButton, $GUI_DISABLE)    ; Watch the value field and determine if the value is greater than 0 and if so, enable Calculate button    $i = 0    Do       $CurrentValue = GUICtrlRead($CurrentValueFld)       If $CurrentValue > 0 Then          GUICtrlSetState($CalculateButton, $GUI_ENABLE + $GUI_FOCUS)          $i = 1       EndIf    until $i = 1    ;Loop until the user exits and check for ESC, "X", or Begin button    While 1       $InitialGUIMsg = GUIGetMsg()       If $InitialGUIMsg = $GUI_EVENT_CLOSE Then          Exit       EndIf    WEnd EndFunc  
      I want to be able to:
        Start with focus in the value field (it is doing this now)  Allow for more than one digit to be entered into the field (it is sort of doing this now but I have to bring focus back to the field) Enable the Calculate button and give focus to it once a value is entered into the value field (it is doing this now) but keep the cursor in the value field so the more digits can be entered (it is not doing this now) Be able to hit ESC or “X” to close the dialog at any time (this only works after I enter a digit in the value field Basically, I want to be able to allow the user to enter one or more digits and hit ENTER or SPACE (while the cursor is still in the value field) to push the Calculate button.  I assume I need to bring focus to the button but maybe I don't and can get away with assigning hotkeys for ENTER and SPACE to push the Calculate button while keeping focus in the value field.
      If you could, please add comments in your code as to what the changes are doing if they aren't obvious to a noobish programmer.  
      Thanks for any help you can offer on this.