Jump to content

Recommended Posts

Posted

I'm trying to create a function to open a file and then set its window on top, but at the moment my code has various limits (it needs to know the window title instead of automatically detects it and uses a single sleep function to wait the window opening instead of wait it in some way).

Func __ShellExecuteOnTop($sFilePath, $sText, $sWait = 0)
    #cs
        Description: Open A File With Default Program And Set It On Top.
        Returns: Nothing
    #ce
    ShellExecute($sFilePath)
    Sleep(800)
    WinSetOnTop($sText, "", 1)
    While $sWait
        Sleep(80)
    WEnd
EndFunc   ;==>__ShellExecuteOnTop

Do you know a better solution for it? thanks!

 

SFTPEx, AutoCompleteInput_DateTimeStandard(), _ImageWriteResize()_GUIGraduallyHide(): some AutoIt functions.

Lupo PenSuite: all-in-one and completely free selection of portable programs and games.

DropIt: a personal assistant to automatically manage your files.

ArcThemALL!: application to multi-archive your files and folders.

  • Moderators
Posted

Lupo73,

A quick way to do this which works for me: ;)

; Get current win list
$aOldWinList = WinList()

ShellExecute("M:\Program\Au3 Scripts\Texts\Test.txt")

Do
    Sleep(100)
    ; Get new win list
    $aNewWinList = WinList()
    ; Wait until new windows are created
Until $aNewWinList[0][0] <> $aOldWinList[0][0]
; Allow time for the system to settle 
Sleep(100)
; Get handle of active window
$hWnd = WinGetHandle("[ACTIVE]")

; Just to prove it is the correct handle
Sleep(1000)
WinSetState($hWnd, "", @SW_MAXIMIZE)
Sleep(1000)
WinSetState($hWnd, "", @SW_RESTORE)
Does it work for you? :huh:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted (edited)

It works, thanks!

Now the only problem in the following updated code is that the "wait" mode doesn't work. Any idea?

Func __ShellExecuteOnTop($sFilePath, $sText, $sWait = 0)
    #cs
        Description: Open A File With Default Program And Set It On Top.
        Returns: Nothing
    #ce
    Local $hWnd, $aNewWinList, $aOldWinList = WinList()

    ShellExecute($sFilePath)
    Do
        Sleep(100)
        $aNewWinList = WinList()
    Until $aNewWinList[0][0] <> $aOldWinList[0][0]
    Sleep(100)
    WinSetOnTop("[ACTIVE]", "", 1)
    If $sWait Then
        WinWaitClose("[ACTIVE]")
    EndIf
EndFunc   ;==>__ShellExecuteOnTop

Edit: WinWaitClose is wrong, I replaced it with WinWait but it still doesn't work (I think the problem is using [ACTIVE]).

Edited by Lupo73

SFTPEx, AutoCompleteInput_DateTimeStandard(), _ImageWriteResize()_GUIGraduallyHide(): some AutoIt functions.

Lupo PenSuite: all-in-one and completely free selection of portable programs and games.

DropIt: a personal assistant to automatically manage your files.

ArcThemALL!: application to multi-archive your files and folders.

  • Moderators
Posted

Lupo73,

In that code you are waiting for a window whose title is [ACTIVE] so little wonder it does not work. :(

You missed the line where you get the window handle: ;)

$hWnd = WinGetHandle("[ACTIVE]") ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
WinSetOnTop($hWnd, "", 1)
If $sWait Then
    WinWaitClose($hWnd)
EndIf
That will work - it does for me. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted (edited)

Currently I'm using autoit 3.3.8.1 and the help for WinSetOnTop() doesn't report that is possible to use Handle :> (I saw online that the new help describes it). It works perfectly, thanks!

Updated code (if someone would like to use it):

Func __ShellExecuteOnTop($sFilePath, $sWait = 0)
    #cs
        Description: Open A File With Default Program And Set It On Top.
        Returns: Nothing
    #ce
    Local $hWnd, $aNewWinList, $aOldWinList = WinList()

    ShellExecute($sFilePath)
    Do
        Sleep(100)
        $aNewWinList = WinList()
    Until $aNewWinList[0][0] <> $aOldWinList[0][0]
    Sleep(100)
    $hWnd = WinGetHandle("[ACTIVE]")
    WinSetOnTop($hWnd, "", 1)
    If $sWait Then
        WinWaitClose($hWnd)
    EndIf
EndFunc   ;==>__ShellExecuteOnTop
Edited by Lupo73

SFTPEx, AutoCompleteInput_DateTimeStandard(), _ImageWriteResize()_GUIGraduallyHide(): some AutoIt functions.

Lupo PenSuite: all-in-one and completely free selection of portable programs and games.

DropIt: a personal assistant to automatically manage your files.

ArcThemALL!: application to multi-archive your files and folders.

  • Moderators
Posted

Lupo73,

 

  Quote

I'm using autoit 3.3.8.1

Then open the Help file at <Using AutoIt - Window Titles and Text (Advanced)> and scroll down to the "Window Handles/HWNDs" section. You will see this:

 

"When you have a handle you may use it in place of the title parameter in any of the function calls that use the title/text convention"

And this has been true for as long as I have been using AutoIt. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted
  On 1/5/2014 at 12:09 PM, Lupo73 said:

 

Currently I'm using autoit 3.3.8.1 and the help for WinSetOnTop() doesn't report that is possible to use Handle :> (I saw online that the new help describes it). It works perfectly, thanks!

 

So consider using the current version 3.3.10.2
The documentation in this version is much more extended (As noticed in the OnLine version).
 
Regards
mlipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

ShellExecute() returns the PID, so you could use this to determine the handle (search Help file) and work from their.

This is for V3.3.10.0 and above though.

Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

  • Moderators
Posted

Hi,

I am feeling generous after lunch: :)

#include <WinAPIProc.au3>
#include <Array.au3>
; Get PID
$iPID = ShellExecute("M:\Program\Au3 Scripts\Texts\pragma.txt")
; Allow window to be created
Sleep(100)
; Get list of visible windows assoicated with that PID
$aData = _WinAPI_EnumProcessWindows($iPID, 1)
; And here they are
_ArrayDisplay($aData, "", Default, 8)
; If there is just the one
If $aData[0][0] = 1 Then
    ; Get the handle
    $hWnd = $aData[1][0]
EndIf
; Just to prove it is the correct handle
Sleep(1000)
WinSetState($hWnd, "", @SW_MAXIMIZE)
Sleep(1000)
WinSetState($hWnd, "", @SW_RESTORE)
M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

  On 1/5/2014 at 3:06 PM, Melba23 said:

Hi,

I am feeling generous after lunch: :)

#include <WinAPIProc.au3>
#include <Array.au3>
; Get PID
$iPID = ShellExecute("M:\Program\Au3 Scripts\Texts\pragma.txt")
; Allow window to be created
Sleep(100)
; Get list of visible windows assoicated with that PID
$aData = _WinAPI_EnumProcessWindows($iPID, 1)
; And here they are
_ArrayDisplay($aData, "", Default, 8)
; If there is just the one
If $aData[0][0] = 1 Then
    ; Get the handle
    $hWnd = $aData[1][0]
EndIf
; Just to prove it is the correct handle
Sleep(1000)
WinSetState($hWnd, "", @SW_MAXIMIZE)
Sleep(1000)
WinSetState($hWnd, "", @SW_RESTORE)
M23

Yeah, like that. Thanks M23. I wasn't feeling so generous today -_0

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

Thanks! This solution is even stronger than the previous one  :thumbsup:

You are right mlipok, that is the plan soon. I didn't update it yet because with the last beta versions there was a problem using Copy UDF under Windows 8 64bit. I'll do more tests to verify it.

SFTPEx, AutoCompleteInput_DateTimeStandard(), _ImageWriteResize()_GUIGraduallyHide(): some AutoIt functions.

Lupo PenSuite: all-in-one and completely free selection of portable programs and games.

DropIt: a personal assistant to automatically manage your files.

ArcThemALL!: application to multi-archive your files and folders.

Posted (edited)
  On 1/5/2014 at 6:36 PM, Lupo73 said:

You are right mlipok, that is the plan soon. I didn't update it yet because with the last beta versions there was a problem using Copy UDF under Windows 8 64bit. I'll do more tests to verify it.

Was there? We did try to minimise on script breaking changes and those that were introduced were documented anyway. Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted
  On 1/5/2014 at 6:36 PM, Lupo73 said:

Thanks! This solution is even stronger than the previous one  :thumbsup:

You are right mlipok, that is the plan soon. I didn't update it yet because with the last beta versions there was a problem using Copy UDF under Windows 8 64bit. I'll do more tests to verify it.

 

You've been using the beta version. You had problems with that version.
 
Why you do not ask right away ?

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

  On 1/5/2014 at 6:46 PM, mlipok said:

You've been using the beta version. You had problems with that version.

 

Why you do not ask right away ?

From my understanding of being in the game for sometime, people feel reluctant to post bug reports on beta releases as they believe the issue will be fixed once the product is declared stable. Though this isn't always the case, if no one reports the issue then how is Jon (a Dev) or such-like supposed to fix said issue.

Another problem is getting people to beta test during the beta stage, as they see "beta" and instantly decide I will wait till the product is "stable". If the reason is they feel the product is a lot more stable once a product is out of beta, then without beta testers it's unlikely to be the case. It's quite logical really.

Note: This is a general comment about software development.

Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted (edited)

I reported and discussed the problem in a private message with wraithdu, UEZ and Yashied (that develops the UDF). The problem was detected in Copy_x64.dll and I thought the fix was planned for a next update (now I'll verify it). I moved back to the previous stable release to be able to publish a stable version of the software.  :)

ps: guinness, I'm agreed with you, tests in beta stage are essential for development.

Edited by Lupo73

SFTPEx, AutoCompleteInput_DateTimeStandard(), _ImageWriteResize()_GUIGraduallyHide(): some AutoIt functions.

Lupo PenSuite: all-in-one and completely free selection of portable programs and games.

DropIt: a personal assistant to automatically manage your files.

ArcThemALL!: application to multi-archive your files and folders.

Posted

A note about __ShellExecuteOnTop(): the previous solution that uses window handles works also with folders, while the new one with process IDs fails.

I made this combined function to bypass the issue, do you think is a bad solution?

Func __ShellExecuteOnTop($sFilePath, $sWait = 0)
    #cs
        Description: Open A File With Default Program And Set It On Top.
        Returns: Nothing
    #ce
    Local $iPID, $aData, $hWnd, $aNewWinList, $aOldWinList = WinList()

    $iPID = ShellExecute($sFilePath)
    If $iPID <> -1 Then
        Sleep(100)
        $aData = _WinAPI_EnumProcessWindows($iPID, 1)
        If $aData[0][0] = 1 Then
            $hWnd = $aData[1][0]
        EndIf
    Else
        Do
            Sleep(100)
            $aNewWinList = WinList()
        Until $aNewWinList[0][0] <> $aOldWinList[0][0]
        Sleep(100)
        $hWnd = WinGetHandle("[ACTIVE]")
    EndIf
    WinSetOnTop($hWnd, "", 1)
    If $sWait Then
        WinWaitClose($hWnd)
    EndIf
EndFunc   ;==>__ShellExecuteOnTop

SFTPEx, AutoCompleteInput_DateTimeStandard(), _ImageWriteResize()_GUIGraduallyHide(): some AutoIt functions.

Lupo PenSuite: all-in-one and completely free selection of portable programs and games.

DropIt: a personal assistant to automatically manage your files.

ArcThemALL!: application to multi-archive your files and folders.

Posted

If it works then use it.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

OK. Unfortunately about the Copy library, UEZ tested the updated code and it still crashes. I'll report it in the UDF topic.

SFTPEx, AutoCompleteInput_DateTimeStandard(), _ImageWriteResize()_GUIGraduallyHide(): some AutoIt functions.

Lupo PenSuite: all-in-one and completely free selection of portable programs and games.

DropIt: a personal assistant to automatically manage your files.

ArcThemALL!: application to multi-archive your files and folders.

Posted
  On 1/5/2014 at 11:44 PM, Lupo73 said:

OK. Unfortunately about the Copy library, UEZ tested the updated code and it still crashes. I'll report it in the UDF topic.

OK.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...