You are not logged in.

Dear visitor, welcome to Jabaco - Community. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

OlimilO

Intermediate

  • "OlimilO" is male
  • "OlimilO" started this thread

Posts: 277

Date of registration: Jan 18th 2009

Location: Germany

Occupation: software engineer

  • Send private message

1

Thursday, August 6th 2009, 7:21pm

Open any file associated to a program by its file extension

Hi,

if you want to open a pdf-file but the path to Acrobat Reader is unknown, you could use the Desktop-Object.

The Desktop-Object is a real Singleton, this means there is only one Desktop-Object for every program.

Of course, because every computer has only one desktop :)

Jabaco Source

1
2
3
4
If java#awt#Desktop.isDesktopSupported Then
      Dim d As java#awt#Desktop = java#awt#Desktop.getDesktop
      d.open(New File(aFileName)) 
   End If


Desktop also has other interesting procedures:

Jabaco Source

1
2
3
4
d.browse(New URI(aFileName)) 
   d.edit(New File(aFileName)) 
   d.mail(New URI(aFileName)) 
   d.print(New File(aFileName))

looks like a new feature of the Shell-function, what do you think?
the disadvantage is:

a) you do not get the path to the program

b) it is not possible to transfer certain program dependent calling parameters

c) the Desktop-Object does not return a Process-object



But of course you can handle these things in your program:

-> a)+b) the user simply must set the path to the desired program

-> c) I also found something different

Jabaco Source

1
2
Dim p As java#lang#Process = java#lang#Runtime.getRuntime.exec( _
      "rundll32 url.dll,FileProtocolHandler " & aFileName)


but this solution is not platformindependent, it is windows-only.



if you want to show a help-file (hlp, chm) you could use the CommonDialog.ShowHelp-command
for windows-only it could be implemented like:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Dim myHelpFile As java#lang#String 
   Dim cmd As New java#lang#StringBuffer
   Dim windir As String = System.getenv("windir")
   Dim p As Process
   
   Dim q As String = ChrW(34) '""""
   
   cmd.append(windir).append("")
   
   'some examples:
   myHelpFile = "windows.hlp"
   myHelpFile = "edit.hlp"
   myHelpFile = windir & "\System32\cliconf.chm"
   
   If myHelpFile.endsWith(".hlp") Then
      cmd.append("winhlp32.exe")
   Elseif myHelpFile.endsWith(".chm") Then
      cmd.append("hh.exe")       
   End If
   cmd.append(" ").append(q).append(myHelpFile).append(q)
   p = Shell(cmd.toString, vbNormalFocus)




OlimilO

Rate this thread
WoltLab Burning Board