Find Control Id With Random ID Number

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • r2du-soft
    Senior Member
    • Nov 2013
    • 343

    Find Control Id With Random ID Number

    Control in some application after open have random control id!
    i for find and send text in a text box with random id use this Section...

    HTML Code:
    !include WinMessages.nsh
    ShowInstDetails show
    var CounterM
    
    Section
    
    GetDlgItem $0 $HWNDPARENT 1
    EnableWindow $0 1
    
    StrCpy $CounterM "0"
    
    
    loop:
    DetailPrint "$CounterM"
    
    FindWindow $0 "WindowsForms10.Window.8.app.0.141b42a_r9_ad1" "Form1"
    GetDlgItem $0 $0 $CounterM
    SendMessage $0 ${WM_SETTEXT} 0 "STR:Hello World!"
    
    
    intop $CounterM $CounterM + 1
    
    Goto loop
    
    SectionEnd
    


    in my application text box id number is: 1246350

    loop It takes a long time for find text box Id number and sendMessage to that...

    There is a faster way for find text box or find other controls id and sendmessage to that's?
  • Anders
    Moderator
    • Jun 2002
    • 5643

    #2
    Maybe provide some more information? Did you write this app? Why do you need to do this?

    You can find child controls with FindWindow...
    IntOp $PostCount $PostCount + 1

    Comment

    • r2du-soft
      Senior Member
      • Nov 2013
      • 343

      #3
      Intelligent and speed up the work
      An organization has changed its Application Storage.
      New software is written with C#.
      The information contained in previous software all need to re-enter the new software.
      In this application,Page where Add the product to inventory goods warehouse There is Has several fields.
      The information to be entered in the fields, in a text file is available.
      Such that The information contained in each line of text file must enter to a field.
      We do it automatically To speed up the work.
      There is no problem in reading text file lines,But the main problem here...Read the value of each line of text file Must enter This program in various fields...
      And since the number control & HWNDPARENT is varies.in my section code has a loop so It takes a lot of time to control handler is found...
      After finding the control HWNDPARENT each line of text file must enter to a field.

      We have problems in doing so:

      1-It takes a long time to find all HWNDPARENT controls and we do not know where we continue to loop for found all controls!
      2-Can not obtain the name of each control
      If the program was written with vb6 we can found control text but this application it was made with C#,C# Controls have Control Name and i can not find control name but can found vb6 control text...

      3-What we want to do:
      read line ONE of text file & Write to Control With Name 'ProductName'
      read line TWO of text file & Write to Control With Name 'Stock'
      and ...

      4-Autoit how show controls Instance,Can be found control by Instance or TabIndex?

      a question:
      GetDlgItem Found control by ID.
      Can be found control by Name and after that write to that control value?
      If yes How?
      the problem is solved If this can be done



      Have prepared An example:
      Was attached
      Attached Files

      Comment

      • r2du-soft
        Senior Member
        • Nov 2013
        • 343

        #4
        YES!
        EnumChildWindows

        HTML Code:
        !include LogicLib.nsh
        !include WinMessages.nsh
        !include "defines.nsh"
        ShowInstDetails show
        
        Var HWND
        
        Section
        
        GetDlgItem $0 $HWNDPARENT 1
        EnableWindow $0 1
        
        ReBack:
        StrCpy $R2 ""
        Dialogs::InputBox "InputBox sample" "Please type something 'Class Names' Or 'Title Names'" "OK" "Cancel" "0" ${VAR_R2}
        StrCmp $R2 "" Cancel Ok
        
        Cancel:
        DetailPrint "No info was inputed by the user"
        goto Exit
        
        Ok:
        DetailPrint "User info: $R2"
        
        
        
        FindWindow $0 "" "$R2" ;$HWNDPARENT  #Class #Title
        ${IF} $0 == "0"
        FindWindow $0 "$R2" "" ;$HWNDPARENT  #Class #Title
        ${IF} $0 == "0"
        MessageBox MB_OK "Dont Find 'Class Names' Or 'Title Names' Please insert A true Value!"
        Goto ReBack
        
        ${Else}
        
        DetailPrint "Find Class"
        ${EndIf}
        ${Else}
        DetailPrint "Find Title"
        ${EndIf}
        
        
        
        
        
        StrCpy $HWND $0
        System::Call 'user32.dll::GetClassName(i r0, t .r5, i ${NSIS_MAX_STRLEN}) i .n'
        System::Call 'user32.dll::GetWindowText(i r0, t .r6, i ${NSIS_MAX_STRLEN}) i .n'
        DetailPrint "-----------------------------------------------------------"
        
        ;FindWindow $0 "" "Form1" ;$HWNDPARENT  #Class #Title
        ;StrCmp $0 0 Exit 0
        
        SetPluginUnload alwaysoff
        System::Get "(i.r1, i) iss"
        Pop $R0
        System::Call "user32::EnumChildWindows(i $0, k R0, i) i.s"
        loop:
                Pop $0
                StrCmp $0 "callback1" 0 done
                System::Call "user32::GetWindowText(ir1,t.r2,i${NSIS_MAX_STRLEN})"
                System::Call "user32::GetClassName(ir1,t.r3,i${NSIS_MAX_STRLEN})"
        		System::Call 'user32.dll::RealGetWindowClass(ir1, t .r4, i ${NSIS_MAX_STRLEN})'
                IntFmt $1 "0x%X" $1
                ;DetailPrint "[$1] - [$3] $2"
        		DetailPrint "Application HWNDPARENT: $HWND"
        		DetailPrint "Application Class: $5"
        		DetailPrint "Application Title: $6"
        		DetailPrint "---"
        		DetailPrint "Control HWNDPARENT: $1"
        		DetailPrint "Control Class: $3"
        		DetailPrint "Control Text: $2"
        		DetailPrint "Control RealGetWindowClass: $4"
        		DetailPrint "-----------------------------------------------------------"
        		;-----------------------------------------------
        		SendMessage $1 ${WM_SETTEXT} 0 "STR:0010"
        		;-----------------------------------------------
                Push 1 # callback's return value
                System::Call "$R0"
                Goto loop
        done:
        
        
        Exit:
        SectionEnd
        

        just i have one problem:
        See attached

        Can return VB6 applications control text value but Can't Return C# Applications Control TEXT Value!!Why?

        DetailPrint "Control Text: $2" Haven't Return Value

        how can fix this?
        Attached Files

        Comment

        • Anders
          Moderator
          • Jun 2002
          • 5643

          #5
          https://blogs.msdn.microsoft.com/old...21-00/?p=42833 hints that you need to use WM_GETTEXTLENGTH+WM_GETTEXT and not GetWindowText.
          IntOp $PostCount $PostCount + 1

          Comment

          • r2du-soft
            Senior Member
            • Nov 2013
            • 343

            #6
            Down ↓ Code Return Initial Value Text Box The programmer Entered To The Text Box:

            HTML Code:
            System::Call "user32::GetWindowText(ir1,t.r2,i${NSIS_MAX_STRLEN})"

            i test WM_GETTEXTLENGTH+WM_GETTEXT
            HTML Code:
            System::Call 'user32::SendMessage(i $1,i ${WM_GETTEXT},i ${WM_GETTEXTLENGTH},t.r9)'
            that Return The Value Which Are Now In The Text Box....

            But I Want Return Control Name...
            But I Don't know How!
            Such As Autoit

            Download New PNG images 100% Free incl. transparent background New PNGs. Get 100+ High Quality New PNGs with many resolutions.


            attached!
            Attached Files

            Comment

            • Anders
              Moderator
              • Jun 2002
              • 5643

              #7
              Name is not something a HWND has at the windowmanager level.

              That tool might be using Microsoft Active Accessibility (MSAA) and/or UI Automation (UIA), IAccessible::get_accName perhaps.

              You could try https://www.codeproject.com/Articles...-Accessibility and see if the Name there is the same thing.

              However, this forum is not a general programming forum! When dealing with stuff like this you should first write it in some language you know (VB? C#?) and then (and only then) if you have problems doing the same thing with System::Call should you ask here on the forum.
              IntOp $PostCount $PostCount + 1

              Comment

              Working...
              X