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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loading a file on startup

Status
Not open for further replies.

WoundEdGoat

Programmer
May 10, 2002
39
CA
I would like to know how to set up my program to load data into the program in the event that a user double-clicks on a related data file or drags a file onto the program.

Thanks.
 
2 different things there.

1st is outside of VB but, though I haven't done it, there are probably API calls to register your file type.

2nd is just drag and drop. When a file is dropped on to your app your application (actually what ever control the file was droped on) gets an
OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, x As Single, y As Single)

then you can use

If Data.GetFormat(vbCFFiles) Then

to see if it was a file(s) dropped on your app

Data.Files.Item(n)

gives you the name of the file where n is a number from 1 to the total number of files dragged onto your app. If you only support 1 file at a time then just grab the 1st and warn them that multiple files can not be opened.

very basic but there is heaps of help on OLEDragDrop out there and you'd be surprised at how much you could/should do in code to support dragdrop.


 
That's not quite what I had in mind. Sorry. I should have explained it better.

What I ment was for example when you double click on a bitmap file in explorer, it will load your default graphics program and the file at the same time. That is what I'd like to learn how to do. You might have, of course, said that in the first part of your reply and I may not have understood it though.

As for the second thing, I was refering to when you're in exporer (again) and you drag a file onto a program file where it will load with the file in memory to start with.

Thanks and once again I should have been more clear on what I wanted to know.
 
This has already been answered

thread222-424599 All the Best
Praveen Menon
pcmin@rediffmail.com
 
Thanks PM. I wouldn't have asked again but I really had no idea what I would have been lokking for.
 
Sorry about not explaining it enough.

1) I have never registered a file type via code so not sure how to do that.

2) the code snippets are the start of being able to drag a file onto your application.

here are 2 events that I use on one of my forms to allow drag and drop of images onto the form
Code:
Private Sub picContactPortait_OLEDragOver(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, x As Single, y As Single, State As Integer)
    Dim vFN As Variant
    Dim sFirstFileName As String
    Dim sExt As String
    If Data.GetFormat(vbCFFiles) Then
        sFirstFileName = Data.Files.Item(1)
        sExt = Right(sFirstFileName, Len(sFirstFileName) - InStrRev(sFirstFileName, "."))
        sExt = UCase(sExt)
        If sExt = "BMP" Or sExt = "GIF" Or sExt = "JPG" Or sExt = "JPEG" Then
            Select Case State
                Case Is = vbEnter
                    Set picOld.Picture = picContactPortait.Picture
                    Set picContactPortait.Picture = LoadPicture(sFirstFileName)
                    Effect = vbDropEffectCopy
                Case Is = vbOver
                    Effect = vbDropEffectCopy
                Case Is = vbLeave
                    Set picContactPortait.Picture = picOld.Picture
                    Set picOld.Picture = Nothing
                    Effect = vbDropEffectNone
            End Select
        Else
            Effect = vbDropEffectNone
        End If
    End If
End Sub


Private Sub picContactPortait_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, x As Single, y As Single)
    Dim vFN As Variant
    Dim sFirstFileName As String
    Dim sExt As String
    If Data.GetFormat(vbCFFiles) Then
        sFirstFileName = Data.Files.Item(1)
        sExt = Right(sFirstFileName, Len(sFirstFileName) - InStrRev(sFirstFileName, "."))
        sExt = UCase(sExt)
        If sExt = "BMP" Or sExt = "GIF" Or sExt = "JPG" Or sExt = "JPEG" Then
            Set picContactPortait.Picture = LoadPicture(sFirstFileName)
        Else
            Effect = vbDropEffectNone
        End If
    End If
End Sub

the
Set picContactPortait.Picture = LoadPicture(sFirstFileName)
in the picContactPortait_OLEDragDrop event is where you'd open the file and load the data just happens that i'm in this case using a picture and most of the work is done for me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top