mbennett
February 8th, 2000, 12:19 PM
I need to know how to control an application from VB. I allready know how to start the application
using the Shell function. However, the VB Program I am running will hide the application in the back
ground if minamized.How can I maxamize and or close the application from VB?
Aaron Young
February 8th, 2000, 03:24 PM
You can use a couple of APIs to Compare ProcessID's until you find a Match, ie.
'In a Module..
private Declare Function GetWindowThreadProcessId Lib "user32" (byval hwnd as Long, lpdwProcessId as Long) as Long
private Declare Function EnumWindows Lib "user32" (byval lpEnumFunc as Long, byval lParam as Long) as Long
private lHwnd as Long
private Function EnumWindowProc(byval hwnd as Long, byval lParam as Long) as Long
Dim lProcessID as Long
Call GetWindowThreadProcessId(hwnd, lProcessID)
If lProcessID = lParam then
lHwnd = hwnd
else
EnumWindowProc = hwnd
End If
End Function
public Function GetProcessIDWindow(byval ProcessID as Long) as Long
lHwnd = 0
Call EnumWindows(AddressOf EnumWindowProc, ProcessID)
GetProcessIDWindow = lHwnd
End Function
Then use the ShowWindow() API to Change the Windows State, ie.
'In a Form..
private Declare Function ShowWindow Lib "user32" (byval hwnd as Long, byval nCmdShow as Long) as Long
private Const SW_HIDE = 0
private Const SW_MAXIMIZE = 3
private Const SW_MINIMIZE = 6
private Const SW_NORMAL = 1
private Const SW_RESTORE = 9
private Sub Command1_Click()
Dim lHwnd as Long
lHwnd = GetProcessIDWindow(Shell("Notepad.exe", vbHide))
Call ShowWindow(lHwnd, SW_RESTORE)
End Sub
Aaron Young
Analyst Programmer
ajyoung@pressenter.com
aarony@redwingsoftware.com