/ Forside / Teknologi / Udvikling / VB/Basic / Nyhedsindlæg
Login
Glemt dit kodeord?
Brugernavn

Kodeord


Reklame
Top 10 brugere
VB/Basic
#NavnPoint
berpox 2425
pete 1435
CADmageren 1251
gibson 1230
Phylock 887
gandalf 836
AntonV 790
strarup 750
Benjamin... 700
10  tom.kise 610
A active program !
Fra : Bertman


Dato : 07-10-01 13:34

Hello,

I have to make a program that checks if a program is active. For example: My
program starts Calc.exe, and my program have to check every 10sec if
calc.exe is still active. And when you close Calc.exe then de VB program
have to give a message.

But I don't know how to check if calc.exe is active.
I'm using VB 6.0 with SP5

Bertman



 
 
Mike Labosh (08-10-2001)
Kommentar
Fra : Mike Labosh


Dato : 08-10-01 20:35

You use the FindWindow API function to get the window handle of the window
you want. Then you call GetWindow in a loop until it returns 0, then you
know the other window has been closed:

lHwnd = FindWindow(...)

While GetWindow(...) <> 0
DoEvents
Wend

In your case, if you wish to poll every x seconds, you can put the above
code in the timer event of a control and modify it so that it does something
else when the window disappears, or you could call the Sleep API function
instead of DoEvents.

--
Peace and happy computing,

Mike Labosh, MCP, MCT, MCSD
"Hit any user to continue."
"Bertman" <Bertman@home.nl> wrote in message
news:K%Xv7.21236$fo2.2748250@zwoll1.home.nl...
> Hello,
>
> I have to make a program that checks if a program is active. For example:
My
> program starts Calc.exe, and my program have to check every 10sec if
> calc.exe is still active. And when you close Calc.exe then de VB program
> have to give a message.
>
> But I don't know how to check if calc.exe is active.
> I'm using VB 6.0 with SP5
>
> Bertman
>
>



Karsten Röttger (09-10-2001)
Kommentar
Fra : Karsten Röttger


Dato : 09-10-01 13:29

'Deklarationen zum Kontrollieren, ob ein Task (Finder) noch läuft
'Deklarations for controlling
Private Declare Function CloseHandle Lib "kernel32" (ByVal _
hObject As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal _
dwDesiredAccess As Long, ByVal bInheritHandle As _
Long, ByVal dwProcessId As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" _
(ByVal hProcess As Long, lpExitCode As Long) As Long

Private Const STILL_ACTIVE = &H103
Private Const PROCESS_ALL_ACCESS = &H1F0FFF

'Enthält die TaskID des Empfangprogramms
'Contains the taskID
Private TaskIDFinder As Double

Private Const cfinder = "C:\Support\Finder.exe"


'controlling code in Timer Event
If Not IsActiveFinder Then
TaskIDFinder = Shell(cfinder, vbNormalFocus)
End If

'Kontrolliert, ob Finder noch läuft
'Controls, if finder still active
Private Function IsActiveFinder() As Boolean
Dim Handle&, ExitCode&
Handle = OpenProcess(PROCESS_ALL_ACCESS, False, TaskIDFinder)
Call GetExitCodeProcess(Handle, ExitCode)
Call CloseHandle(Handle)
IsActiveFinder = IIf(ExitCode = STILL_ACTIVE, True, False)
End Function

--
Gruss
Karsten

- Ideen aus Folie -
http://www.cd-design.de

Bertman <Bertman@home.nl> schrieb in im Newsbeitrag:
K%Xv7.21236$fo2.2748250@zwoll1.home.nl...
> Hello,
>
> I have to make a program that checks if a program is active. For example:
My
> program starts Calc.exe, and my program have to check every 10sec if
> calc.exe is still active. And when you close Calc.exe then de VB program
> have to give a message.
>
> But I don't know how to check if calc.exe is active.
> I'm using VB 6.0 with SP5
>
> Bertman
>
>



Søg
Reklame
Statistik
Spørgsmål : 177558
Tips : 31968
Nyheder : 719565
Indlæg : 6408887
Brugere : 218888

Månedens bedste
Årets bedste
Sidste års bedste