Results 1 to 16 of 16

Thread: [RESOLVED] Simulate drag and drop image from clipboard

Threaded View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2020
    Posts
    16

    Resolved [RESOLVED] Simulate drag and drop image from clipboard

    I'm trying to 'Drop' an image file at the current mouse location, FileType Image (BMP,JPG,PNG).

    i've written code to grab an image from the clipboard and save it. But now i want to grab this image and drop it at mousepos when a hotkey is pressed.

    The hotkey is working without my app having the focus ( as intended ) but now im stuck at actually dropping this file when the hotkey is pressed.

    My form:
    Code:
    Option Explicit
    
    Private Sub Command1_Click()
    
    Dim ImageName$
    
    Picture1.Picture = Clipboard.GetData
    Clipboard.Clear
    ImageName$ = InputBox("Provide filename")
    FileName$ = ImageName$
    Text1.Text = FileName$
    
    End Sub
    
    Sub On_Event_CtrlShiftV(FileName$)
    
    Dim FilePath$, MouseX&, MouseY&
    
    FilePath$ = "c:\AnyLocation\"
    SavePicture Picture1.Image, FilePath$ & FileName$ & ".png"
    
    Call GetCursorPos(Mpos)
    MouseX = Mpos.x
    MouseY = Mpos.y
    
    'drop the saved image at cursorposition as if it was dragged and dropped.
    
    
    End Sub
    
    Private Sub Timer1_Timer()
    
    If Picture1.Picture Then
        If GetAsyncKeyState(vbKeyF9) Then
            'Hotkey pressed,do dragdrop at mousepos
            Call On_Event_CtrlShiftV(Text1.Text)
                    
        End If
    End If
    End Sub
    Module:
    Code:
    Option Explicit
    
    Public Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
    Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    
    Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    
    Public Const VK_RSHIFT = &HA1
    Public Const VK_RCONTROL = &HA3
    
    Public Type POINTAPI
        x As Long
        y As Long
    End Type
    Public Mpos As POINTAPI
    Public FileName$
    Im just not sure how to begin the dropping of the file that is created.
    Last edited by rikdol; Feb 6th, 2020 at 10:49 AM. Reason: change to: FileType Image (BMP,JPG,PNG)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width