How to check that Adobe Application is running (1 Viewer)

darbid

Registered User.
Local time
Today, 07:40
Joined
Jun 26, 2008
Messages
1,428
I have links to pdf documents. The PDFs are stored on a network drive which means that the time from click to seeing a PDF document can vary. Plus during this waiting time nothing appears to be happening in the form.

Can someone tell me how I can check with VBA if the adobe application is open. Or maybe what event occurs on the form once the adobe application window comes up over the top of the access form?

Thanks in advance.
 
Local time
Today, 00:40
Joined
Mar 4, 2008
Messages
3,856
To begin with, look at AppActivate() and SendKeys()...I have no idea whether either of them will work for your needs. The way you could tell if the app is running in this scenario is whether you get an error or not. If a call to either of those created an error (which you would handle and use to "find out"), then they wouldn't be running (in theory).

I'm sure there are better ways, just nobody answered you and I didn't want to leave you hanging.
 

darbid

Registered User.
Local time
Today, 07:40
Joined
Jun 26, 2008
Messages
1,428
To begin with, look at AppActivate() and SendKeys()...

Thanks for the reply. I had found AppActivte(), but did not really understand it, nor if it was exactly what I needed and nobody had an example of it with Adobe so I was hoping for a little spoon feeding.

Now it looks like I will have to work it out myself. At least I know that I am using the right things. :D

Thanks
 
Local time
Today, 00:40
Joined
Mar 4, 2008
Messages
3,856
I don't know if it will work but I imagine if you try to activate an application that is not there, you will get an error. Just trap the error (in On Error Go To) and you know that the app isn't in memory.

I'm pretty sure there's a Windows API call that would be able to give you that information. Since I never do Windows programming, instead preferring the Access realm, I don't have the API documentation handy.
 

darbid

Registered User.
Local time
Today, 07:40
Joined
Jun 26, 2008
Messages
1,428
almost solved

thanks a million for going that extra step. my google search were not as good as yours.

for anyone who has stumbled across this thread here is what I have done. I have put this code into a module.

Code:
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long
 
Function AdobeUp()
         Const lpClassName = "Acrobat"
         Const lpCaption = "Adobe Acrobat Standard"
         'This demonstrates three different ways to call FindWindow:
            '1. The ClassName only.
            '2. The Caption only.
            '3. Both the ClassName and the Caption
            'NOTE: When using Access 2.0, the value 0& must be used to
            '      pass a null string to the FindWindow function rather
            '      than the constant VBNullString.  For Example:
            '      FindWindow(lpClassName, 0&)
         MsgBox "Adobe Handle = " & FindWindow(lpClassName, vbNullString)
         MsgBox "Adobe Handle = " & FindWindow(vbNullString, lpCaption)
         MsgBox "Adobe Handle = " & FindWindow(lpClassName, lpCaption)
         'This function could return the handle of a window.
         AdobeUp = FindWindow(lpClassName, 0&)
      End Function

Please note that the above does not fully work as I have guessed the class name and caption for adobe.

If I test it, I only get a result (when adobe is open) from the caption name. I simply took the name that my adobe has from the task bar when it is open. But this can be different names depending on what adobe you have. I also do not have the Class name which I hope does not change depending on versions.

So does anybody know the windows class name for Adobe. I do not have the developers kit from windows and that spy.exe program. I know there are other ways but if somebody already knows it then great.
 
Last edited:

ErikSnoek

Programmer
Local time
Yesterday, 22:40
Joined
Apr 26, 2007
Messages
100
I checked out Adobe Reader 8 with spy++ and found class name "AcrobatSDIWindow" and caption "Adobe Reader". Give it a try, might work for you :)
 

darbid

Registered User.
Local time
Today, 07:40
Joined
Jun 26, 2008
Messages
1,428
Thanks Erik,

That did not work for me, but I am guessing that the problem is that the windows class for the adobe reader is different to a full version of adobe acrobat (which is what I have).

It appears the caption is simply the name of the program that is placed in your tool bar at the bottom of your windows desktop when the program is open.

Guys i am way out of my depth here. I am wondering how can I change my code so that it could deal with two or three different captions. Then I could simple use this for all the different captions that adobe could have.

I just found out something that I find interesting the Ipcaption returns 0 if adobe is not open AND if adobe was opened before you start Access.
 
Last edited:

ErikSnoek

Programmer
Local time
Yesterday, 22:40
Joined
Apr 26, 2007
Messages
100
Well here's a way to find the class. Create a new module, put all this code in it, open your Adobe application and run the sub fEnumWindows
Code:
Public Const MAX_PATH = 260
Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
 
Public Function fEnumWindowsCallBack(ByVal hwnd As Long, ByVal lpData As Long) As Long
    Dim lResult    As Long
    Dim sWndName   As String
    Dim sClassName As String
    Dim objFileSys As Object, objTextFile As Object
    fEnumWindowsCallBack = 1
    sClassName = Space$(MAX_PATH)
    sWndName = Space$(MAX_PATH)
 
    lResult = GetClassName(hwnd, sClassName, MAX_PATH)
    sClassName = Left$(sClassName, lResult)
    lResult = GetWindowText(hwnd, sWndName, MAX_PATH)
    sWndName = Left$(sWndName, lResult)
    If sWndName <> "" Then
        Set objFileSys = CreateObject("Scripting.FileSystemObject")
        Set objTextFile = objFileSys.OpenTextFile("c:\windows\temp\temptext.txt", 8, True)
        objTextFile.Write "Caption: " & sWndName & vbCrLf & "Class:" & sClassName & vbCrLf & vbCrLf
        objTextFile.Close
    End If
End Function
 
Public Sub fEnumWindows()
    Dim hwnd As Long
    Call EnumWindows(AddressOf fEnumWindowsCallBack, hwnd)
    Shell "notepad " & "c:\windows\temp\temptext.txt", vbNormalFocus
    Kill "c:\windows\temp\temptext.txt"
 
End Sub
 

darbid

Registered User.
Local time
Today, 07:40
Joined
Jun 26, 2008
Messages
1,428
Thanks for that.

So for my computer my

Classname is AdobeAcrobat
Caption is Adobe Acrobat Standard

I have not been able to test this on a computer with only a reader yet.
 

Users who are viewing this thread

Top Bottom