Link to home
Start Free TrialLog in
Avatar of raunol
raunolFlag for Finland

asked on

How to access and read dragged text?

If I select text from some other application and then drag
it to drop it into my RichEdit-control, how I can access and read this text before it will display in my control?
OnDragDrop doesn't effect.
Avatar of viktornet
viktornet
Flag of United States of America image

Oh, kinda difficult task!

Regards,
Viktor
Avatar of d003303
d003303

Yo,
you will have to implement OLE drag and drop services. Use the RegisterDragDrop function to register your rich edit as a drop target and provide an implementation of IDropTarget as an interface. In its DragEnter implementation, you ca nquery the clipboard format of the IDataObject and read its content with the GetData method.

Slash/d003303
Avatar of raunol

ASKER

d003303,

Thank's for the hint. I grade it,if You can solve what's wrong here:


First I made TDropTarget type:

Uses ole2

Type

TDropTarget=Class(iDropTarget)
Public
   function Drop(DataObj:IDataObject; rfKeyState:Longint;
                 const pt: TPoint; var dwEffect:Longint):Hresult;
                 override;

   function DragOver(grfKeyState: Longint; const pt: TPoint;
                    var dwEffect: Longint): HResult;override;
End;

TMyRich=Class(TCustomRichEdit)
public
      DropTarget:TDropTarget;

End

Then I put this into the MyRich's WM_CREATE handler: RegisterDragDrop(handle,DropTarget);

When I now test it and drag text from an other edit-application to my control, nothing will happen - no effects will disapear
under functions TdropTarget.Drop or TDropTarget.DragOver ??
 
- Rauno -
just an idea.. why not when selecting, copying it to the clipboard? (Or isn't this also already done, just for dragging and dropping to another application?) Zif?. The clipboard can be easely entered from delphi.
OK,
you don't have any effects because the RichEdit control is already registered as a Drag/Drop target when you call RegisterDragDrop, take a look at the return value. You can re-register it with RevokeDragDrop and then call RegisterDragDrop again. But, all RichEdit internal Drag/Drop events do not work anymore :-(

I'm currently looking for a way to get the previous IDropTarget of a registered drop target window, so you can proxy/stub the whole thing in your implementation.

Slash/d003303
Avatar of raunol

ASKER

d003303,

"no effects will appear" I should had written ;-)
(My english is not good)

Yes, I notised the function returned E_INVALIDARG.
I changed it a little and then it returned
DRAGDROP_E_ALREADYREGISTERED.

I also tried this RevokeDragDrop, but it caused
always error.


ZifNaf,

If I drag text from an other application to my
control, for example from WordPad, the text isn't
there in the clipboard.

There is the SelectionChange procedure in the RichEdit.
I dropped dragged text different position when the
SelectionChange activated. Under the procedure I
opened the ClipBoard and red the contents, but dragged
text wasn't there. There was some other text copied
before.

Obviously, due to OLE operation, I think the
text is stored somewhere in iDropTarged. But how to
get out it from there, before it will display in my control?
I want to do this, because I want to change the style of the
text (size and so on) before it will display.

- Rauno


ASKER CERTIFIED SOLUTION
Avatar of d003303
d003303

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of raunol

ASKER

Thanks for Your kindness, the code looks fine,
but I have still broblems. I think, the code is for
Delphi3 or 4, and I have Delphi 2 :-(

I don't find ActiveX unit for me, but obviously OLE2 unit
works as well, becouse there is all what are used in the
code - except TInterfacedObject. But Class-clause respects
only one descent so I must remove TInterfacedObject anyway.

Also I must make some other changes. There is some "out" type
in the code or it is bug (e.g. out medium) I changed it "Var".
Also I must change "Const" types to "Var", because
functions (e.g. GetData) don't respect Class constants
as variable. Then I change _Addref And _release without "_" Addref And Release.

That's all. After those changes Delphi2 compiled the code.
But If I try to run the program, it breaks off in the RegisterDragDrop-function which is under the
FormCreate -event, and causes run-time error 210
that means: "Object not initialized". What to do?

- Rauno  -
I still got a Delphi 2 installed somewhere, I'll port you the code. Hang on.

Slash/d003303
hum, hum, hum. I re-designed the objects for D2 and it will not run properly. Bad, bad. I keep on diggin...
d003303, If you keep digging, you'll end up in China :-).
...or in New Zealand...