用API时遇到一个小问题! (20分)

  • 主题发起人 主题发起人 yuzhizhi
  • 开始时间 开始时间
Y

yuzhizhi

Unregistered / Unconfirmed
GUEST, unregistred user!
我在做一个拖放的程序时!用到了WM_DropFile消息字时!<br>Procedure WM_DropFile(Var Msg:TMessage);Message WM_DropFile;<br>Implementation;<br>Procedure WM_DropFile(var Msg:TMessage);<br>begin<br>??//怎么编写!<br>end;<br>我已经编写好单个文件拖放!就不知道怎么拖放多个文件到 TListBox对像中!<br>
 
{ Private declarations }<br>&nbsp; Dragging: Boolean;<br>&nbsp; OldIndex: Integer;<br>&nbsp; TempStr: String;<br><br>procedure TForm1.ListBox1MouseUp(Sender: TObject; Button: TMouseButton;<br>&nbsp; Shift: TShiftState; X, Y: Integer);<br>var <br>&nbsp; Index: integer;<br>begin<br>&nbsp; if Dragging then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Index := ListBox1.ItemAtPos(point(x, y), true);<br>&nbsp; &nbsp; &nbsp; if (Index &gt; -1) and (Index &lt;&gt; OldIndex) then<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ListBox1.Items.Delete(OldIndex);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ListBox1.Items.Insert(Index, TempStr);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ListBox1.ItemIndex := Index; <br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; end; <br>&nbsp; Dragging := false;<br>end;<br><br>procedure TForm1.ListBox1MouseDown(Sender: TObject; Button: TMouseButton;<br>&nbsp; Shift: TShiftState; X, Y: Integer);<br>var <br>&nbsp; Index: integer;<br>begin<br>&nbsp; Index := ListBox1.ItemAtPos(point(x, y), true);<br>&nbsp; if Index &gt; -1 then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; TempStr := ListBox1.Items[Index];<br>&nbsp; &nbsp; &nbsp; OldIndex := Index;<br>&nbsp; &nbsp; &nbsp; Dragging := true;<br>&nbsp; &nbsp; end; <br>end;
 
我是在外面拖放文件到TListBox中!<br>不是在TListBox中的文件之间地拖放!
 
var<br>&nbsp; &nbsp; Fname &nbsp;:pchar;<br>&nbsp;if msg.message=wm_DropFiles then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; getmem(Fname,250);<br>&nbsp; &nbsp; &nbsp; &nbsp; dragqueryFile(msg.wParam,0,fname,250); <br>&nbsp; &nbsp; &nbsp; &nbsp; dragFinish(msg.wParam);<br>&nbsp; &nbsp; &nbsp; &nbsp; listbox1.Items.Clear;<br>&nbsp; &nbsp; &nbsp; &nbsp; libname:=string(Fname);<br>&nbsp; &nbsp; &nbsp; &nbsp; index:=0;<br>&nbsp; &nbsp; &nbsp; &nbsp; while pchar(fname)&gt;0 do<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; listbox1.items.add(intTostr(index));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; inc(index);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if listbox1.Items.count&gt;0<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; then listbox1.PopupMenu:=popupmenu1<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else listbox1.popupmenu:=nil;<br>&nbsp; &nbsp; &nbsp; &nbsp; freemem(Fname,250);<br>&nbsp; &nbsp; &nbsp; &nbsp; handled:=true;<br>&nbsp; &nbsp; &nbsp; end;
 
这个方法不对!
 
呵呵,托放一个文件你都会了,多个还不会<br>见804367,就可以了
 
后退
顶部