Public Type WINDOWPLACEMENT
Length As Long
flags As Long
showCmd As Long
ptMinPosition As POINTAPI
ptMaxPosition As POINTAPI
rcNormalPosition As RECT
End Type
Public Const SW_SHOWNORMAL = 1
Public Const SW_SHOWMINIMIZED = 2
Public Const SW_SHOWMAXIMIZED = 3
Public Const SW_SHOWNOACTIVATE = 4
Public Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Public Declare Function GetWindowPlacement Lib "user32" _
(ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long
Public Declare Function SetWindowPlacement Lib "user32" _
(ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long
Public Sub MinimizeWindow(sWindowTitle As String)
Dim hWndCtlApp As Long
Dim currWinP As WINDOWPLACEMENT
'obtain the handle to the control app
hWndCtlApp = FindWindow(vbNullString, sWindowTitle)
If hWndCtlApp Then
'prepare the WINDOWPLACEMENT type
currWinP.Length = Len(currWinP)
If GetWindowPlacement(hWndCtlApp, currWinP) > 0 Then
'determine the window state
If currWinP.showCmd <> SW_SHOWMINIMIZED Then
'minimized, so restore
currWinP.Length = Len(currWinP)
currWinP.flags = 0&
currWinP.showCmd = SW_SHOWMINIMIZED
Call SetWindowPlacement(hWndCtlApp, currWinP)
End If
End If
End If
End Sub
Copy the above into a new module, and save it (don't name the module
MinimizeWindow: modules cannot have the same name as routines within them)
When AdobeReader is open, its Window Title is (usually) something like
"Adobe Reader - [xxxx]", where xxxx is the name of the file. That means to
minimize the window, you'd use
Call MinimizeWindows("Adobe Reader - [MyFile.pdf]")
If you're not going to know what file is open, you can use the code in
http://www.mvps.org/access/api/api0013.htm to determine all windows
associated with Class AdobeAcrobat.
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
Ron said:
Hi,
I'm trying to minimize an open program from within MS Access.
For example, if I'm trying to minimize Adobe Reader by clicking an
Access form's button, how would I go about doing so?
Thanks for your help!
-Ron