Jump to content

Recommended Posts

I'm trying to use some inputboxes as radio buttons.

This code seems to work ok, but don't know if there's is a better 'option'

#include <GUIConstantsEx.au3>
#include <GuiConstants.au3>

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

Global $aInput[4]

$hGUI = GUICreate("Test", 500, 500)

$aInput[0] = GUICtrlCreateInput("Some text 1a", 10, 10, 200, 24)
$aInput[1] = GUICtrlCreateInput("Some text 1b", 10, 40, 200, 24)

$aInput[2] = GUICtrlCreateInput("Some text 2a", 10, 80, 200, 24)
$aInput[3] = GUICtrlCreateInput("Some text 2b", 10, 110, 200, 24)

GUISetState(@SW_SHOW, $hGUI)

While 1
   Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE
         ExitLoop
   EndSwitch
WEnd

Func WM_COMMAND($hWnd, $msg, $wParam, $lParam)
   Local $nNotifyCode = BitShift($wParam, 16) ; high word
   Local $nID = BitAND($wParam, 0xFFFF) ; low word
   Local $hCtrl = $lParam

   Switch $nID
      Case $aInput[0]
         Switch $nNotifyCode
            Case $EN_SETFOCUS
               GUICtrlSetBkColor($aInput[0], 0x98FB98)
               GUICtrlSetBkColor($aInput[1], 0xD3D3D3)
         EndSwitch
      Case $aInput[1]
         Switch $nNotifyCode
            Case $EN_SETFOCUS
               GUICtrlSetBkColor($aInput[0], 0xD3D3D3)
               GUICtrlSetBkColor($aInput[1], 0x98FB98)
         EndSwitch

      Case $aInput[2]
         Switch $nNotifyCode
            Case $EN_SETFOCUS
               GUICtrlSetBkColor($aInput[2], 0x98FB98)
               GUICtrlSetBkColor($aInput[3], 0xD3D3D3)
         EndSwitch
      Case $aInput[3]
         Switch $nNotifyCode
            Case $EN_SETFOCUS
               GUICtrlSetBkColor($aInput[2], 0xD3D3D3)
               GUICtrlSetBkColor($aInput[3], 0x98FB98)
         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   ;==>WM_COMMAND

Would you recommend using _WinAPI_GetFocus instead?

 

 

Thanks,

 

Link to post
Share on other sites
10 minutes ago, robertocm said:

I'm trying to use some inputboxes as radio buttons.

I'm not sure if you're aware of it or not, but that sounds really silly, use radio buttons as radio buttons. Why would you deliberately make things complicated when there's a simpler way to do it?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to post
Share on other sites

This is more or less the situation:

- There is one product description in the GUI

- This product has around 15 fields of components text information, to display in the GUI

- But i have 2 sources of text information for each component (like two database tables)

I want to dispaly both sources and also give the possibility of chosing between one of 'options'.

I also looking for a way to make possible the editing of the selected info, before generating a report.

Link to post
Share on other sites

Here is another option.

#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <WinAPIDlg.au3>

Global $g_idFocus, $g_aInput[2][2]
Global $g_hWnd = GUICreate("Test", 500, 500)

$g_aInput[0][0] = GUICtrlCreateInput("Some text 1a", 10, 10, 200, 24)
$g_aInput[0][1] = GUICtrlCreateInput("Some text 1b", 10, 40, 200, 24)

$g_aInput[1][0] = GUICtrlCreateInput("Some text 2a", 10, 80, 200, 24)
$g_aInput[1][1] = GUICtrlCreateInput("Some text 2b", 10, 110, 200, 24)

GUISetState()

AdlibRegister("_Highlight")

While 1
   Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE
         ExitLoop
   EndSwitch
WEnd

Func _Highlight()
    ;~ Get currently focused control id
    $idFocus = _WinAPI_GetDlgCtrlID(ControlGetHandle($g_hWnd, "", ControlGetFocus($g_hWnd, ""))) ;~ Get Control Id
    ;~ Compare local control id and global control id to determine if the focused control has already been processed, stops flickering
        If $g_idFocus = $idFocus Then Return
    ;~ Set global control id to local control id to show focused control has begun processing, stops flickering
        $g_idFocus = $idFocus
    ;~ Search input array for focused control id
    Local $iSearch = _ArraySearch($g_aInput, $idFocus)
    ;~ If search is unsuccessful return
        If @error Then Return
    ;~ Highlights for focused control id and unfocused control id of the selected array index item
    If $g_aInput[$iSearch][0] = $idFocus Then
        GUICtrlSetBkColor($g_aInput[$iSearch][0], 0x98FB98)
        GUICtrlSetBkColor($g_aInput[$iSearch][1], 0xD3D3D3)
    Else
        GUICtrlSetBkColor($g_aInput[$iSearch][0], 0xD3D3D3)
        GUICtrlSetBkColor($g_aInput[$iSearch][1], 0x98FB98)
    EndIf
EndFunc

 

Link to post
Share on other sites
21 hours ago, robertocm said:

Would you recommend using _WinAPI_GetFocus instead?

Hi robertocm :)

I tried _WinAPI_GetFocus() and it gave good results (code below) without the need of GUIRegisterMsg() or AdlibRegister() or $GUI_EVENT_PRIMARYDOWN (coupled with GUIGetCursorInfo() to retrieve the ID of the control that the mouse cursor is hovering over)

Also the _WinAPI_GetFocus() approach allows you to move through your Input controls using the Tab key, while the background colors change, which you can't do when using $GUI_EVENT_PRIMARYDOWN

As Melba23 wrote in one of your links : "It seems Input controls do not send messages, so we have to take a roundabout way..."

#include <GuiConstants.au3>
#include <WinAPISysWin.au3>

Global $idInput[2][5], $hInput[2][5], $hGetFocus = 0, $hGetFocus_Old = 0, $iRow = -20

$hGUI = GUICreate("Test", 500, 500)
For $i = 0 To 1
    For $j = 0 To 4
        $iRow += 30
        $idInput[$i][$j] = GUICtrlCreateInput("Some text " & ($i + 1) & Chr(97 + $j), _
            10, $iRow + $i*50, 200, 24)
        $hInput[$i][$j] = GUICtrlGetHandle($idInput[$i][$j])
    Next
Next

GUISetState(@SW_SHOW, $hGUI)

While 1
   Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE
         ExitLoop
    EndSwitch

    $hGetFocus = _WinAPI_GetFocus()
    If $hGetFocus <> $hGetFocus_Old Then Focus_Changed()
WEnd

Func Focus_Changed()
    For $i = 0 To 1
        For $j = 0 To 4
            If $hGetFocus = $hInput[$i][$j] Then
                GUICtrlSetBkColor($idInput[$i][$j], 0x98FB98)
                For $k = 0 To 4
                    If $k <> $j Then GUICtrlSetBkColor($idInput[$i][$k], 0xD3D3D3)
                Next
                ExitLoop(2) ; exit both For loops
            EndIf
        Next
    Next
    $hGetFocus_Old = $hGetFocus
EndFunc

 

_WinAPI_GetFocus.png.64201d69a47843ee1b19419c7a09dbee.png

Edited by pixelsearch
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By odaylton
      Text translated from Portuguese by google - please apologize for any errors
       
      First I have to thank the development team for product quality and the ease with which it is possible to develop tools with AutoIt.
       
      I am developing a series of libraries to facilitate the creation of Forms that once it is stable and comprehensive I intend to share here for autoit
      But suddenly during development an unexpected effect appeared in simple inputbox fields.
       
      Everything is working fine, however if I'm in an inputbox, don't change its selected content and move focus to another field the selected text remains blue (selected) instead of returning to normal
      See the image....

      When pricing 3x TABs all remain blue
       
      However if I change the field , when leaving its focus it behaves normally
      See the ex below:

      1) I selected “tipo Default” and pressed TAB (to test what happens)
      2) typed "TESTE" and pressed TAB
      3) I pressed TAB 2x again and the "Centralizado" field turned blue
      Note: by default, when receiving focus, the text is always automatically selected
       
      Here are some parts of the code:
      Gui  create:
      ;modifique o tamanho inicial aqui ;$Form[$Form[0][0]][1] = 600 ;largura =800 ;$Form[$Form[0][0]][2] = 600 ;Atura =600 ;$Form[$Form[0][0]][3] = "RoboAutomato - "&$NomeProjeto $Form[$Form[0][0]][0] = GUICreate($Form[$Form[0][0]][3], _ $Form[$Form[0][0]][1], $Form[$Form[0][0]][2], _ Default, Default, _ BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_TABSTOP, $WS_POPUP)) GUISetFont($FormFonteTam, _ ;Tamanho da Fonte $FormFonteTipo, _ ;Tipo da Fonte $FormFonteEstilo, _ ;Estilo da Fonte $FormFonteNome) ; Nome da Fonte #Region Criando ToolTip $hGUIToolTip = _GUIToolTip_Create($Form[$Form[0][0]][0], BitOR($_TT_ghTTDefaultStyle, $TTS_BALLOON)) ; balloon style tooltip #EndRegion Criando ToolTip  inputs create:
      .... InputCriar(200, 200, _ ;Coordenadas Base Default, Default, _ ;Largura e Altura automatica se negativo em função do extremo da janela "|Referencia|", _ ;Label do Input "Tudo Default ou qq diferente de 1,2,3,4: mais simples", _ ;Texto explicativo do InputBox e seu label "Teste do tipo Default", _ ;Valor Default da Input Default, _ ;0 é Defaultou define o estilo Default, _ ;Defini a forma de incerção Default=20 caracteres "CCCCCCCCCCCCCCCCCCCC" Default, _ Default, _ Default, _ ; Tipo de alinhamento em relação a Janela Default, _ ;Tamanho da Fonte Default, _ ;Tipo da Fonte Default, _ ;Estilo da Fonte Default) ; Nome da Fonte InputCriar(200, Default, _ ;Coordenadas Base Default, Default, _ ;Largura e Altura automatica se negativo em função do extremo da janela "|Canto inferior esquerdo|", _ ;Label do Input "Tipo 1: 2 linhas", _ ;Texto explicativo do InputBox e seu label "Tipo 1: 2 linhas", _ ;Valor Default da Input 1, _ ;0 é Defaultou define o estilo Default, _ ;Defini a forma de incerção Default=20 caracteres "CCCCCCCCCCCCCCCCCCCC" Default, _ Default, _ Default, _ ; Tipo de alinhamento em relação a Janela Default, _ ;Tamanho da Fonte Default, _ ;Tipo da Fonte Default, _ ;Estilo da Fonte Default) ; Nome da Fonte ..... Function InputCriar:
      Func InputCriar($InputX = Default, $InputY = Default, _ ;Coordenadas Base Canto Superior Esquerdo se não definido proxima linha e coluna $InputWidth = Default, $InputHeight = Default, _ ;Largura e Altura automatica se negativo em função do extremo da janela $InputRotulo = "", _ ;Label do Inpu $InputTip = "", _ ;Texto explicativo do InputBox e seu label $InputDefault = "", _ ;Valor Default da Input $InputAlin = Default, _ ;0 é Defaultou define o estilo $InputMascara = Default, _ ;Defini a forma de incerção Default=20 caracteres "CCCCCCCCCCCCCCCCCCCC" $InputEstilo = Default, _ $InputEstiloEx = Default, _ $InputResizing = Default, _ ; Tipo de alinhamento em relação a Janela $InputTamFonte = Default, _ ;Tamanho da Fonte $InputFonteTipo = Default, _ ;Tipo da Fonte $InputFonteEstilo = Default, _ ;Estilo da Fonte $InputFonteNome = Default) ; Nome da Fonte .... $InputEstilo = BitOR($ES_AUTOHSCROLL, _ $WS_TABSTOP) ... $InputEstiloEx = $WS_EX_CLIENTEDGE ;formato baixo relevo ... $Inputs[$Inputs[0][0]][0] = GUICtrlCreateInput($Mascara5, _ ;Default da Input $Form[$Form[0][0]][6]+$InputX, $Form[$Form[0][0]][7]+$InputY, _ ;Coordenadas Base $InputWidth, $InputHeight, _ ;Altura e largura automatica $InputEstilo, _ ;Estilo $InputEstiloEx) ;Extilo extra ... GUICtrlSetData($Inputs[$Inputs[0][0]][0], $Inputs[$Inputs[0][0]][3]) Return $Inputs[$Inputs[0][0]][0] EndFunc ;==>InputCriar sorry for not putting all the code because there are many libraries and they are in the initial stage of development
       
      What should I change to get Inputbox's behavior back to normal????
      Thank you for your attention
    • By nooneclose
      Why can I not click on either of my input fields?
      #Region ### START Koda GUI section ### Form= Global $Form1 = GUICreate("Form1", 730, 437, 192, 124) ;GUISetFont(14, 800, 0, "MS Sans Serif") GUISetBkColor(0xC0DCC0) Global $Label1 = GUICtrlCreateLabel("Enter your Password. UserName is auto filled", 62, 40, 604, 41, $SS_CENTER) GUICtrlSetFont(-1, 26, 800, 0, "MS Sans Serif") Global $Label2 = GUICtrlCreateLabel("User Name:", 120, 130, 604, 31, $SS_LEFT) GUICtrlSetFont(-1, 20, 800, 0, "MS Sans Serif") Global $Label3 = GUICtrlCreateLabel("Password:", 135, 210, 604, 31, $SS_LEFT) GUICtrlSetFont(-1, 20, 800, 0, "MS Sans Serif") Global $Input1 = GUICtrlCreateInput(@UserName, 274, 130, 185, 32) GUICtrlSetFont(-1, 14, 800, 1, "MS Sans Serif") Global $Input2 = GUICtrlCreateInput("Password", 274, 210, 185, 32, $ES_PASSWORD) GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif") Global $OK = GUICtrlCreateButton("OK", 274, 270, 185, 57) GUICtrlSetFont(-1, 20, 800, 0, "MS Sans Serif") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $OK Global $UserName = GUICtrlRead($Input1) Global $PassWord = GUICtrlRead($Input2) ExitLoop EndSwitch WEnd ; Delete the GUI window GUIDelete()  
    • By matwachich
      Hi AutoIters!
      Here is my new UDF about GUIs: it's an enhanced mixture of Advanced InputBox (deprecated) and KODA Parser (deprecated), with additional functions.
      What you can do with it:
      Parse KODA files and directly create GUIs (_GUIUtils_CreateFromKODA) Parse a simple JSON form definition to simply create advanced InputBoxes with any amount/type of input controls (_GUIUtils_CreateFromJSON) Created GUIs are returned as Scripting.Dictionary objects, and you have helper functions to access GUIs controls by their names (_GUIUtils_HWnd, _GUIUtils_CtrlID, _GUIUtils_HCtrl ...) A function that can make a GUI created from KODA/JSON (defined by it's $oForm object) and make it a modal InputDialogBox (just like InputBox, but returns all entered data as Scripting.Dictionary object) Functions are documented, and there are some examples.
      Consider this UDF as beta, but since I'm currently using it in a small commercial project, it should become production ready in near future.
      To always get the latest code version, get it from Github (more up to date than this topic).
      Update 04/02/2020:
      New simple application example Fixed focused control handling in _GUIUtils_InputDialog Reset input values before returning from _GUIUtils_InputDialog Fixed CloseOnEsc in _GUIUtils_InputDialog Fixed Input not reset Fixed all ListBox items are selected Project now on GitHub https://github.com/matwachich/autoit-guiutils/
      Update 05/02/2020:
      Support for nodate for Date and Time input controls (pass null value) New handling of focused control _GUIUtils_InputDialog: Now, you can specify the focused control in $oInitialData by setting "controlName:focus" = True Updated documentation of _GUIUtils_InputDialog Update 07/02/2020:
      Bug corrected when setting Data input control Added: abillity to read a single input control New functions (_GUIUtils_GetInputs, _GUIUtils_WriteInputs), documentation completion. Readme file and screenshots on Github Page  
      GUIUtils.zip
    • By matwachich
      DEPRECATED: see this new UDF
       
    • By Ackerz
      Hi guys,
      So I am trying to automate a task and this task has an input box with an already set character "9". 
      I have just decided that I don't really need the input as an option but it's good to leave however for this instance I would like it to run past this point automatically. I've tried numerous ways to try and automate the use of the "OK" button using ControlClick and various other options. I just can't seem to see where this point in the script is. Scoured the forums for anything similar but didn't have any luck finding anything. Sorry to be a pain and I hope someone can help, if I haven't explained in enough detail please don't hesitate to ask for more.
      Many thanks,
      Ackerz
       
      Local $len Local $n Local $buff Local $aMyDate $Len = InputBox("Test",$msgPrompt,"9") $len = StringStripWS($len,$STR_STRIPALL) ;Check that user has entered a vaild password length if not StringIsDigit($len) or $len = 0 Then MsgBox(48,"Error","Invaild Integer was entered" & @CRLF & "Program will now exit.") Exit EndIf ;This creates the random password. for $i = 1 to $Len ;Pick a random char between 1 and the pwsMask Length $n = int(random(1,StringLen($pwsMask))) ;Concat each char that has been picked out of pwsMask to $buff $buff = $Buff & StringMid($pwsmask,$n,1) Next  
×
×
  • Create New...