|
-
February 8th, 2000, 01:19 PM
#1
Controlling a application from VB
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?
-
February 8th, 2000, 04:24 PM
#2
Re: Controlling a application from VB
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
[email protected]
[email protected]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|