Sign in to follow this  
Followers 0
Frank_O

Hide and Show: $pid vs. $handle

3 posts in this topic

Hi all,

I want to run a dos-script (with an endless lopp) and make it visible or hide it from time to time.

I don't want to use the window-title, because it's the same as @comspec and there could exist more than 1 process with that name ...

Can't I use the PID? Or is there a way to get the WinHandle of that PID?

thanks in advance

frank

CODE
#comments-start

rem loop.cmd

@echo off

if not exist sleep.exe goto end

:loop

echo %time%

sleep 1

goto loop

:end

#comments-end

$pid = Run(@ComSpec & " /c " & 'loop.cmd')

; , "", @SW_HIDE

$rc = ProcessWait( $pid, 5 )

If $rc = 1 Then

MsgBox( 0, "Info", "loop.cmd was stated. PID=" & $pid, 5 )

Else

MsgBox( 0, "Info", "loop.cmd could not be started")

Exit

EndIf

sleep( 5000 )

WinSetState( $pid, "", @SW_HIDE )

msgbox( 0, "Info", "Window is hiden" )

sleep( 5000 )

WinSetState( $pid, "", @SW_SHOW )

msgbox( 0, "Info", "Window is shown again" )

Share this post


Link to post
Share on other sites



added some code to retrieve the Window Handle that belongs to the ran PID which enables you to use that in stead of the title:

#comments-start
    rem loop.cmd
    @echo off
    if not exist sleep.exe goto end
    :loop
    echo %time%
    sleep 1
    goto loop
    :end
#comments-end
$pid = Run(@ComSpec & ' /k Dir *.*')
; , "", @SW_HIDE
$rc = ProcessWait($pid, 5)
; get window handle
$wintitle = ""
$WinHnd = 0
$list = WinList()
for $i = 1 to $list[0][0]
    If $list[$i][0] = "" Then ContinueLoop
    If WinGetProcess($list[$i][0]) = $pid Then
        $winTitle = $list[$i][0]
        $WinHnd = $list[$i][1]
        ExitLoop
    EndIf
next
;
If $rc = 1 Then
    MsgBox(0, "Info", "loop.cmd was stated. PID=" & $pid, 5)
Else
    MsgBox(0, "Info", "loop.cmd could not be started")
    Exit
EndIf
Sleep(5000)
WinSetState($WinHnd, "", @SW_HIDE)
MsgBox(0, "Info", "Window is hiden")
Sleep(5000)
WinSetState($WinHnd, "", @SW_SHOW)
MsgBox(0, "Info", "Window is shown again")

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Hi Jos,

thank you, now it's clear :D

Just combining winlist with wingetprocess ...

frank

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