HighTechRedNeck

AfxWndW Controls

9 posts in this topic

I writing code to Export Oracle Calendar into Outlook Calendar. I am using the native Import/Export function of Outlook. When I bring up my calendars, I have the Outlook calendar on the left and the Oracle calendar on the right. They both appear to be an AfxWndW control. So when I use the native Import/Export function, I have to click on the Oracle side of the calender to give it focus, then perform the Export function.

I have noticed that the AfxWndW control Instance is not always the same. The text in the control is "Day View" (same text in both).

How can I determine the Instance number of each control so I can use the ControlClick() function? I have tried the MouseClick() function and that works OK, except if the screen resolution is different. Then the absolute mouse coordinates are not right and I don't get focus on the proper window.

Share this post


Link to post
Share on other sites



I writing code to Export Oracle Calendar into Outlook Calendar. I am using the native Import/Export function of Outlook. When I bring up my calendars, I have the Outlook calendar on the left and the Oracle calendar on the right. They both appear to be an AfxWndW control. So when I use the native Import/Export function, I have to click on the Oracle side of the calender to give it focus, then perform the Export function.

I have noticed that the AfxWndW control Instance is not always the same. The text in the control is "Day View" (same text in both).

How can I determine the Instance number of each control so I can use the ControlClick() function? I have tried the MouseClick() function and that works OK, except if the screen resolution is different. Then the absolute mouse coordinates are not right and I don't get focus on the proper window.

You can use advanced control ID notation: "[CLASS:AfxWndW; X:178; Y:63]"

The X/Y fields are left/top corner of the control in client-area relative coordinates, I believe.

See the help file under "Controls".

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

You may have already solved your problem, but I wanted to offer this link to a question I raised on the use of X/Y when referencing a control. It is not very intuitive, at least when I was attempting to use it.

In addition, I'll throw out that I had a similar problem with a control in an app I was testing. Namely, the instance would change if I changed screens. In my context, I fortunately discovered that the target control was always instance N-4, where N is the total number of instances of that control class in the window. So I wrote wrappers so that I could access the control like so:

;===============================================================================
;
; Function Name:    GetClassNameNNforWindow
; Description::     Returns a dictionary that contains all classes and their 
;                   total count for a given window
; Parameter(s):     $WindowName = Name of the .NET Window Form
;                   $WindowText = Text of the Window to read ( Optional )
; Return Value(s):  Dictionary ( key = CLASS; value = Total Count )
; Author(s):        Zach Fisher
;
;===============================================================================
;
Func GetClassNameNNforWindow( $windowTitle, $WindowText = "" )
    Local $dctClassNameNN = ObjCreate( "Scripting.Dictionary" )
    Local $aClassList = StringSplit( WinGetClassList( $windowTitle, $WindowText ), @LF )

    for $i = 1 to $aClassList[0] - 1
        if ( $dctClassNameNN.Exists( $aClassList[$i] )) then
            $dctClassNameNN( $aClassList[$i] ) = $dctClassNameNN( $aClassList[$i] ) + 1
        else
            $dctClassNameNN.Add( $aClassList[$i], 1 )
        endif
    next    
    
    return $dctClassNameNN
EndFunc

; Open calculator in Standard view 
Dim $controlClasses = GetClassNameNNforWindow( "Calculator" )

; get the text from the fourth-to-last button
Dim $controlText = ControlGetText( "Calculator", "", "Button" & $controlClasses( "Button" ) - 3 )
ConsoleWrite( $controlText & @CRLF)

It may not solve your immediate problem, but it is a nice trick to have in your back pocket. Good luck!

Zach Fisher...

EDIT: Off by one bugs abound.

Edited by zfisherdrums

Share this post


Link to post
Share on other sites

You may have already solved your problem, but I wanted to offer this link to a question I raised on the use of X/Y when referencing a control. It is not very intuitive, at least when I was attempting to use it.

; ...

EDIT: Off by one bugs abound.

Well, they always have in MY scripts! :)

I do see an issue with the X/Y/W/H format. This demo works when specifying X/Y or X/Y/W, but not X/Y/W/H:

Global $hGUI = GUICreate("Test", 300, 200)

; Create 3 buttons
$idButton_1 = GUICtrlCreateButton("1", 100, 20, 100, 30)
$idButton_2 = GUICtrlCreateButton("2", 100, 70, 100, 30)
$idButton_3 = GUICtrlCreateButton("3", 100, 120, 100, 30)

GUISetState()

; Set text by X/Y
Sleep(1000)
ControlSetText($hGUI, "", "[X:100; Y:20]", "Button_ONE")
Sleep(1000)
ControlSetText($hGUI, "", "[X:100; Y:70; W:100]", "Button_TWO")
Sleep(1000)
ControlSetText($hGUI, "", "[X:100; Y:120; W:100; H:30]", "Button_THREE")

Do
    Sleep(20)
Until GuiGetMsg() = -3

First two buttons get their text changed, the third does not. Hmmm.... :)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

PsaltyDS,

The difference between my scripts and yours are that mine are coded by a roomful of monkeys with dumb terminals. I'm surprised anything works, but darn if those suckers don't turn out something every year or two. :)

Seriously, though: thanks for the example on how to use this feature. It was/is very frustrating trying to nail down the syntax.

Zach...

Share this post


Link to post
Share on other sites

Well, they always have in MY scripts! :)

I do see an issue with the X/Y/W/H format. This demo works when specifying X/Y or X/Y/W, but not X/Y/W/H:

Global $hGUI = GUICreate("Test", 300, 200)

; Create 3 buttons
$idButton_1 = GUICtrlCreateButton("1", 100, 20, 100, 30)
$idButton_2 = GUICtrlCreateButton("2", 100, 70, 100, 30)
$idButton_3 = GUICtrlCreateButton("3", 100, 120, 100, 30)

GUISetState()

; Set text by X/Y
Sleep(1000)
ControlSetText($hGUI, "", "[X:100; Y:20]", "Button_ONE")
Sleep(1000)
ControlSetText($hGUI, "", "[X:100; Y:70; W:100]", "Button_TWO")
Sleep(1000)
ControlSetText($hGUI, "", "[X:100; Y:120; W:100; H:30]", "Button_THREE")

Do
    Sleep(20)
Until GuiGetMsg() = -3

First two buttons get their text changed, the third does not. Hmmm.... :)

Global $hGUI = GUICreate("Test", 300, 200)

; Create 3 buttons
$idButton_1 = GUICtrlCreateButton("1", 100, 20, 100, 30)
$idButton_2 = GUICtrlCreateButton("2", 100, 70, 100, 30)
$idButton_3 = GUICtrlCreateButton("3", 100, 120, 100, 30)

GUISetState()

; Set text by X/Y

ControlSetText($hGUI, "", "[X:100; Y:120; W:100 H:30 ]", "Button_THREE")
Sleep(1000)
ControlSetText($hGUI, "", "[X:100; Y:70; W:100 H:30 ]", "Button_TWO")
Sleep(1000)
ControlSetText($hGUI, "", "[X:100; Y:20; W:100 H:30]", "Button_ONE")
Sleep(1000)
Do
    Sleep(20)
Until GuiGetMsg() = -3

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

 

Share this post


Link to post
Share on other sites

Global $hGUI = GUICreate("Test", 300, 200)

; Create 3 buttons
$idButton_1 = GUICtrlCreateButton("1", 100, 20, 100, 30)
$idButton_2 = GUICtrlCreateButton("2", 100, 70, 100, 30)
$idButton_3 = GUICtrlCreateButton("3", 100, 120, 100, 30)

GUISetState()

; Set text by X/Y

ControlSetText($hGUI, "", "[X:100; Y:120; W:100 H:30 ]", "Button_THREE")
Sleep(1000)
ControlSetText($hGUI, "", "[X:100; Y:70; W:100 H:30 ]", "Button_TWO")
Sleep(1000)
ControlSetText($hGUI, "", "[X:100; Y:20; W:100 H:30]", "Button_ONE")
Sleep(1000)
Do
    Sleep(20)
Until GuiGetMsg() = -3
I think that works because the broken syntax makes the H: parameter get ignored altogether. Note that removing the semicolon makes that ID work even if the value for H: is way off:
ControlSetText($hGUI, "", "[X:100; Y:120; W:100 H:4096]", "Button_THREE")

It is matching based on X/Y/W and ignoring H, I believe.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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