Sign in to follow this  
Followers 0
ptrex

Add Button on external appl. (Control ID missing)

7 posts in this topic

I am trying to create a button on a legacy application using ANYGUI.

The button won't appear ??!!

I' ve tested the script creating a button on Windows Explorer, and this works fine.

When I use the AU3Info Tool to get the info of the legacy appl. I don' t see a CONTROL ID for any of the controls.

Only ClassnameNN and Text are available.

This is my problem that none of the Ctrls are having a Control ID.

Is there a workaround for this. To work using the ClassNameNN instead or maybe using a DLLCall routine ?

This is the working script for the Windows Explorer.

#include <ANYGUI.au3>
#include <guiconstants.au3>
Opt("WinTitleMatchMode", 4)
Opt("GUIOnEventMode", 1)

$appWindow = WinGetHandle("classname=ExploreWClass")

$Targetwindow = _GuiTarget($appWindow,"FolderView","",40960)
$btn = _TargetaddButton ( "Drawing", 740, 3, 80, 30,"","",$Targetwindow);
GUICtrlSetOnEvent($btn[0], "Clicked") 
GUISetState(@SW_SHOW)

_EndTarget() 

While WinExists($Targetwindow)
     Sleep(100)
      If Not WinExists($Targetwindow) Then
         Exit
      EndIf
WEnd

Func Clicked()
MsgBox(0,"TEST","OK")
EndFunc

Share this post


Link to post
Share on other sites



$Targetwindow = _GuiTarget($appWindow,"FolderView","",40960)

the above parameters aren't in the right order.

the parameter order is supposed to be: Title, Mode, Text, Controlid

as far as using ClassnameNN see the docs for Wingethandle() and Controlgethandle(). There is only one extra parameter between them. The Mode parameter simply determines whether the returned variable is either Local or Global in Scope.


[u]Do more with pre-existing apps![/u]ANYGUIv2.8

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

@quaizywabbit

Thanks for the info.

1. The parameter info was not correct, like you noticed. But it is working in both cases.

2. Second, I looked at the Wingethandle() and Controlgethandle(). But I can' t situate what it has to do with my problem.

I will explain a but further.

This is what I get from the AU3Info Tool. As you can see the CONTROL ID's are missing for any of the the control in that window. (This is not a Microsoft Appl.)

Class: TsShellWinClass

Size: X: 202 Y: 69 W: 767 H: 551

>>>>>>>>>>> Mouse Details <<<<<<<<<<<

Screen: X: 884 Y: 129

Cursor ID: 2

>>>>>>>>>>> Pixel Color Under Mouse <<<<<<<<<<<

RGB: Hex: 0xECE9D8 Dec: 15526360

>>>>>>>>>>> Control Under Mouse <<<<<<<<<<<

Size: X: 0 Y: 0 W: 759 H: 497

Control ID: MISSING

ClassNameNN: TsWinClass2

Text: DsCmwindow-5

Style: 0x56000000

ExStyle: 0x00000000

I wanted to add a button on one of those controls.

But when using your ANYGUI, I need a CONTROL ID to tell it on which control it should place the BUTTON.

Since I am missing the CONTROL ID's I can't get it to work, because your _GuiTarget() needs a CONTROL ID as a last parameter.

Maybe you can show me what to do in this case.

Thanks a lot.

Edited by ptrex

Share this post


Link to post
Share on other sites

@quaizywabbit

I've got it to work !!

Still I don't understand why, maybe you can explain me the background details.

This is the code.

$handle = ControlGetHandle("classname=TsShellWinClass", "DsCrowColumn", "TsWinClass10")
;MsgBox(0,"",$handle)

$Targetwindow = _GuiTarget($appWindow,"","",$handle)

As you suggested I added the ControlGetHandle() to get the HWND/Handle value. This variable $handle, I have put as a last parameter value for your function _GuiTarget().

This is not clear to me why it accepts the handle value instead of the CONTROL ID, as is mentioned in your function description.

Or is AutoIT always capable of working with the handle instead of the control ID ?

This is all new to me. So feedback would be much appreciated.

Anyhow, your function ANYGUI rocks !!! :lmao:

Share this post


Link to post
Share on other sites

Hi ptrex,

your code looks great. I will use it in excel but i've got a little problem.

I loose my focus. A workaround is a msgbox - but not very nice.

Can you help me?

Here is youre code with a german excel.

#include <ANYGUI.au3>
#include <guiconstants.au3>
Opt("WinTitleMatchMode", 4)
Opt("GUIOnEventMode", 1)

$appWindow = WinGetHandle("classname=XLMAIN")

$handle = ControlGetHandle("classname=XLMAIN", "", "EXCEL22")
;MsgBox(0,"",$handle)

$Targetwindow = _GuiTarget($appWindow,"","",$handle)

$btn = _TargetaddButton ( "Test Button", 800, 25, 80, 30,"","",$Targetwindow);
GUICtrlSetOnEvent($btn[0], "Clicked") 
GUISetState(@SW_SHOW)

_EndTarget() 

;WinActivate("Microsoft Excel - Mappe1", "")

$handle = ControlGetHandle("classname=XLMAIN", "", "XLDESK1")
$Targetwindow = _GuiTarget($appWindow,"","",$handle)
GUISetState(@SW_SHOW)
_EndTarget() 

;WinSetState("Microsoft Excel - Mappe1", "", @SW_ENABLE)
;ControlFocus("Microsoft Excel - Mappe1", "", "XLDESK1")
MsgBox(0,"Help Window","Just to get the focus back",2)
;Send ("^G")
;Send ("F5")
;Send ("{ENTER}")



While WinExists($Targetwindow)
     Sleep(100)
      If Not WinExists($Targetwindow) Then
         Exit
      EndIf
WEnd

Func Clicked()
MsgBox(0,"TEST","OK")
EndFunc

CU

Dizzy

Share this post


Link to post
Share on other sites

@Dizzy

This code works on my system.

Excel English version (Excel22 does not exist on my Excel, changed to 21)

Than I did some cleaning up of your code and run this one.

; Working example for EXCEL 2002 English version
; PTREX 04/02/2006

#include <ANYGUI.au3>
#include <guiconstants.au3>

Opt("WinTitleMatchMode", 4)
Opt("GUIOnEventMode", 1)

$appWindow = WinGetHandle("classname=XLMAIN")
$handle = ControlGetHandle("classname=XLMAIN", "", "EXCEL21")
WinWaitActive("")

$Targetwindow = _GuiTarget($appWindow,"","",$handle)

$btn = _TargetaddButton ( "Test Button", 800, 25, 80, 30,"","",$Targetwindow);
GUICtrlSetOnEvent($btn[0], "Clicked") 
GUISetState(@SW_SHOW)


While WinExists($Targetwindow)
     Sleep(100)
      If Not WinExists($Targetwindow) Then
         Exit
      EndIf
WEnd

Func Clicked()
    MsgBox(0,"TEST","OK")
EndFunc

Success !!

Share this post


Link to post
Share on other sites

@ptrex

yes - my focus is back!

I think i've to test, play and read a little more ...

Thanks for your help!

Dizzy

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
Sign in to follow this  
Followers 0