VB6 Code to drag & drop objects form our app to external apps.
Assume you want to drag and drop a jpeg picture.
1. Create a form
2. place a image control.
3. Place a nice icon insed of loading the whole picture.
Code:Private Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = vbLeftButton Then Image1.OLEDrag End SubCode:Private Sub Image1_OLEGiveFeedback(Effect As Long, DefaultCursors As Boolean) ' asking Effect = vbDropEffectCopy 'a copy is droped of the data End SubPrivate Sub Image1_OLECompleteDrag(Effect As Long)Code:Private Sub Image1_OLEStartDrag(Data As DataObject, AllowedEffects As Long) AllowedEffects = vbDropEffectCopy Data.Clear ' if dragging the filename, then do this Me.Image1.Tag = "c:\test.jpg" Data.Files.Add Image1.Tag Data.SetData , vbCFFiles ' if dragging the image, then do this 'Data.SetData LoadPicture(Image1.Tag), vbCFBitmap ' note that you can actually do both and the target will pick which it wants End Sub
' do whatever you need to do after data was accepted/rejected, if anything
End Sub
* This is a sample code posted by lavolp inresponse to my drag & drop question and found that really useful.


Reply With Quote