Arkadaşlar VB& ile hazırladığım bir programda başka bir programı çalıştırıyorum.Ancak bu programın çalışması esnasında ana programın devre dışı kalıp,çalışan programın işi bitip kapandığında tekrar aktif olmasını istiyorum.Hide-Show ya da Visible ayarı denedim olmadı.En sonunda aşağıdaki kodları buldum.
Option Explicit
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Const SYNCHRONIZE = &H100000
Private Const INFINITE = -1&
' Start the indicated program and wait for it
' to finish, hiding while we wait.
Private Sub ShellAndWait(ByVal program_name As String, ByVal window_style As VbAppWinStyle)
Dim process_id As Long
Dim process_handle As Long
' Start the program.
On Error GoTo ShellError
process_id = Shell(program_name, window_style)
On Error GoTo 0
' Hide.
Me.Visible = False
DoEvents
' Wait for the program to finish.
' Get the process handle.
process_handle = OpenProcess(SYNCHRONIZE, 0, process_id)
If process_handle <> 0 Then
WaitForSingleObject process_handle, INFINITE
CloseHandle process_handle
End If
' Reappear.
Me.Visible = True
Exit Sub
ShellError:
MsgBox "Error starting task " & _
txtProgram.Text & vbCrLf & _
Err.Description, vbOKOnly Or vbExclamation, _
"Error"
End Sub
' Start the program.
Private Sub cmdRun_Click()
ShellAndWait [b]ÇALIŞANPROGRAM[/b], vbNormalFocus
End Sub
Fakat bu kezde şöyle bir sorunla karşılaştım.
Ben programımı çalıştırırken;
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Sub Command2_Click()
ShellExecute 0, "", "VirtualDubMod.exe", "/r /s""addaudio.vcf"" /x", "", 1
End Sub
kod grubunu kullanıyorum.Üstte yazdığım kodla uyumunu bir türlü sağlayamadım.Bu konuda yardımcı olabilirseniz sevinirim.