如何拖动超链接到窗体中,并得到超链接的内容 (50分)

  • 主题发起人 主题发起人 jyh_jack
  • 开始时间 开始时间
J

jyh_jack

Unregistered / Unconfirmed
GUEST, unregistred user!
小人有一个问题:<br><br>&nbsp; &nbsp; 我要将一个选中的文本或是超链接,拖动到窗体中,并且还要得到拖动的内容。<br><br>&nbsp; &nbsp; 就像是flashget那样的效果,拖动完后出现在窗口中,请各位大仙指示。<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;谢谢。。。。。。
 
为什么没有人回答这个问题啊,我这么不受欢迎吗.......<br><br><br>......God bless me.....
 
拖动到窗体上行不行我不知道,但拖动到一个memo或richedit是没有问题的。<br>你可以考虑在窗口上放一个可以接受文本dragdrop的控件如memo就成。
 
我有个专门搞定DragDrop的控件,如果你不建议用或想参考的话,留下MAIL!<br>[:)]
 
看看这个例子吧:<br><br>unit uDropit;<br>{From &nbsp;: Dragfile.dpr<br>&nbsp; &nbsp;To &nbsp;:<br>&nbsp; &nbsp;Do &nbsp;: Accept Drag and Drop Files And &nbsp;Show it's Full Name.<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Use API: DragAcceptFiles<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DragQueryFile &nbsp;;<br>}<br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; StdCtrls, Buttons,ole2,shellapi, ComCtrls, ExtCtrls;<br><br>type<br>&nbsp; Tmymemo=class(Tmemo)<br>&nbsp; &nbsp;procedure DefaultHandler(var Message); override;<br>end;<br><br>type<br>&nbsp; Tfrm = class(TForm)<br>&nbsp; &nbsp; Memo1: TMemo;<br>&nbsp; &nbsp; Panel1: TPanel;<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; &nbsp; procedure FormDestroy(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; mymemo:Tmymemo;<br>&nbsp; &nbsp; &nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; frm: Tfrm;<br><br>implementation<br><br>{$R *.DFM}<br><br><br>procedure Tfrm.FormCreate(Sender: TObject);<br>begin<br>DragAcceptFiles(memo1.handle,False);<br>Mymemo:=TMyMemo.create(self);<br>&nbsp; with Mymemo do<br>&nbsp; begin<br>&nbsp; &nbsp; Parent:= Self;<br>&nbsp; &nbsp; lines.add('Accept Files');<br>&nbsp; &nbsp; Align:= alClient;<br>&nbsp; &nbsp; DragAcceptFiles(Handle, true);<br>&nbsp; end;<br>end;<br><br>procedure TMymemo.DefaultHandler(var Message);<br>var I:Integer;<br>&nbsp; &nbsp; dd:string[250];<br>&nbsp; &nbsp; pp:Pchar;<br>begin<br>&nbsp;inherited DefaultHandler(Message);<br>&nbsp;with TMessage(Message) do<br>&nbsp; if (Msg = WM_DROPFILES) then<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; I:=DragQueryFile(wparam,0,@dd,250);<br>&nbsp; &nbsp; pp:=Pchar(@dd);<br>&nbsp; &nbsp; showmessage(pp);<br>&nbsp; &nbsp;end;<br>end;<br><br>procedure Tfrm.FormDestroy(Sender: TObject);<br>begin<br>mymemo.free;<br>end;<br><br>end.<br>
 
好象有一个draganddrop控件吧
 
我已将问题改了,<br>只要是能拖动超链接就OK了,各位,再帮帮我。
 
你要是愿意研究源代码的话,看一看Drag and Drop 的源代码。<br>要是愿意找书看的话,可以看一看《Delphi高级开发指南》<br>我有这样的程序,具体解说一下子不容易说得清楚。<br>
 
Doy, <br>你可不可以把代码发给我呢。<br>或是贴在这里面。。。
 
我把dragdrop中的DropURLSource贴了,如果满意可以给分了我等分用呀![:D]<br>unit DropURLSource;<br>interface<br>uses<br>&nbsp; DropSource,<br>&nbsp; Classes, ActiveX;<br>{$include DragDrop.inc}<br><br>type<br>&nbsp; TDropURLSource = class(TDropSource)<br>&nbsp; private<br>&nbsp; &nbsp; fURL: String;<br>&nbsp; &nbsp; fTitle: String;<br>&nbsp; protected<br>&nbsp; &nbsp; function DoGetData(const FormatEtcIn: TFormatEtc; OUT Medium: TStgMedium):HRESULT; Override;<br>&nbsp; public<br>&nbsp; &nbsp; constructor Create(aOwner: TComponent); Override;<br>&nbsp; &nbsp; function CutOrCopyToClipboard: boolean; Override;<br>&nbsp; published<br>&nbsp; &nbsp; property URL: String Read fURL Write fURL;<br>&nbsp; &nbsp; property Title: String Read fTitle Write fTitle;<br>&nbsp; end;<br><br>procedure Register;<br><br>implementation<br><br>uses<br>&nbsp; Windows,<br>&nbsp; SysUtils,<br>&nbsp; ClipBrd,<br>&nbsp; ShlObj;<br><br>procedure Register;<br>begin<br>&nbsp; RegisterComponents('DragDrop', [TDropURLSource]);<br>end;<br>function ConvertURLToFilename(url: string): string;<br>const<br>&nbsp; Invalids = '//:?*&lt;&gt;,|''"';<br>var<br>&nbsp; i: integer;<br>begin<br>&nbsp; if lowercase(copy(url,1,7)) = 'http://' then<br>&nbsp; &nbsp; url := copy(url,8,128) // limit to 120 chars.<br>&nbsp; else if lowercase(copy(url,1,6)) = 'ftp://' then<br>&nbsp; &nbsp; url := copy(url,7,127)<br>&nbsp; else if lowercase(copy(url,1,7)) = 'mailto:' then<br>&nbsp; &nbsp; url := copy(url,8,128)<br>&nbsp; else if lowercase(copy(url,1,5)) = 'file:' then<br>&nbsp; &nbsp; url := copy(url,6,126);<br><br>&nbsp; if url = '' then url := 'untitled';<br>&nbsp; result := url;<br>&nbsp; for i := 1 to length(result) do<br>&nbsp; &nbsp; if result = '/'then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; result := copy(result,1,i-1);<br>&nbsp; &nbsp; &nbsp; break;<br>&nbsp; &nbsp; end<br>&nbsp; &nbsp; else if pos(result,Invalids) &lt;&gt; 0 then<br>&nbsp; &nbsp; &nbsp; result := ' ';<br>&nbsp; &nbsp;appendstr(result,'.url');<br>end;<br><br><br>constructor TDropURLSource.Create(aOwner: TComponent);<br>begin<br>&nbsp; inherited Create(aOwner);<br>&nbsp; fURL := '';<br>&nbsp; fTitle := '';<br>&nbsp; DragTypes := [dtLink]; // Only dtLink allowed<br><br>&nbsp; AddFormatEtc(CF_URL, NIL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL);<br>&nbsp; AddFormatEtc(CF_FILEGROUPDESCRIPTOR, NIL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL);<br>&nbsp; AddFormatEtc(CF_FILECONTENTS, NIL, DVASPECT_CONTENT, 0, TYMED_HGLOBAL);<br>&nbsp; AddFormatEtc(CF_TEXT, NIL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL);<br>end;<br>function TDropURLSource.CutOrCopyToClipboard: boolean;<br>var<br>&nbsp; FormatEtcIn: TFormatEtc;<br>&nbsp; Medium: TStgMedium;<br>begin<br>&nbsp; result := false;<br>&nbsp; FormatEtcIn.cfFormat := CF_URL;<br>&nbsp; FormatEtcIn.dwAspect := DVASPECT_CONTENT;<br>&nbsp; FormatEtcIn.tymed := TYMED_HGLOBAL;<br>&nbsp; if fURL = '' then exit;<br>&nbsp; if GetData(formatetcIn,Medium) = S_OK then<br>&nbsp; begin<br>&nbsp; &nbsp; Clipboard.SetAsHandle(CF_URL,Medium.hGlobal);<br>&nbsp; &nbsp; result := true;<br>&nbsp; end else exit;<br><br>&nbsp; //render several formats...<br>&nbsp; FormatEtcIn.cfFormat := CF_TEXT;<br>&nbsp; FormatEtcIn.dwAspect := DVASPECT_CONTENT;<br>&nbsp; FormatEtcIn.tymed := TYMED_HGLOBAL;<br>&nbsp; if GetData(formatetcIn,Medium) = S_OK then<br>&nbsp; begin<br>&nbsp; &nbsp; Clipboard.SetAsHandle(CF_TEXT,Medium.hGlobal);<br>&nbsp; &nbsp; result := true;<br>&nbsp; end;<br>end;<br>// ----------------------------------------------------------------------------- <br><br>function TDropURLSource.DoGetData(const FormatEtcIn: TFormatEtc; OUT Medium: TStgMedium):HRESULT;<br>const<br>&nbsp; URLPrefix = '[InternetShortcut]'#10'URL=';<br>var<br>&nbsp; pFGD: PFileGroupDescriptor;<br>&nbsp; pText: PChar;<br>begin<br><br>&nbsp; Medium.tymed := 0;<br>&nbsp; Medium.UnkForRelease := NIL;<br>&nbsp; Medium.hGlobal := 0;<br><br>&nbsp; //--------------------------------------------------------------------------<br>&nbsp; if ((FormatEtcIn.cfFormat = CF_URL) or (FormatEtcIn.cfFormat = CF_TEXT)) and<br>&nbsp; &nbsp; (FormatEtcIn.dwAspect = DVASPECT_CONTENT) and<br>&nbsp; &nbsp; (FormatEtcIn.tymed and TYMED_HGLOBAL &lt;&gt; 0) then<br>&nbsp; begin<br>&nbsp; &nbsp; Medium.hGlobal := GlobalAlloc(GMEM_SHARE or GHND, Length(fURL)+1);<br>&nbsp; &nbsp; if (Medium.hGlobal = 0) then<br>&nbsp; &nbsp; &nbsp; result := E_OUTOFMEMORY<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; medium.tymed := TYMED_HGLOBAL;<br>&nbsp; &nbsp; &nbsp; pText := PChar(GlobalLock(Medium.hGlobal));<br>&nbsp; &nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; &nbsp; StrCopy(pText, PChar(fURL));<br>&nbsp; &nbsp; &nbsp; finally<br>&nbsp; &nbsp; &nbsp; &nbsp; GlobalUnlock(Medium.hGlobal);<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; result := S_OK;<br>&nbsp; &nbsp; end;<br>&nbsp; end<br>&nbsp; //--------------------------------------------------------------------------<br>&nbsp; else if (FormatEtcIn.cfFormat = CF_FILECONTENTS) and<br>&nbsp; &nbsp; (FormatEtcIn.dwAspect = DVASPECT_CONTENT) and<br>&nbsp; &nbsp; (FormatEtcIn.tymed and TYMED_HGLOBAL &lt;&gt; 0) then<br>&nbsp; begin<br>&nbsp; &nbsp; Medium.hGlobal := GlobalAlloc(GMEM_SHARE or GHND, Length(URLPrefix + fURL)+1);<br>&nbsp; &nbsp; if (Medium.hGlobal = 0) then<br>&nbsp; &nbsp; &nbsp; result := E_OUTOFMEMORY<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; medium.tymed := TYMED_HGLOBAL;<br>&nbsp; &nbsp; &nbsp; pText := PChar(GlobalLock(Medium.hGlobal));<br>&nbsp; &nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; &nbsp; StrCopy(pText, PChar(URLPrefix + fURL));<br>&nbsp; &nbsp; &nbsp; finally<br>&nbsp; &nbsp; &nbsp; &nbsp; GlobalUnlock(Medium.hGlobal);<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; result := S_OK;<br>&nbsp; &nbsp; end;<br>&nbsp; end<br>&nbsp; //--------------------------------------------------------------------------<br>&nbsp; else if (FormatEtcIn.cfFormat = CF_FILEGROUPDESCRIPTOR) and<br>&nbsp; &nbsp; (FormatEtcIn.dwAspect = DVASPECT_CONTENT) and<br>&nbsp; &nbsp; (FormatEtcIn.tymed and TYMED_HGLOBAL &lt;&gt; 0) then<br>&nbsp; begin<br>&nbsp; &nbsp; Medium.hGlobal := GlobalAlloc(GMEM_SHARE or GHND, SizeOf(TFileGroupDescriptor));<br>&nbsp; &nbsp; if (Medium.hGlobal = 0) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; result := E_OUTOFMEMORY;<br>&nbsp; &nbsp; &nbsp; Exit;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; medium.tymed := TYMED_HGLOBAL;<br>&nbsp; &nbsp; pFGD := pointer(GlobalLock(Medium.hGlobal));<br>&nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; with pFGD^ do<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; cItems := 1;<br>&nbsp; &nbsp; &nbsp; &nbsp; fgd[0].dwFlags := FD_LINKUI;<br>&nbsp; &nbsp; &nbsp; &nbsp; if title = '' then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; StrPCopy(fgd[0].cFileName,ConvertURLToFilename(fURL))<br>&nbsp; &nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; StrPCopy(fgd[0].cFileName,ConvertURLToFilename(fTitle));<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; finally<br>&nbsp; &nbsp; &nbsp; GlobalUnlock(Medium.hGlobal);<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; result := S_OK;<br>&nbsp; &nbsp; end else<br>&nbsp; &nbsp; result := DV_E_FORMATETC;<br>end;<br>end.
 
写拖动事件不行吗?
 
干脆我把dragdrop的空间法给你算了<br>http://www.torry.net/vcl/system/draganddrop/dragdrop.exe<br><br>这个
 
呵呵。<br><br>下载中。<br><br>谢谢。。
 
好用吗?
 
后退
顶部