Jump to content

Help with ControlID using the "X \ Y \ W \ H" Properties


Recommended Posts

Hello,

I am having some trouble with ControlID when I use the "X Y W H" properties. The reason I am trying to use the "X Y W H" properties instead of "[CLASS:Edit; INSTANCE:1]" is because the instance number changes as my script is ran, so if I refer to it as instance 1 at the end of the script, it is not pointing to the correct text box.

I'm not sure if using X and Y is a good idea though, since the X and Y can change if the size of the window is changed. Is it possible to just use W and H?

I have also though about using ControlGetHandle, but that brings another set of problems with it. When I looked in the help file under controls (http://www.autoitscript.com/autoit3/docs/intro/controls.htm) there were no examples using the "X Y W H" properties.

(Apologizes if this has already been discussed in the forums...I searched and could not find anything)

When i use the code below, the text does not get set:

Code:

ControlSetText($_currentWindowHWND, "", "[X:1081; Y:9; W:188; H:15]", $_orderNumber)

AutoIt v3 Window Info (Coord mode = "Window"):

>>>> Window <<<<
Title:    Title System Main
Class:    WindowsForms10.Window.8.app.0.360e033_r15_ad1
Position:    366, 59
Size:    1328, 900
Style:    0x16CF0000
ExStyle:    0x00050100
Handle:    0x00040584

>>>> Control <<<<
Class:    Edit
Instance:    1
ClassnameNN:    Edit1
Name:    
Advanced (Class):    [CLASS:Edit; INSTANCE:1]
ID:    1001
Text:    
Position:    1078, 9
Size:    188, 15
ControlClick Coords:    29, 7
Style:    0x50000380
ExStyle:    0x00000000
Handle:    0x00040712

>>>> Mouse <<<<
Position:    1111, 58
Cursor ID:    0
Color:    0xEEE8AA
Edited by Shrapnel
Link to comment
Share on other sites

Use the ID:

ID:    1001
 

ControlSetText($_currentWindowHWND, "", 1001, $_orderNumber)
 
your syntax for the xywh is good, but not including the proper values
Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Thanks for the quick reply jdelaney, but there are other text boxes in the window that also have an ID of 1001

There are about 9 text boxes that are all [CLASS:Edit; INSTANCE: X] and have an ID of 1001, but the Instance is always changing... its strange.

Link to comment
Share on other sites

More info on this:

The text boxes are actually embedded in a DDLB

When the Screen is first opened, the "Order number" text box is instance 1, and the "Type" text box is instance 2.

Then as I go though all of the tabs (which also have these type of text boxes embedded in DDLBs....that are all exactly the same as far as the window info too is concerned except for the instance number), the Instance number of the text box(es) changes, and at the end, the order number text box is instance 9....

 

Link to comment
Share on other sites

So each tab produces it's own edit with identical id?

try [iD:1001; INSTANCE:n]...and loop through, counting up n, until the returned handle is visible, maybe?

 

ControlCommand ( "title", "text", controlID, "IsVisible")

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

So each tab produces it's own edit with identical id?

 

Ya its pretty weird, especially with the instance number changing when new edits are shown....

 

Anyways, I went and compared all of the edits height and width, and the order number edit has a unique height and width, so by removing the X and Y, the below command works as expected. (I should have tried that before :blink: )

Thank you for your help though!

ControlSetText($_currentWindowHWND, "", "[CLASS:Edit; W:188; H:15]", $_orderNumber)

 

[Edit] Added "CLASS:Edit" to the controlid as well, just to make it more specific!

Edited by Shrapnel
Link to comment
Share on other sites

Try this code

#include <Constants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

Global $WinSetText = "WinSetText"

HotKeySet("{F1}", "MouseSetWindowText")
HotKeySet("{ESC}", "Terminate")

While True
Sleep(200)
WEnd

Func MouseSetWindowText()
$Pos = MouseGetPos()
if IsArray($Pos) Then
$X = $Pos[0]
$Y = $Pos[1]
$sPoint = DllStructCreate("int;int")
DllStructSetData($sPoint,1,$X)
DllStructSetData($sPoint,2,$Y)
$HWND = _WinAPI_WindowFromPoint($sPoint)
if ($HWND) Then
$hWndParent = $HWND
$OWNER = _WinAPI_GetWindow($HWND,$GW_OWNER)
if ($OWNER) Then $hWndParent = $OWNER
SetWindowText($hWndParent,$X,$Y,$WinSetText)
EndIf
EndIf
EndFunc

Func SetWindowText($hWndParent,$X,$Y,$sText)
$HWND = ChildWindowFromPoint($hWndParent,$X,$Y)
if @error Then Return SetError(1,0,False)
$BOOL = _WinAPI_SetWindowText($HWND,$sText)
if Not($BOOL) Then Return SetError(2,0,False)
_WinAPI_RedrawWindow($HWND,0,0,$RDW_INVALIDATE + $RDW_ALLCHILDREN)
Return SetError(0,0,True)
EndFunc

Func ChildWindowFromPoint($hWndParent,$X,$Y)
$Rect = _WinAPI_GetWindowRect($hWndParent)
if @error Then Return SetError(1,0,0)
$L = DllStructGetData($Rect,1)
$T = DllStructGetData($Rect,2)
$R = DllStructGetData($Rect,3)
$B = DllStructGetData($Rect,4)
if $X < $L Or $X > $R Or $Y < $T Or $Y > $B Then Return SetError(2,0,0)
$sPoint = DllStructCreate("int;int")
DllStructSetData($sPoint,1,$X)
DllStructSetData($sPoint,2,$Y)
_WinAPI_ScreenToClient($hWndParent,$sPoint)
$X = DllStructGetData($sPoint,1)
$Y = DllStructGetData($sPoint,2)
$HWND = DllCall("User32.dll","ptr","ChildWindowFromPoint","ptr",$hWndParent,"int",$X,"int",$Y)
if @error Or $HWND[0] = 0 Then Return SetError(3,0,0)
Return SetError(0,0,$HWND[0])
EndFunc

Func Terminate()
    Exit 0
EndFunc   

 

صرح السماء كان هنا

 

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...