大家来讨论一下关于拖放的问题!!(29分)

L

lon911

Unregistered / Unconfirmed
GUEST, unregistred user!
我想和大家讨论一下关于拖放问题,类似于蚂蚁一样,但要比它复杂。<br>我写了一个拖放窗口下面是原代码<br>private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; &nbsp; //创建拖放窗口<br>&nbsp; &nbsp; procedure Createparams(Var Params:TCreateParams);override;<br>&nbsp; &nbsp;//拖放窗口的移动<br>&nbsp; &nbsp; procedure WMNCHitTest( var Msg : TWMNCHitTest );message wm_NCHitTest;<br>………………<br>//在窗口上按下鼠标移动窗口<br>procedure TfrmDarg.WMNCHitTest( var Msg : TWMNCHitTest );<br>begin<br>&nbsp; if &nbsp;GetAsyncKeyState(VK_LButton) &lt; 0 then<br>&nbsp; &nbsp; &nbsp;Msg.Result := HTCaption<br>&nbsp; else<br>&nbsp; &nbsp; &nbsp;Msg.Result := HTCLient;<br>end;<br>//创建窗口<br>procedure TfrmDarg.Createparams(var Params:TCreateParams);<br>begin<br>&nbsp; Inherited CreateParams(Params);<br>&nbsp; With Params do<br>&nbsp; begin<br>&nbsp; &nbsp; //Width:=40;<br>&nbsp; &nbsp; //Height:=40;<br>&nbsp; &nbsp; Style :=WS_CAPTION;<br>&nbsp; &nbsp; Style :=WS_POPUP;<br>&nbsp; &nbsp; EXStyle:=ExStyle or WS_EX_TOPMOST;// OR WS_EX_ACCEPTFILES or WS_DLGFRAME or WM_NCHITTEST;<br>&nbsp; &nbsp; WndParent:=GetDeskTopWindow();<br>&nbsp; end;<br>end;<br>这是窗口代码,现在让我们来讨论一下拖放的问题吧!<br><br><br>
 
unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, ShellApi, StdCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Memo1: TMemo;<br>&nbsp; &nbsp; procedure CreateParams(var Params:TCreateParams);override;<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; &nbsp; procedure WMDropFiles(var Msg:TWMDropFiles);message WM_DROPFILES;<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>{ TForm1 }<br><br>procedure TForm1.CreateParams(var Params: TCreateParams);<br>begin<br>&nbsp; inherited CreateParams(Params);<br>&nbsp; Params.ExStyle:=Params.ExStyle or WS_EX_ACCEPTFILES;<br>end;<br><br>procedure TForm1.WMDropFiles(var Msg: TWMDropFiles);<br>var<br>&nbsp; FCount:integer;<br>&nbsp; i:integer;<br>&nbsp; P:pchar;<br>begin<br>&nbsp; GetMem(P,MAX_PATH);<br>&nbsp; try<br>&nbsp; &nbsp; FCount:=DragQueryFile(Msg.Drop,DWORD(-1),nil,0);<br>&nbsp; &nbsp; for i:=0 to FCount-1 do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; DragQueryFile(Msg.Drop,i,P,MAX_PATH);<br>&nbsp; &nbsp; &nbsp; Memo1.Lines.Add(StrPas(P));<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; DragFinish(Msg.Drop);<br>&nbsp; finally<br>&nbsp; &nbsp; FreeMem(P);<br>&nbsp; end;<br>&nbsp; inherited;<br>end;<br><br>end.<br>
 
我在Delphi6下实现的,测试过了
 
谢谢楼上的,有没有更好的办法
 
这是最简单的,还可以用Shell做,当然要复杂多啦<br>因为涉及到Com
 
楼上的你只是把读取文件路径我要的是内容,当然是文本或网页的<br>另外要可以把选中的文本内容也拖进来
 
用com的,有相关控件源码参考。
 
怎么没人了吗
 
我也想学习
 
怎么没人了
 
去下载“DragDrop”控件看看吧,好象“海阔天空”有。
 
懒得再写了把原来写的茶房系统,创建茶桌对象和拖放都贴出来<br><br>//---------------------------------------------------------------------------<br><br>#include &lt;vcl.h&gt;<br>#pragma hdrstop<br><br>#include "table.h"<br>#include "dm.h"<br>#include "sy.h"<br>#include "main.h"<br>#include "khxz.h"<br>#include "myinput.h"<br>//---------------------------------------------------------------------------<br>#pragma package(smart_init)<br>#pragma resource "*.dfm"<br>Tfmtable *fmtable;<br>//---------------------------------------------------------------------------<br>__fastcall Tfmtable::Tfmtable(TComponent* Owner)<br>&nbsp; &nbsp; : TForm(Owner)<br>{<br>}<br>//---------------------------------------------------------------------------<br><br>void Tfmtable::createimg(int i,int x,int y,int letzwh,Currency lsj,Currency hyj,AnsiString l1cap,AnsiString l2cap)<br>{<br>&nbsp; &nbsp; m1.i1=new TImage(Application);<br>&nbsp; &nbsp; m1.i1-&gt;Parent=this-&gt;ScrollBox1;<br>&nbsp; &nbsp; m1.i1-&gt;Picture-&gt;LoadFromFile("F://茶房前台//res//amplifier.ico");<br>&nbsp; &nbsp; m1.i1-&gt;AutoSize=true;<br>&nbsp; &nbsp; m1.i1-&gt;Name="im"+IntToStr(i);<br>&nbsp; &nbsp; m1.i1-&gt;Top=y;<br>&nbsp; &nbsp; m1.i1-&gt;Left=x;<br>&nbsp; &nbsp; m1.i1-&gt;Transparent=true;<br>&nbsp; &nbsp; m1.i1-&gt;PopupMenu=this-&gt;PopupMenu1;<br>&nbsp; &nbsp; m1.i1-&gt;DragMode=dmAutomatic;<br><br>&nbsp; &nbsp; m1.l1=new TLabel(Application);<br>&nbsp; &nbsp; m1.l1-&gt;Parent=this-&gt;ScrollBox1;<br>&nbsp; &nbsp; m1.l1-&gt;Top=m1.i1-&gt;Top+m1.i1-&gt;Height+2;<br>&nbsp; &nbsp; m1.l1-&gt;Left=m1.i1-&gt;Left;<br>&nbsp; &nbsp; m1.l1-&gt;Caption=l1cap;//dm1-&gt;qr_tea_zwjbxxzwmc-&gt;Value;<br>&nbsp; &nbsp; m1.l1-&gt;Transparent=true;<br><br>&nbsp; &nbsp; m1.setxpos(120);<br><br>&nbsp; &nbsp; m1.myzwh=letzwh;<br>&nbsp; &nbsp; m1.zwlsj=lsj;<br>&nbsp; &nbsp; m1.zwhyj=hyj;<br><br>&nbsp; &nbsp; m1.l2=new TLabel(Application);<br>&nbsp; &nbsp; m1.l2-&gt;Parent=this-&gt;ScrollBox1;<br>&nbsp; &nbsp; m1.l2-&gt;Top=m1.i1-&gt;Top+m1.i1-&gt;Height+16;<br>&nbsp; &nbsp; m1.l2-&gt;Left=m1.i1-&gt;Left;<br>&nbsp; &nbsp; m1.l2-&gt;Caption=l2cap;<br>&nbsp; &nbsp; m1.l2-&gt;Transparent=true;<br>&nbsp; &nbsp; if (m1.l2-&gt;Caption=="无人 &nbsp; &nbsp; &nbsp;") m1.l2-&gt;Font-&gt;Color=clBlue;<br>&nbsp; &nbsp; &nbsp; &nbsp;else m1.l2-&gt;Font-&gt;Color=clRed;<br>&nbsp; &nbsp; &nbsp; &nbsp;m1.setxpos(120);<br>}<br><br>void __fastcall Tfmtable::FormShow(TObject *Sender)<br>{<br>&nbsp; &nbsp; <br>&nbsp; &nbsp; dm1-&gt;qr_tea_zwjbxx-&gt;Close();<br>&nbsp; &nbsp; dm1-&gt;qr_tea_zwjbxx-&gt;Open();<br>&nbsp; &nbsp; zwcount=dm1-&gt;qr_tea_zwjbxx-&gt;RecordCount;<br><br>&nbsp; &nbsp; dm1-&gt;qr_tea_zwjbxx-&gt;First();<br><br><br>&nbsp; &nbsp; for(int i=0;i&lt;zwcount;i++)<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; if (i&gt;=1)dm1-&gt;qr_tea_zwjbxx-&gt;Next();<br>&nbsp; &nbsp; createimg(i,dm1-&gt;qr_tea_zwjbxxzwx-&gt;Value,dm1-&gt;qr_tea_zwjbxxzwy-&gt;Value,dm1-&gt;qr_tea_zwjbxxzwh-&gt;Value,dm1-&gt;qr_tea_zwjbxxzwlsj-&gt;Value,dm1-&gt;qr_tea_zwjbxxzwhyj-&gt;Value,dm1-&gt;qr_tea_zwjbxxzwmc-&gt;Value,dm1-&gt;qr_tea_zwjbxxkhh-&gt;Value);<br>&nbsp; &nbsp; }<br>}<br>//---------------------------------------------------------------------------<br>void mypic::dragl1()<br>{<br>&nbsp; &nbsp; l1-&gt;Top=i1-&gt;Top+i1-&gt;Height;<br>&nbsp; &nbsp; l1-&gt;Left=i1-&gt;Left;<br>&nbsp; &nbsp; l2-&gt;Top=i1-&gt;Top+i1-&gt;Height+16;<br>&nbsp; &nbsp; l2-&gt;Left=i1-&gt;Left;<br>}<br>void mypic::setxpos(int a)<br>{<br>&nbsp; &nbsp; xpos=a;<br>}<br>//---------------------------------------------------------------------------<br>int mypic::getxpos()<br>{<br>&nbsp; &nbsp; return xpos;<br>}<br><br>void __fastcall Tfmtable::Image1DragOver(TObject *Sender, TObject *Source,<br>&nbsp; &nbsp; &nbsp; int X, int Y, TDragState State, bool &amp;Accept)<br>{<br>&nbsp; &nbsp; Accept=true;<br>}<br>//---------------------------------------------------------------------------<br><br>void __fastcall Tfmtable::Image1DragDrop(TObject *Sender, TObject *Source,<br>&nbsp; &nbsp; &nbsp; int X, int Y)<br>{<br>&nbsp; &nbsp; TImage* source=(TImage*) Source;<br><br>&nbsp; &nbsp; AnsiString s1;<br>&nbsp; &nbsp; s1=Trim(source-&gt;Name);<br>&nbsp; &nbsp; s1=s1.SubString(3,s1.Length()-2);<br>&nbsp; &nbsp; int j;<br>&nbsp; &nbsp; j=s1.ToInt();<br><br>&nbsp; &nbsp; m1[j].i1-&gt;Left=X - this-&gt;ScrollBox1-&gt;HorzScrollBar-&gt;Position;<br>&nbsp; &nbsp; m1[j].i1-&gt;Top=Y - this-&gt;ScrollBox1-&gt;VertScrollBar-&gt;Position;<br>&nbsp; &nbsp; m1[j].dragl1();<br><br>&nbsp; &nbsp; dm1-&gt;q_ty-&gt;Close();<br>&nbsp; &nbsp; dm1-&gt;q_ty-&gt;SQL-&gt;Clear();<br>&nbsp; &nbsp; dm1-&gt;q_ty-&gt;SQL-&gt;Add ("update tea_zwjbxx");<br>&nbsp; &nbsp; dm1-&gt;q_ty-&gt;SQL-&gt;Add ("set zwx="+IntToStr(m1[j].i1-&gt;Left));<br>&nbsp; &nbsp; dm1-&gt;q_ty-&gt;SQL-&gt;Add (", zwy="+IntToStr(m1[j].i1-&gt;Top));<br>&nbsp; &nbsp; dm1-&gt;q_ty-&gt;SQL-&gt;Add ("where zwh="+IntToStr(m1[j].myzwh));<br>&nbsp; &nbsp; dm1-&gt;q_ty-&gt;ExecSQL();<br><br><br><br>}<br>//---------------------------------------------------------------------------<br><br><br>void __fastcall Tfmtable::FormClose(TObject *Sender, TCloseAction &amp;Action)<br>{<br>&nbsp; &nbsp; &nbsp; &nbsp; Action=caFree;<br>}<br>//---------------------------------------------------------------------------<br><br>void __fastcall Tfmtable::p1Click(TObject *Sender)<br>{<br>&nbsp; &nbsp; if (!fmmain-&gt;openform("fmsy"))<br>&nbsp; &nbsp; &nbsp; &nbsp;{<br>&nbsp; &nbsp; &nbsp; &nbsp;Tfmsy *t1;<br>&nbsp; &nbsp; &nbsp; &nbsp;t1=new Tfmsy(Application);<br>&nbsp; &nbsp; &nbsp; &nbsp;t1-&gt;ShowModal();<br>&nbsp; &nbsp; &nbsp; &nbsp;}<br>}<br>//---------------------------------------------------------------------------<br><br>void __fastcall Tfmtable::p2Click(TObject *Sender)<br>{<br>&nbsp; &nbsp; if (!fmmain-&gt;openform("fmxzkr"))<br>&nbsp; &nbsp; &nbsp; &nbsp;{<br>&nbsp; &nbsp; &nbsp; &nbsp;Tfmxzkr *t1;<br>&nbsp; &nbsp; &nbsp; &nbsp;t1=new Tfmxzkr(Application);<br>&nbsp; &nbsp; &nbsp; &nbsp;t1-&gt;ShowModal();<br>&nbsp; &nbsp; &nbsp; &nbsp;}<br>}<br>//---------------------------------------------------------------------------<br><br><br>void __fastcall Tfmtable::popupMenu1Popup(TObject *Sender)<br>{<br>&nbsp; p1-&gt;Enabled=true;<br>&nbsp; p2-&gt;Enabled=true;<br>&nbsp; AnsiString temzwh1;<br>&nbsp; temzwh1=PopupMenu1-&gt;PopupComponent-&gt;Name;<br>&nbsp; temzwh1=temzwh1.SubString(3,temzwh1.Length()-2);<br>&nbsp; m1i=StrToInt(temzwh1);<br>&nbsp; temzwh=m1[m1i].myzwh;<br>&nbsp; temkhh=m1[m1i].l2-&gt;Caption;<br>&nbsp; temkhh=m1[m1i].l2-&gt;Caption;<br>&nbsp; temzwmc=m1[m1i].l1-&gt;Caption;<br>&nbsp; temkhh=m1[m1i].l2-&gt;Caption;<br><br><br><br>&nbsp; if (temkhh=="无人 &nbsp; &nbsp; &nbsp;")<br>&nbsp; &nbsp; &nbsp;p1-&gt;Enabled=false;<br>&nbsp; else<br>&nbsp; &nbsp; &nbsp;p2-&gt;Enabled=false;<br><br>}<br>//---------------------------------------------------------------------------<br><br><br>void __fastcall Tfmtable::ToolButton1Click(TObject *Sender)<br>{<br><br>&nbsp; &nbsp; newzwmc="";<br>&nbsp; &nbsp; if (!fmmain-&gt;openform("fminput"))<br>&nbsp; &nbsp; &nbsp; &nbsp;{<br>&nbsp; &nbsp; &nbsp; &nbsp;Tfminput *t1;<br>&nbsp; &nbsp; &nbsp; &nbsp;t1=new Tfminput(Application);<br>&nbsp; &nbsp; &nbsp; &nbsp;t1-&gt;ShowModal();<br>&nbsp; &nbsp; &nbsp; &nbsp;}<br>}<br>//---------------------------------------------------------------------------<br><br>void __fastcall Tfmtable::ToolButton3Click(TObject *Sender)<br>{<br>&nbsp; &nbsp; Close();<br>}<br>//---------------------------------------------------------------------------<br>
 
高手,我晕了
 
还有没有人
 
拖放窗体(注意这里的窗体是windows编程的概念,如edit,button也是)可以通过wm_syscommand消息进行处理
 
你到底想拖放什么?<br>不同的东西编程是不一样的。
 
顶部