PDA

View Full Version : VB & CreateProcess API


Sirber
1st February 2004, 20:18
Hi

I've found some tweak to be able to hide or minimize the created process, but it don't work:(. Am I doing something wrong?

' This file is part of RealAnime.
'
' RealAnime is free software; you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation; either version 2 of the License, or
' (at your option) any later version.
'
' RealAnime is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with RealAnime; if not, write to the Free Software
' Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessId As Long
dwThreadId As Long
End Type

Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
hHandle As Long, ByVal dwMilliseconds As Long) As Long

Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
lpApplicationName As Long, ByVal lpCommandLine As String, ByVal _
lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _
lpStartupInfo As STARTUPINFO, lpProcessInformation As _
PROCESS_INFORMATION) As Long

Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long

Private Const REALTIME_PRIORITY_CLASS = &H100&
Private Const HIGH_PRIORITY_CLASS = &H80&
Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const IDLE_PRIORITY_CLASS = &H40&
Private Const STILL_ACTIVE& = &H103&
Private Const INFINITE = -1&

Private Const SW_HIDE = 0
Private Const SW_SHOWNORMAL = 1
Private Const SW_NORMAL = 1
Private Const SW_SHOWMINIMIZED = 2
Private Const SW_SHOWMAXIMIZED = 3
Private Const SW_MAXIMIZE = 3
Private Const SW_SHOWNOACTIVATE = 4
Private Const SW_SHOW = 5
Private Const SW_MINIMIZE = 6
Private Const SW_SHOWMINNOACTIVE = 7
Private Const SW_SHOWNA = 8
Private Const SW_RESTORE = 9
Private Const SW_SHOWDEFAULT = 10
Private Const SW_MAX = 10

Public Function ExecCmd(cmdline$, priority, newwindowstatus)
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO

Dim prio As Variant
Dim newW As Variant

start.cb = Len(start)
start.dwFlags = STARTF_USESHOWWINDOW

' Process priority
Select Case priority
Case 0:
prio = IDLE_PRIORITY_CLASS
Case 1:
prio = NORMAL_PRIORITY_CLASS
Case 2:
prio = HIGH_PRIORITY_CLASS
Case 3:
prio = REALTIME_PRIORITY_CLASS
End Select

' New window?
Select Case newwindowstatus
Case 0:
start.wShowWindow = SW_HIDE
Case 1:
start.wShowWindow = SW_HIDE
Case 2:
start.wShowWindow = SW_SHOWNOACTIVATE
End Select

' Start the process
ret& = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, prio, 0&, 0&, start, proc)

GetExitCodeProcess proc.hProcess, ret&
Do While ret& = STILL_ACTIVE&
DoEvents
GetExitCodeProcess proc.hProcess, ret&
DoEvents
Sleep (100)
Loop
Call CloseHandle(proc.hThread)
Call CloseHandle(proc.hProcess)
ExecCmd = ret&
End FunctionThanks!!! :D

stax76
1st February 2004, 20:47
VB6 :scared:

you want to minimize a window of a external application that is already running? You need the window api for this, I do this in DVX with a class called WinAPI

Sirber
1st February 2004, 20:49
Yep, I want to minimize (or hide) a process (window) that I created. I use VB6 for RealAnime, I know it's crappy but RealAnime is old also :)

Sirber
1st February 2004, 21:01
got it

Private Const STARTF_USESHOWWINDOW = &H1

this was missing... :rolleyes: sorry!!! :D