Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

make my vb app open a file which has been clicked in Windows

Status
Not open for further replies.

ToshTrent

Technical User
Jul 27, 2003
209
Hi,

I was wondering how i can make my program open when windows user double click on the file type used with it.

for example *.JPG opens with Paint, i would like it to open with my VB app instead.

Can this been done with out a major amount of coding?

Thanks
Matt
 
If you want all jpg's to open with your program, just change the association in the operating system. For instance in XP, in explorer window go to Tools|Folder Options|File types, select your file type, click Advanced, then Edit and browse to your program.

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
I don't believe that will work, as you then need to make your program take the file location that was clicked and process it in another manner.

I'll have a think and may get back to ya later Matt.
 

Explorer>Right Click>Open With... pretty much the same as johnwm's post but with one difference. Make sure that the "Use as default" check box is not checked. Then you will be able to test your exe and its parsing of the "Command" line parameters that are passed to it.

Also, once you have your program working the way you want in this manner, come back to this site and search for "associate program". You should find some examples on what you need to do pragmatically to make your program the default for a file type.

Good Luck

 
Use the API function ShellExecute to open any windows registered document.

'Decclare the function in general section
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

'This general routine will open any type of file u passed
Public Sub ShowTextFile(ByVal cTextFile As String, ByVal myHandle As Double)

'General routine to view any text file
'Parameters:
'1 - cTextFile = The text file to be viewed
'George Varghese/7.05.2003

On Error GoTo err_Proc

'Just show the passed text file using the windows text file editor
If IsNothing(Trim(cTextFile)) Then Exit Sub
If IsFileExist(cTextFile) Then
Call ShellExecute(myHandle, "open", cTextFile, "", "", 8)
End If

Exit Sub

err_Proc:
msgbox err.description
End Sub

'This is statement to open the text file
'me.hwnd is the current vb form's handle
cFileName="c:\test\mypicture.jpg"
Call ShowTextFile(cFileName, Me.hwnd)

Hope this will solve your problem.
thanks

 
Thank you i'll give that a go.

[red]
Thankyou[/red]
Matt
 
Dear Matt,

Thats not what you want. The code provided by gevee executes a file from inside your application. But i guess you need something by which when any one tries to open a file from windows, you need it to open in your app.

First thing to do is to create a file association for the file extension, so that windows knows what to do when that type of a file is double clicked/opened/edited. This file association can be created as a registry key.

Next part is the opening of document in your window. For that, there is a Command$ passed on to the VB app, which actually is the filename you just double clicked. So if you have this filename, you can actually pull data outta that file, process it the way you want it, and display contents in a picturebox, or textbox or whatever..

All the best
Sunil
 
not tested it personnaly... but code here is usually sound


good luck!

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
come on... get involved!
To get the best response to a question, please check out FAQ222-2244 first
A General Guide To Excel in VB FAQ222-3383
 
Ah right, thank you!,

I'll give that a tinkle, and take a look at the link too...

Cheers to all,

Matt.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top