Minimize Open Application from within MS Access?

R

Ron

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
 
L

Lynn Trapp

I'm not sure if you can do it after the external application is running, but
you can call the Shell() function which opens the application in minimized
state.

Dim RetVal
RetVal = Shell("C:\Program Files\Adobe\Acrobat 6.0\Acrobat\Acrobat.exe", 6)

The value of 6 in the Window state argument causes it to open minimized.
 
D

Douglas J. Steele

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.
 
R

Ron

Wow! Well, at least this seems to confirm that I didn't overlook some
straightforward method or function...

Thanks very much to both of you for your responses!

-Ron


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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top