Sign in to follow this  
Followers 0
StSchnell

Problems with WinMove after ControlClick

6 posts in this topic

Hello community,

I am new at AutoIt and now I have a question about the following code in vb script:

Const WindowTitle = "Test"
  Const ClassName = "HH Parent"

  Dim oAutoIt
  Set oAutoIt = CreateObject("AutoItX3.Control")

Sub view_onclick()
  Dim Title
  Title = "[TITLE:" & WindowTitle & "; CLASS:" & ClassName & "]"
  Dim XPos, YPos, Width, Height
  XPos = oAutoIt.WinGetPosX(Title)
  YPos = oAutoIt.WinGetPosY(Title)
  Width = oAutoIt.WinGetPosWidth(Title)
  Height = oAutoIt.WinGetPosHeight(Title)
  If oAutoIt.ControlCommand(Title, "", "SysTabControl321", "IsVisible", "") Then
    oAutoIt.ControlClick(Title, "", "ToolbarWindow321", "left", 1, 10, 10)
    oAutoIt.WinMove Title, "", XPos, YPos, Width, Height
  Else
    oAutoIt.ControlClick(Title, "", "ToolbarWindow321", "left", 1, 10, 10)
  End If
End Sub

All works well, but not the WinMove command. If I set a MsgBox command between ControlClick and WinMove it works. Is there a command to take a DoEvents, a ReDraw or something else to bring the program to a ControlClick and then to move the window?

Thanks for tips.

Cheers

Stefan

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hello community,

a small addition:

;-Begin-----------------------------------------------------------------

;-Constants-------------------------------------------------------------
  Const $WindowTitle = "Test5"
  Const $ClassName = "HH Parent"
  
;-Variables-------------------------------------------------------------
  Dim $Title
  $Title = "[TITLE:" & $WindowTitle & "; CLASS:" & $ClassName & "]"
    
;-Function IsTabControlVisible------------------------------------------
  Func IsTabControlVisible()
    Return ControlCommand($Title, "", "SysTabControl321", "IsVisible") 
  EndFunc
    
;-Function ShowTabControl-----------------------------------------------
  Func ShowTabControl()
    Return ControlClick($Title, "", "ToolbarWindow321", "left", 1, _
      10, 10)
  EndFunc  

;-Procedure main--------------------------------------------------------
  Func main()
    Dim $Size
    $Size = WinGetPos($Title)
    If IsTabControlVisible() Then
      ShowTabControl()
      WinMove($Title, "", $Size[0], $Size[1], $Size[2], $Size[3])
    Else
      ShowTabControl()
    EndIf
  EndFunc
    
;-Main------------------------------------------------------------------
  main()    

;-End-------------------------------------------------------------------

I check the function with an external AutoIt program and all works well. I do not know the difference between the ActiveX from AutoIt and the program, any ideas?

Thanks for tips.

Cheers

Stefan [21.12.2008]

Edited by StSchnell

Share this post


Link to post
Share on other sites

After Controlclick you should check the result (winactive, winclose,, ...)

or at least give the programm time to wait on event with

WScript.Sleep 1000

HTH, Reinhard

Share this post


Link to post
Share on other sites

Hello Reinhard,

thanks for your tip.

I checked WinWaitActive and Sleep from AutoIt and both do not work. WScript.Sleep also do not work, because I use VBScript in a HTML site. It is not possible to use methods of the WScript object in VBScript in a HTML site, specifically Sleep.

Now I solve the problem with the following vb script:

'-Begin-----------------------------------------------------------------

Option Explicit

'-Procedure Sleep-------------------------------------------------------
  Sub Sleep()
    Dim Arg
    Set Arg = WScript.Arguments
    WScript.Sleep CInt(Arg(0))
  End Sub
    
'-Main------------------------------------------------------------------
  Sleep()  

'-End-------------------------------------------------------------------

I call this script file with this function:

'-Sleep-----------------------------------------------------------------
  Function Sleep(Time)
    Dim Path
    Path = GetActualPath()
    Sleep = oShell.Run(Path & "\Sleep.vbs " & Time, 0, true)
  End Function

Now, after a CommandClick, I call

Sleep 1

and all works well.

Cheers

Stefan

Share this post


Link to post
Share on other sites

I remember that I've had a similar problem with a HTA script, where also WScript.sleep don't work.

I looked for an older script. The solution was to setTimeOut:

While not WshShell.AppActivate("Adobe Acrobat") : setTimeout "Wait()",5000 : Wend

....

....

sub Wait : end sub

That should work, but my HTA knowledge is a little bit rusty.

Best regards, Reinhard

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