How to Open Single Instance of Program

D

Davy

I have been using Dev Ashish's code which uses ShellExcute (see below) to
open the registered jpg program which in my case is IrfanView. But each
time it runs it opens a new instance of IrfanView. This is inconvenient
since I am viewing more than 200 images by clicking on a thumbnail in an
Access 2000 database. Can anybody guide a VBA novice like myself on how to
change this code to open a file in the current instance of InfranView? It
needs to work both in Windows NT and 2000. IrfanView has a switch "/one"
which forces a single instance. Would it be sufficient to add the switch to
the file associations in Windows?

many thanks

David

' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
''***************Usage Examples***********************
'Open a folder: fHandleFile("C:\TEMP\",WIN_NORMAL)
'Call Email app: fHandleFile("mailto:[email protected]",WIN_NORMAL)
'Open URL: fHandleFile("http://home.att.net/~dashish", WIN_NORMAL)
'Handle Unknown extensions (call Open With Dialog):
' fHandleFile("C:\TEMP\TestThis",Win_Normal)
'Start Access instance:
' fHandleFile("I:\mdbs\CodeNStuff.mdb", Win_NORMAL)
'****************************************************
Function fHandleFile(stFile As String, lShowHow As Long)
Dim lRet As Long, varTaskID As Variant
Dim stRet As String
'First try ShellExecute
lRet = apiShellExecute(hWndAccessApp, vbNullString, _
stFile, vbNullString, vbNullString, lShowHow)

If lRet > ERROR_SUCCESS Then
stRet = vbNullString
lRet = -1
Else
Select Case lRet
Case ERROR_NO_ASSOC:
'Try the OpenWith dialog
varTaskID = Shell("rundll32.exe shell32.dll,OpenAs_RunDLL "
_
& stFile, WIN_NORMAL)
lRet = (varTaskID <> 0)
Case ERROR_OUT_OF_MEM:
stRet = "Error: Out of Memory/Resources. Couldn't Execute!"
Case ERROR_FILE_NOT_FOUND:
stRet = "Error: File not found. Couldn't Execute!"
Case ERROR_PATH_NOT_FOUND:
stRet = "Error: Path not found. Couldn't Execute!"
Case ERROR_BAD_FORMAT:
stRet = "Error: Bad File Format. Couldn't Execute!"
Case Else:
End Select
End If
fHandleFile = lRet & _
IIf(stRet = "", vbNullString, ", " & stRet)
End Function
 
D

Davy

Regarding the above I have just realised that this will not really solve my
problem. Even if I can open the graphic display program in a single instance
then each image will persist as a window in that program until I run out of
memory.
So what I really need to do is automatically close the currently open image
before opening the next.
I cannot close the program because the program reload time for each new
image would seriously slow down the presentation to a group.

cheers

Davy
 
D

Davy

Please ignore all above posts. By experimentation I have found that if I
put a /one switch in the windows file association for jpg/Irfanview then
ShellExecute does not keep loading new instances of IrfanView - and as a
bonus closes the previous image before loading the next image!

So problems solved.

cheers

Davy
 

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