一个关于拖放选中文本的问题,有人回答正确后加分到200

hkbarton 2003-09-15 09:22:44
今天还以为在google上搜索到了,结果还是没有什么结果
问题描述:让窗口接收从网页或其他地方拖放过来的选中的文本进行处理
疑惑:处理WM_DrogFile消息只能接收拖动过来的文件,而不知道怎么接收一段选中的文本,它是否是一个临时存储的文件,还是一快内存中的临时区域
要求:给出大概的思路和实现方法即可,即要么用到什么api,要么是系统COM服务提供的接口名等等。。。
...全文
113 38 打赏 收藏 转发到动态 举报
写回复
用AI写文章
38 条回复
切换为时间正序
请发表友善的回复…
发表回复
hkbarton 2003-09-18
  • 打赏
  • 举报
回复
我已经解决了,再次感谢AWolfBoy(龍行江湖) 提供的资料
关于实现的文章我已经写了出来,发布以后大家去看看
gdfd 2003-09-17
  • 打赏
  • 举报
回复
在《Delphi深度探索》一书里有一章专门介绍。要实现Idroptarget接口。
hkbarton 2003-09-16
  • 打赏
  • 举报
回复
谢谢大家,我现在已经知道基本的实现方法了,等我实现后我会将全部方法写成文章,贴出来,因为我发现关于这个的讲的到是很多,但用delphi描述的很少
ly_liuyang 2003-09-16
  • 打赏
  • 举报
回复
OLE处理
组件DropMaster可以做到

For more information about DropMaster or other Raize Software products,
point your web browser to the Raize Software web site at:

http://www.raize.com
很土 2003-09-16
  • 打赏
  • 举报
回复
可能是内存地址越界, 你可能去释放不属于自己区域的指针, 或者说是内存.
hkbarton 2003-09-16
  • 打赏
  • 举报
回复
我晕,楼上给的是什么地址啊??
jsandy 2003-09-16
  • 打赏
  • 举报
回复
http://fengyebar.cn.st 看看这里
hkbarton 2003-09-16
  • 打赏
  • 举报
回复
p.s:我是在实现IDropTarget接口的那个类的析构函数中写的RevokeDragDrop
hkbarton 2003-09-16
  • 打赏
  • 举报
回复
最后一个问题(效果已经实现,但在退出是调用RevokeDragDrop释放窗体对OLE拖放的支持时总是出内存调用错误,如果不释放就没有错)
cmain83 2003-09-16
  • 打赏
  • 举报
回复
up
koma2003 2003-09-16
  • 打赏
  • 举报
回复
UP
leapmars 2003-09-16
  • 打赏
  • 举报
回复
听课
hkbarton 2003-09-16
  • 打赏
  • 举报
回复
ok,我怎么把这个重要的文件忘了啊,以前做COM都要引用的,这次是晕了,漏掉了它
AWolfBoy 2003-09-16
  • 打赏
  • 举报
回复
在ActiveX单元有
AWolfBoy 2003-09-16
  • 打赏
  • 举报
回复
可以参照VC或者C++Builder的自已实现呀
hkbarton 2003-09-16
  • 打赏
  • 举报
回复
现在又遇到一个小问题,我不知道delphi中的OLE Drag and Drop服务的IDropTarget接口装在哪个单元里,不在shlobj里,我看source里有一个ole2.pas的文件里也没有,呵呵,还真是麻烦啊
路人陈 2003-09-16
  • 打赏
  • 举报
回复
在memo里拖放文本:

type
TMyMemo = class(TMemo)
private
FLastSelStart : Integer;
FLastSelLength : Integer;
procedure WMLButtonDown(var Message: TWMLButtonDown);
message WM_LBUTTONDOWN;
published
property LastSelStart : Integer read FLastSelStart
write FLastSelStart;
property LastSelLength : Integer read FLastSelLength
write FLastSelLength;
end;

Make the implementation of WMLButtonDown look like this:

procedure TMyMemo.WMLButtonDown(var Message: TWMLButtonDown);
var
Ch : Integer;
begin
if SelLength > 0 then begin
Ch := LoWord(Perform(EM_CHARFROMPOS,0,
MakeLParam(Message.XPos,Message.YPos)));
LastSelStart := SelStart;
LastSelLength := SelLength;
if (Ch >= SelStart) and (Ch <= SelStart+SelLength-1) then
BeginDrag(True)
else
inherited;
end
else
inherited;
end;

Now, install this component into a package, start a brand new project
in Delphi 3 and drop two TMyMemos down.

Make them both have an OnDragOver event handler looking like this:

procedure TForm1.MyMemo1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
Accept := Source is TMyMemo;
end;

Make them both have an OnDragDrop event handler looking like this:

procedure TForm1.MyMemo1DragDrop(Sender, Source: TObject;
X, Y: Integer);
var
Dst, Src : TMyMemo;
Ch : Integer;
Temp : String;
begin
Dst := Sender as TMyMemo;
Src := Source as TMyMemo;
Ch := LoWord(Dst.Perform(EM_CHARFROMPOS,0,MakeLParam(X,Y)));

if (Src = Dst) and (Ch >= Src.LastSelStart) and
(Ch <= Src.LastSelStart+Src.LastSelLength-1) then
Exit;

Dst.Text := Copy(Dst.Text,1,Ch)+Src.SelText+
Copy(Dst.Text,Ch+1,Length(Dst.Text)-Ch);
Temp := Src.Text;
Delete(Temp,Src.LastSelStart+1,Src.LastSelLength);
Src.Text := Temp;
end;

hkbarton 2003-09-15
  • 打赏
  • 举报
回复
恩,我正在看,很有帮助,谢谢 你!实现了,就揭贴!
AWolfBoy 2003-09-15
  • 打赏
  • 举报
回复
http://www.cppfans.com/articles/system/oledroptext.asp
这个是C++Builder的,你只要做少少改动就可以了。
cbdiy 2003-09-15
  • 打赏
  • 举报
回复
三方控件:http://community.borland.com/homepages/dsp/ftp/d30free/dragdrop.exe
可以实现你的功能。
加载更多回复(18)

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧