Jump to content

How to edit a numeric updown value for an existing UI


Recommended Posts

Hi All,

I have a UI which has window text using that i am able to control it. But there are few numeric updown with a default value and i want to change them to a different value. Using autoit info tool it doesnt have property called "Value" which is the property holding item. Please help me how to control that. Here the instance is always changing when i close and reopen the UI. Class name is same for all numeric updown files.

>>>> Control <<<<
Class:    WindowsForms10.Window.8.app.0.33c0d9d
Instance:    32
ClassnameNN:    WindowsForms10.Window.8.app.0.33c0d9d32
Name:    nupPllActive
Advanced (Class):    [NAME:nupPllActive]
ID:    461968
Text:    
Position:    419, 93
Size:    51, 20
ControlClick Coords:    28, 18
Style:    0x56010000
ExStyle:    0x00010000
Handle:    0x0000000000070C90
 

Waiting for help

thanks

tej

Link to comment
Share on other sites

  • Moderators

Tej,

Welcome to the AutoIt forum. :)

But please pay attention to where you post - the "Examples" section where you started this thread is clearly marked: "This is NOT a general support forum!". I have moved it for you, but would ask you to be more careful in future. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
Share on other sites

Hi jguinch,

I have tried but of no use. I believe control send is not having access to change "value" of numeric up and down as "Text" property is null for numUPDown control

Appreciate your help. Please let me know if you can give an example i will let you know the feedback.

ControlSetText($hWnd, "", "[NAME:nupPllActive]", "")
  Local $sText = ControlGetText($hWnd, "", "[CLASS:WindowsForms10.EDIT.app.0.33c0d9d; INSTANCE:8]")
  Local $sText = ControlGetText($hWnd, "", "WindowsForms10.EDIT.app.0.33c0d9d8")
  ControlSend("My parameters", "", "[NAME:nupPllActive]", "{DEL 3}6")
  ControlSetText("My  parameters", "", "nupPllActive", "77")

None of the above worked Let me know if something is wrong above.

Link to comment
Share on other sites

Hi Larsj,

Thanks a lot! That looks like a champion code.. i tried the script but of no help may be as i am new to it. There are 2 sections if i choose combox box i can grep with property name no value is shown and if i choose edit box its vice versa. How to fix this?

 

post-86216-0-31592600-1402654075_thumb.j

For combo box.docx

Link to comment
Share on other sites

Here is a small example (included in the zip below, exe + dll) with a WindowsForms10 numeric up-down control.

Edit_zps920f43fc.png

This code walks through all UI elements in the window:

#include "CUIAutomation2.au3"

Opt( "MustDeclareVars", 1 )

Global $oUIAutomation

MainFunc()


Func MainFunc()

  Local $hWindow = WinGetHandle( "NumericUpDown Cell/Col. Sample" )
  If Not $hWindow Then Return

  $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation )
  If Not IsObj( $oUIAutomation ) Then Return

  Local $pWindow
  ;$oUIAutomation.GetRootElement( $pWindow )             ; Desktop
  $oUIAutomation.ElementFromHandle( $hWindow, $pWindow ) ; Window
  If Not $pWindow Then Return

  Local $oWindow = ObjCreateInterface( $pWindow, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  If Not IsObj( $oWindow ) Then Return

  ;ListDescendants( $oWindow, 0, 1 ) ; Desktop
  ListDescendants( $oWindow, 0, 0 )  ; Window

EndFunc


Func ListDescendants( $oParent, $iLevel, $iLevels = 0 )

  If Not IsObj( $oParent ) Then Return
  If $iLevels And $iLevel = $iLevels Then Return

  Local $pRawWalker, $oRawWalker
  $oUIAutomation.RawViewWalker( $pRawWalker )
  $oRawWalker = ObjCreateInterface( $pRawWalker, $sIID_IUIAutomationTreeWalker, $dtagIUIAutomationTreeWalker )

  Local $pUIElement, $oUIElement
  $oRawWalker.GetFirstChildElement( $oParent, $pUIElement )
  $oUIElement = ObjCreateInterface( $pUIElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )

  Local $sIndent = ""
  For $i = 0 To $iLevel - 1
    $sIndent &= "    "
  Next

  While IsObj( $oUIElement )
    ConsoleWrite( $sIndent & "Title     = " & _UIA_getPropertyValue( $oUIElement, $UIA_NamePropertyId ) & @CRLF & _
                  $sIndent & "Class     = " & _UIA_getPropertyValue( $oUIElement, $UIA_ClassNamePropertyId ) & @CRLF & _
                  $sIndent & "Ctrl type = " & _UIA_getPropertyValue( $oUIElement, $UIA_ControlTypePropertyId ) & @CRLF & _
                  $sIndent & "Ctrl name = " & _UIA_getPropertyValue( $oUIElement, $UIA_LocalizedControlTypePropertyId ) & @CRLF & _
                  $sIndent & "Value     = " & _UIA_getPropertyValue( $oUIElement, $UIA_LegacyIAccessibleValuePropertyId ) & @CRLF & _
                  $sIndent & "Handle    = " & Hex( _UIA_getPropertyValue( $oUIElement, $UIA_NativeWindowHandlePropertyId ) ) & @CRLF & @CRLF )

    ListDescendants( $oUIElement, $iLevel + 1, $iLevels )

    $oRawWalker.GetNextSiblingElement( $oUIElement, $pUIElement )
    $oUIElement = ObjCreateInterface( $pUIElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  WEnd

EndFunc


Func _UIA_getPropertyValue( $obj, $id )
  Local $tVal
  $obj.GetCurrentPropertyValue( $id, $tVal )
  If Not IsArray( $tVal ) Then Return $tVal
  Local $tStr = $tVal[0]
  For $i = 1 To UBound( $tVal ) - 1
    $tStr &= "; " & $tVal[$i]
  Next
  Return $tStr
EndFunc

And this is output in Scite console:

Title     = ThousandsSeparator?
Class     = WindowsForms10.BUTTON.app.0.378734a
Ctrl type = 50002
Ctrl name = check box
Value     = 
Handle    = 00060274

Title     = Set
Class     = WindowsForms10.BUTTON.app.0.378734a
Ctrl type = 50000
Ctrl name = button
Value     = 
Handle    = 00060270

Title     = Get
Class     = WindowsForms10.BUTTON.app.0.378734a
Ctrl type = 50000
Ctrl name = button
Value     = 
Handle    = 00070248

Title     = Minimum:
Class     = WindowsForms10.STATIC.app.0.378734a
Ctrl type = 50020
Ctrl name = text
Value     = 
Handle    = 00070282

Title     = Minimum:
Class     = WindowsForms10.EDIT.app.0.378734a
Ctrl type = 50004
Ctrl name = edit
Value     = 0
Handle    = 0003030E

Title     = Set
Class     = WindowsForms10.BUTTON.app.0.378734a
Ctrl type = 50000
Ctrl name = button
Value     = 
Handle    = 000302F6

Title     = Get
Class     = WindowsForms10.BUTTON.app.0.378734a
Ctrl type = 50000
Ctrl name = button
Value     = 
Handle    = 000302F8

Title     = Maximum:
Class     = WindowsForms10.EDIT.app.0.378734a
Ctrl type = 50004
Ctrl name = edit
Value     = 100
Handle    = 000302FA

Title     = Set
Class     = WindowsForms10.BUTTON.app.0.378734a
Ctrl type = 50000
Ctrl name = button
Value     = 
Handle    = 00070224

Title     = Get
Class     = WindowsForms10.BUTTON.app.0.378734a
Ctrl type = 50000
Ctrl name = button
Value     = 
Handle    = 0007026A

Title     = DecimalPlaces:
Class     = WindowsForms10.EDIT.app.0.378734a
Ctrl type = 50004
Ctrl name = edit
Value     = 0
Handle    = 0006025A

Title     = Set
Class     = WindowsForms10.BUTTON.app.0.378734a
Ctrl type = 50000
Ctrl name = button
Value     = 
Handle    = 0008026C

Title     = Get
Class     = WindowsForms10.BUTTON.app.0.378734a
Ctrl type = 50000
Ctrl name = button
Value     = 
Handle    = 00080226

Title     = Maximum:
Class     = WindowsForms10.STATIC.app.0.378734a
Ctrl type = 50020
Ctrl name = text
Value     = 
Handle    = 0009026E

Title     = Increment:
Class     = WindowsForms10.EDIT.app.0.378734a
Ctrl type = 50004
Ctrl name = edit
Value     = 1
Handle    = 000302C2

Title     = Increment:
Class     = WindowsForms10.STATIC.app.0.378734a
Ctrl type = 50020
Ctrl name = text
Value     = 
Handle    = 00070268

Title     = DecimalPlaces:
Class     = WindowsForms10.STATIC.app.0.378734a
Ctrl type = 50020
Ctrl name = text
Value     = 
Handle    = 000202DE

Title     = DataGridView
Class     = WindowsForms10.Window.8.app.0.378734a
Ctrl type = 50036
Ctrl name = table
Value     = 
Handle    = 000202E0

    Title     = 
    Class     = WindowsForms10.Window.8.app.0.378734a
    Ctrl type = 50003
    Ctrl name = combo box
    Value     = 
    Handle    = 000202F2

        Title     = Spinner
        Class     = WindowsForms10.Window.8.app.0.378734a
        Ctrl type = 50016
        Ctrl name = spinner
        Value     = 
        Handle    = 000202E8

            Title     = Up
            Class     = 
            Ctrl type = 50000
            Ctrl name = button
            Value     = 
            Handle    = 00000000

            Title     = Down
            Class     = 
            Ctrl type = 50000
            Ctrl name = button
            Value     = 
            Handle    = 00000000

        Title     = 
        Class     = WindowsForms10.EDIT.app.0.378734a
        Ctrl type = 50004
        Ctrl name = edit
        Value     = 7
        Handle    = 000202EA

    Title     = Top Row
    Class     = 
    Ctrl type = 50025
    Ctrl name = 
    Value     = Top Row
    Handle    = 00000000

        Title     = Top Left Header Cell
        Class     = 
        Ctrl type = 50034
        Ctrl name = header
        Value     = 
        Handle    = 00000000

        Title     = NumericUpDown Column
        Class     = 
        Ctrl type = 50034
        Ctrl name = header
        Value     = NumericUpDown Column
        Handle    = 00000000

    Title     = Row 0
    Class     = 
    Ctrl type = 50025
    Ctrl name = 
    Value     = 7
    Handle    = 00000000

        Title     = Row 0
        Class     = 
        Ctrl type = 50034
        Ctrl name = header
        Value     = 
        Handle    = 00000000

        Title     = NumericUpDown Column Row 0
        Class     = 
        Ctrl type = 50025
        Ctrl name = 
        Value     = 7
        Handle    = 00000000

    Title     = Row 1
    Class     = 
    Ctrl type = 50025
    Ctrl name = 
    Value     = (Create New)
    Handle    = 00000000

        Title     = Row 1
        Class     = 
        Ctrl type = 50034
        Ctrl name = header
        Value     = 
        Handle    = 00000000

        Title     = NumericUpDown Column Row 1
        Class     = 
        Ctrl type = 50025
        Ctrl name = 
        Value     = (null)
        Handle    = 00000000

Title     = 
Class     = 
Ctrl type = 50037
Ctrl name = title bar
Value     = NumericUpDown Cell/Col. Sample
Handle    = 00000000

    Title     = System
    Class     = 
    Ctrl type = 50010
    Ctrl name = menu bar
    Value     = 
    Handle    = 00000000

        Title     = System
        Class     = 
        Ctrl type = 50011
        Ctrl name = menu item
        Value     = 
        Handle    = 00000000

    Title     = Minimize
    Class     = 
    Ctrl type = 50000
    Ctrl name = button
    Value     = 
    Handle    = 00000000

    Title     = Maximize
    Class     = 
    Ctrl type = 50000
    Ctrl name = button
    Value     = 
    Handle    = 00000000

    Title     = Close
    Class     = 
    Ctrl type = 50000
    Ctrl name = button
    Value     = 
    Handle    = 00000000

In the top of the picture you see a datagrid with a combo box and three rows. The combo box contains an edit control and a spinner. The spinner contains an up button and a down button. The top row is a header. The next row contains the value 7.

This code shows how to find all edit elements:

#include "CUIAutomation2.au3"

Opt( "MustDeclareVars", 1 )

MainFunc()


Func MainFunc()

  Local $hWindow = WinGetHandle( "NumericUpDown Cell/Col. Sample" )
  If Not $hWindow Then Return ConsoleWrite( "Window handle ERR" & @CRLF )
  ConsoleWrite( "Window handle OK" & @CRLF )

  ; Create UI Automation object
  Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation )
  If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "UI Automation object ERR" & @CRLF )
  ConsoleWrite( "UI Automation object OK" & @CRLF )

  ; Get UI Automation element from window handle
  Local $pWindow, $oWindow
  $oUIAutomation.ElementFromHandle( $hWindow, $pWindow )
  $oWindow = ObjCreateInterface( $pWindow, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  If Not IsObj( $oWindow ) Then Return ConsoleWrite( "Automation element from window ERR" & @CRLF )
  ConsoleWrite( "Automation element from window OK" & @CRLF )

  ; Condition to find Edit elements
  Local $pCondition
  $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_EditControlTypeId, $pCondition )
  If Not $pCondition Then Return ConsoleWrite( "Property condition ERR" & @CRLF )
  ConsoleWrite( "Property condition OK" & @CRLF )

  ; Find all Edit elements
  Local $pUIElementArray, $oUIElementArray, $iElements
  $oWindow.FindAll( $TreeScope_Descendants, $pCondition, $pUIElementArray ) ; <<<< Use your own $oWindow element <<<<<<<<<<<
  $oUIElementArray = ObjCreateInterface( $pUIElementArray, $sIID_IUIAutomationElementArray, $dtagIUIAutomationElementArray )
  $oUIElementArray.Length( $iElements )
  If Not $iElements Then Return ConsoleWrite( "Find Edit elements ERR" & @CRLF )
  ConsoleWrite( "Find all Edit elements OK. Elements: " & $iElements & @CRLF )

  ; Print values of the Edit elements
  Local $pEdit, $oEdit, $nValue
  For $i = 0 To $iElements - 1
    $oUIElementArray.GetElement( $i, $pEdit )
    $oEdit = ObjCreateInterface( $pEdit, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
    $oEdit.GetCurrentPropertyValue( $UIA_ValueValuePropertyId, $nValue )
    ConsoleWrite( "Value of Edit element " & $i & ": " & $nValue & @CRLF )
  Next

EndFunc

Now you can try to adapt the code to your own window.

NumericUpDown.7z

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...