如执行
a = shell("c:\abc.exe",VbMaximizedFocus)
以后窗口是最大化的,没错。但如果用户又把 abc.exe 的程序窗口最小化了,我想再在程序中放一个按钮,这个按钮要做的事是
再把 abc.exe 程序窗口变成当前窗口,并且把窗口最大化或还原大小。我想了一个办法用 AppActivate a
可以把窗口激活,但它不能把最小化的窗口最大化或还原。请教高手,如果窗口被用户最小化了,怎么再根据这个 a 的值来把窗口激活为当前窗口并使之最大化或还原呢?谢谢。我试了一起API不成功,请各位指点
a = shell("c:\abc.exe",VbMaximizedFocus)
以后窗口是最大化的,没错。但如果用户又把 abc.exe 的程序窗口最小化了,我想再在程序中放一个按钮,这个按钮要做的事是
再把 abc.exe 程序窗口变成当前窗口,并且把窗口最大化或还原大小。我想了一个办法用 AppActivate a
可以把窗口激活,但它不能把最小化的窗口最大化或还原。请教高手,如果窗口被用户最小化了,怎么再根据这个 a 的值来把窗口激活为当前窗口并使之最大化或还原呢?谢谢。我试了一起API不成功,请各位指点
楼主记得给分,俺穷!
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Const SW_SHOWDEFAULT = 10代码上面加:
ShowWindow abc.hwnd, SW_SHOWDEFAULT
楼主记得给分,俺穷!
Option ExplicitPrivate Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Long, ByVal lpWindowName As Long) As Long
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Const GW_HWNDNEXT = 2Function InstanceToWnd(ByVal target_pid As Long) As Long
Dim test_hwnd As Long, test_pid As Long, test_thread_id As Long
'Find the first window
test_hwnd = FindWindow(ByVal 0&, ByVal 0&)
Do While test_hwnd <> 0
'Check if the window isn't a child
If GetParent(test_hwnd) = 0 Then
'Get the window's thread
test_thread_id = GetWindowThreadProcessId(test_hwnd, test_pid)
If test_pid = target_pid Then
InstanceToWnd = test_hwnd
Exit Do
End If
End If
'retrieve the next window
test_hwnd = GetWindow(test_hwnd, GW_HWNDNEXT)
Loop
End Function
Private Sub Form_Load()
Dim Pid As Long
Dim mWnd As Long
'Execute notepad.Exe
Pid = Shell("notepad.exe", vbNormalFocus)'以调用记事本为例
If Pid = 0 Then MsgBox "Error starting the app"
'retrieve the handle of the window
mWnd = InstanceToWnd(Pid)
Debug.Print mWnd'mWnd即为所求的窗口句柄
End Sub
剩下的工作就是用ShowWindow调整窗口大小,这里我就不罗嗦了:)