• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 239
  • Last Modified:

vb6 opening a file in a certain program

Hello,
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.

cheers
chris
0
Rickardc
Asked:
Rickardc
  • 2
1 Solution
 
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
        Next
        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

0
 
gecko_au2003Commented:
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.
0
 
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.

~IM
0
 
RickardcAuthor Commented:
Sorry Bout that!

Thanx Idle mind!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now