vb6 opening a file in a certain program

I've just fineshed writing my imaging software, and wanted to open certain files in that program.

say for instance that I wanted to open a jpg by dragging that file over my program's icon. How?

I have changed the "open with" settings so that it opens my program but how do I get the picture in my program.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike TomlinsonMiddle School Assistant TeacherCommented:
The two processes you have described are completely different animals.  The first involves drag and drop while the second involves command line parameters.

In the "open with" settings, you should have the "%1" parameter tacked onto the end of your program name as in the example below:
    "C:\Program Files\Common Files\Microsoft Shared\PhotoEd\PHOTOED.EXE" "%1"

This will cause the file name being opened to be passed into your program as a command line parameter.  You can get to this information in your program using code like this:

    Private fileName As String

    Private Sub Form_Load()
        fileName = Command()
    End Sub

As for the drag and drop part, you can use code like this to determine when a file has been dropped on your application.  The following will cause the dropped filenames to be displayed in Text1 if they are dropped on the Form or Text1:

Option Explicit

Private Sub Form_Load()
    Text1.OLEDropMode = 1 ' Manual
    Me.OLEDropMode = 1 ' Manual
End Sub

Private Sub Form_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Data.GetFormat(vbCFFiles) Then
        Dim sText As String
        Dim i As Integer
        For i = 1 To Data.Files.Count
            sText = sText & Data.Files(i) & vbCrLf
        Text1.SelText = sText
    End If
End Sub

Private Sub Text1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
    Call Form_OLEDragDrop(Data, Effect, Button, Shift, X, Y)
End Sub


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Shane Russell2nd Line Desktop SupportCommented:
I dont know if this is possible but instead of the command line parameters , isnt there a way to see what file has been dragged over the application in question and then use the shell command to open it ? I am new to programming and it was just a thought I had when I was reading through this.
Mike TomlinsonMiddle School Assistant TeacherCommented:
The OLEDragDrop code is for determining what file(s) have been dropped onto your application.  By inspecting the extension of those files, you can decide if your application should attempt to process them or just ignore them.

If you associate an extension with your application, double clicking a file with that extension in explorer will cause your app to be opened and the filename that was double clicked to be passed in as a command-line parameter.

The Shell() command is used to execute an external EXE, COM or BAT file from within a VB application.  You would use it if you need to launch another app from yours.  It wouldn't be used to process a file associated with your app unless you needed to launch a new instance of your application for each file to be opened.

RickardcAuthor Commented:
Sorry Bout that!

Thanx Idle mind!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.