Jump to content
Sign in to follow this  
jerome

Drag & Drog of text from external application

Recommended Posts

jerome

Hi,

I want to be able to drag some text from any other/external application to a gui/program made in autoit.

I found a solution with drag & drop of files but it doesn't work with text (drop refused by gui)...

Is there a solution for that?

Thanks for any help

JD

Share this post


Link to post
Share on other sites
MrBeatnik

I don't actually think Windows allow text to be dragged as an object?

It would have to be converted to a scrap first? Not sure how to go about that; it would be a condition of the program displaying the text I think.


Please correct me if I am wrong in any of my posts. I like learning from my mistakes too.

Share this post


Link to post
Share on other sites
jerome

I don't actually think Windows allow text to be dragged as an object?

It would have to be converted to a scrap first? Not sure how to go about that; it would be a condition of the program displaying the text I think.

Yes Windows allows that, you can even drag an URL from IEXPLORER address bar to another application but this kind of things are automatically refused by autoit applications even if drag & drop is activated on window...

Please help, really need it... Anyone?

Thanks

JD

Share this post


Link to post
Share on other sites
MrCreatoR

Maybe someone came up with a solution for this one?

I search the forum, but no results found :P (only this old topic).


 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites
Siao

You have to do it with OLE drag and drop, obviously WM_DROPFILES isn't going to cut it. May look in MSDN on RegisterDragDrop, IDropTarget etc.

I don't know jack about COM, so I'm not sure how to implement it, AutoIt or no AutoIt...

Some smarter fellows at AutoHotkey have it figured out so you can take that as a starting point. Since now AutoIt supports DllCallback too, I assume that script would be possible to convert.

Edited by Siao

"be smart, drink your wine"

Share this post


Link to post
Share on other sites
Richard Robertson

There are several types of drops. It can contain a number of data types and each one has to be handled differently. Text can be dropped, along with files, and I think even bitmap data.

Share this post


Link to post
Share on other sites
ValeryVal

If you need any help...

This group

http://tech.groups.yahoo.com/group/autoitgroup/

has topic Files/Misc and my old script CalendarRTF.au3 (Translated from Gui4Cli into AutoIt - 20 February 2005) in ACalendar_1.zip

It showes how can you use Drag&Drop action with rich text from CalendarRTF.au3 to

ie

WordPad


The point of world view

Share this post


Link to post
Share on other sites
MrCreatoR

Thanks to all, but i think (after reading tons of stuff about the subject) that it is too hard to do this in Autoit.

I found also this tutorial about the implementation of drag and drop, there also demo available (the first link to zip file), but it's for C/C++ Afaik, and i have no idea how to translate it to autoit (and i tried, realy tried), basicaly i don't understand how to manage the IDropTarget :P .. and maybe some more stuff...

If someone can translate it, it will be great.


 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites
martin

Thanks to all, but i think (after reading tons of stuff about the subject) that it is too hard to do this in Autoit.

I found also this tutorial about the implementation of drag and drop, there also demo available (the first link to zip file), but it's for C/C++ Afaik, and i have no idea how to translate it to autoit (and i tried, realy tried), basicaly i don't understand how to manage the IDropTarget :P .. and maybe some more stuff...

If someone can translate it, it will be great.

I haven't looked at any of the references you gave, but I tried just detecting the mouse down and got something to work. You have to select the text to be copied by dragging over it with the mouse, then drag it into the edit. It's a start maybe.

#include <GUIConstants.au3>

#include <guilistview.au3>
#include <misc.au3>
$Title = "Drag Text to"
$dragInc = 5;set when we decide dragging has started
$Form1 = GUICreate($Title, 353, 256, 303, 219)
$Edit1 = GUICtrlCreateEdit("", 60, 32, 250, 89)
GUICtrlSetData(-1, "Edit1")
Dim $np[2] = [0,0]
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$text = ""
$Dragging = False
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
            
    EndSwitch
    CheckDrag()
    
    
    
WEnd


Func CheckDrag()
    If _IsPressed("1") Then
        $mp = MouseGetPos()
        While _IsPressed("1")
            $np= MouseGetPos()
            If Abs($np[0] - $mp[0]) > $dragInc Or Abs($np[1] - $mp[1]) > $dragInc Then
                $dragging = True
                ExitLoop
            EndIf
        WEnd
        
        While _IsPressed("1")
            $np= MouseGetPos()
            Sleep(20)
        WEnd
        $wp = WinGetPos($Title)
        If $dragging Then
            If $np[0] > $wp[0] + 60 And $np[1] < ($wp[0] +60 + 250) And $np[0] > ($wp[1] + 32) And $np[1] < ($wp[1] + 32 + 89) Then
                WinActivate($Title)
                GUICtrlSetState($Edit1,$GUI_FOCUS)
                Send("{END}^v")
                
            EndIf
        EndIf
        $Dragging = False
        
        Send("^c")
        $text = ClipGet()
    ;ConsoleWrite("Copied this" & @LF & $text & @LF)
    EndIf
    
    
    
    
EndFunc

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
MrCreatoR

Thanks martin, that is really a good start for a workaround, but to be unest, i am not like the idea that Clipboard is always used, and also the cursor is displayed as restriction (dropping not allowed)...

Here is a little improvments in your example (it's not really "fix" the mention issues, but it faster and i think more reliable) :P

#include <GUIConstants.au3>
#include <Misc.au3>

Global $Title = "Drag Text to"
Global $Dragging = False
Global $DragInc = 5 ;set when we decide dragging has started
Global $OldClip = ClipGet()

$Form1 = GUICreate($Title, 353, 256, 303, 219)
$Edit1 = GUICtrlCreateEdit("", 60, 32, 250, 89)
GUICtrlSetData(-1, "Edit1")

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            ClipPut($OldClip)
            Exit
    EndSwitch
    CheckDrag()
WEnd

Func CheckDrag()
    If _IsPressed("1") And Not WinActive($Form1) Then
        Local $MousePos = MouseGetPos()
        While _IsPressed("1")
            $MousePosNew = MouseGetPos()
            If Abs($MousePosNew[0] - $MousePos[0]) > $DragInc Or Abs($MousePosNew[1] - $MousePos[1]) > $DragInc Then
                $Dragging = True
                ExitLoop
            EndIf
        WEnd
        
        While _IsPressed("1")
            $MousePosNew = MouseGetPos()
            Sleep(20)
        WEnd
        
        Local $WinPos = WinGetPos($Form1)
        Send("^{Insert}")
        
        If $Dragging Then
            If _ControlIDGetHovered() = $Edit1 Then
                MouseClick("Left")
                Send("+{Insert}")
            EndIf
        EndIf
        $Dragging = False
    EndIf
EndFunc

Func _ControlIDGetHovered()
    Local $Old_Opt_MCM = Opt("MouseCoordMode", 1)
    Local $iRet = DllCall("user32.dll", "int", "WindowFromPoint", _
        "long", MouseGetPos(0), _
        "long", MouseGetPos(1))
    $iRet = DllCall("user32.dll", "int", "GetDlgCtrlID", "hwnd", $iRet[0])
    Opt("MouseCoordMode", $Old_Opt_MCM)
    Return $iRet[0]
EndFunc
Edited by MsCreatoR

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites
martin

Thanks martin, that is really a good start for a workaround, but to be unest, i am not like the idea that Clipboard is always used, and also the cursor is displayed as restriction (dropping not allowed)...

Here is a little improvments in your example (it's not really "fix" the mention issues, but it faster and i think more reliable) :P

#include <GUIConstants.au3>
#include <Misc.au3>

Global $Title = "Drag Text to"
Global $Dragging = False
Global $DragInc = 5 ;set when we decide dragging has started
Global $OldClip = ClipGet()

$Form1 = GUICreate($Title, 353, 256, 303, 219)
$Edit1 = GUICtrlCreateEdit("", 60, 32, 250, 89)
GUICtrlSetData(-1, "Edit1")

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            ClipPut($OldClip)
            Exit
    EndSwitch
    CheckDrag()
WEnd

Func CheckDrag()
    If _IsPressed("1") And Not WinActive($Form1) Then
        Local $MousePos = MouseGetPos()
        While _IsPressed("1")
            $MousePosNew = MouseGetPos()
            If Abs($MousePosNew[0] - $MousePos[0]) > $DragInc Or Abs($MousePosNew[1] - $MousePos[1]) > $DragInc Then
                $Dragging = True
                ExitLoop
            EndIf
        WEnd
        
        While _IsPressed("1")
            $MousePosNew = MouseGetPos()
            Sleep(20)
        WEnd
        
        Local $WinPos = WinGetPos($Form1)
        Send("^{Insert}")
        
        If $Dragging Then
            If _ControlIDGetHovered() = $Edit1 Then
                MouseClick("Left")
                Send("+{Insert}")
            EndIf
        EndIf
        $Dragging = False
    EndIf
EndFunc

Func _ControlIDGetHovered()
    Local $Old_Opt_MCM = Opt("MouseCoordMode", 1)
    Local $iRet = DllCall("user32.dll", "int", "WindowFromPoint", _
        "long", MouseGetPos(0), _
        "long", MouseGetPos(1))
    $iRet = DllCall("user32.dll", "int", "GetDlgCtrlID", "hwnd", $iRet[0])
    Opt("MouseCoordMode", $Old_Opt_MCM)
    Return $iRet[0]
EndFunc

Good improvements. But still, it's not a proper solution as you say.

I had a look at the link you gave and I decided there are things I'd rather be doing, like the ironing!


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
Triblade

Well, hoe about creating an extra gui/edit control that hovers under you mouse button? In there is the copied text. Then when the mousebtn is release, destroy the gui and copy the text again in the new field.


My active project(s): A-maze-ing generator (generates a maze)

My archived project(s): Pong3 (Multi-pinger)

Share this post


Link to post
Share on other sites
BrettF
Triblade

I don't have a new question...

It is a anwser to a old question. It not bumping, just helping people wanting to do something like this and can't find an anwser.

This topic is probably burried anyway at the end of the day, so why not trying to help people instead of keep creating more topics...


My active project(s): A-maze-ing generator (generates a maze)

My archived project(s): Pong3 (Multi-pinger)

Share this post


Link to post
Share on other sites
argumentum

use a Richedit, it will take the dropped text, make it of an edit control size, thats it, solved =)

Share this post


Link to post
Share on other sites
BrewManNH

Please don't post to 6 year old topics for users that haven't even been here in 2 years. I'm sure he's probably figured it out by this time.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×