Londer
一般會員
![](./myimg/board/mystar_empty.gif)
![](images/icon_photo_none.gif) 發表:5 回覆:32 積分:7 註冊:2003-01-08
發送簡訊給我
|
請問各位 BCB 的前輩大大們~~
在 http://delphi.ktop.com.tw/topic.php?topic_id=55712
一文中提到的從外部拖曳的方法是拖到 Form 裡的~~~~
不過小弟之前有在許偵翔大大的 BCB 小世界網站中~~
看過可以設定拖曳到個別元件去判斷的~~
例如 Panel1 或 Panel2 區裡~~不過 BCB 小世界關了~~
先前有存下來~~不過小弟硬碟前陣壞了之後~~
那些資料就都不見了~~現小弟有要用到~~但小弟已忘怎麼改~~~ >_<
請問有沒有哪位大大知道的呢???幫幫小弟救救火好嗎 >_<
小弟在此先跟各位大大說聲謝謝了 ^_^
|
m8815010
版主
![](./myimg/board/mystar.gif) ![](./myimg/board/mystar.gif) ![](./myimg/board/mystar.gif) ![](./myimg/board/mystar.gif)
![](images/icon_photo_none.gif) 發表:99 回覆:372 積分:289 註冊:2003-11-13
發送簡訊給我
|
引言:
請問各位 BCB 的前輩大大們~~
在 http://delphi.ktop.com.tw/topic.php?topic_id=55712
一文中提到的從外部拖曳的方法是拖到 Form 裡的~~~~
不過小弟之前有在許偵翔大大的 BCB 小世界網站中~~
看過可以設定拖曳到個別元件去判斷的~~
例如 Panel1 或 Panel2 區裡~~不過 BCB 小世界關了~~
先前有存下來~~不過小弟硬碟前陣壞了之後~~
那些資料就都不見了~~現小弟有要用到~~但小弟已忘怎麼改~~~ >_<
請問有沒有哪位大大知道的呢???幫幫小弟救救火好嗎 >_<
小弟在此先跟各位大大說聲謝謝了 ^_^
Londer你好 : 承接你的例子作例子,也就是假設現在你的>> 我採用方法二,因為直接改你提供的範例比較快、簡單! < class="code">
In .cpp
~~
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
DragAcceptFiles(Handle,true);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::OnDropFiles(TWMDropFiles & Msg)
{
int count=DragQueryFile((HDROP)Msg.Drop,0xFFFFFFFF,NULL,0); for (int i=0;iHandle,&rect1);
GetWindowRect(Panel2->Handle,&rect2);
POINT point;
GetCursorPos(&point); if (PtInRect(&rect1,point))
ShowMessage("Dragging in Panel1");
else if(PtInRect(&rect2,point))
ShowMessage("Draggng in Panel2");
else {
//不做任何事!
} delete []sFileName;
}
} 注意事項
1.判斷的方式很多,可判斷就可行< >
>
>
> 小小意見,參著參著< >!
|
Londer
一般會員
![](./myimg/board/mystar_empty.gif)
![](images/icon_photo_none.gif) 發表:5 回覆:32 積分:7 註冊:2003-01-08
發送簡訊給我
|
非常感謝 m8815010 版主大大的解答~
很抱歉這麼晚才回應,因為小弟在等原著許湞翔大大的回應,不過看來是等不到了 ^_^
小弟想要的是 http://delphi.ktop.com.tw/topic.php?topic_id=21001 這篇介紹裡所寫的 DragDrop2.zip 範例 ^_^
版大您提供的方式的確可行,非常的不錯,可是有一個缺點,
那就是在拖曳時滑鼠游標在整個 Form 的範圍內都會是拖曳狀態~
不知有沒有辦法變成只在 Panel1 及 Panel2 才變拖曳狀態呢?
小弟有試過將它 FormCreate 的事件裡的 DragAcceptFiles(Handle,true); 改成:
DragAcceptFiles(Panel1->Handle,true);
DragAcceptFiles(Panel2->Handle,true);
但這樣只有游標顯示正常而已,OnDropFiles 事件完全沒有觸發 >_<
請問版大或其它大大知不知道更改後該如何讓 OnDropFiles 觸發呢?
小弟同樣的先謝謝各位大大囉 ^_^
|
m8815010
版主
![](./myimg/board/mystar.gif) ![](./myimg/board/mystar.gif) ![](./myimg/board/mystar.gif) ![](./myimg/board/mystar.gif)
![](images/icon_photo_none.gif) 發表:99 回覆:372 積分:289 註冊:2003-11-13
發送簡訊給我
|
引言:
非常感謝 m8815010 版主大大的解答~
很抱歉這麼晚才回應,因為小弟在等原著許湞翔大大的回應,不過看來是等不到了 ^_^
小弟想要的是 http://delphi.ktop.com.tw/topic.php?topic_id=21001 這篇介紹裡所寫的 DragDrop2.zip 範例 ^_^
版大您提供的方式的確可行,非常的不錯,可是有一個缺點,
那就是在拖曳時滑鼠游標在整個 Form 的範圍內都會是拖曳狀態~
不知有沒有辦法變成只在 Panel1 及 Panel2 才變拖曳狀態呢?
小弟有試過將它 FormCreate 的事件裡的 DragAcceptFiles(Handle,true); 改成:
DragAcceptFiles(Panel1->Handle,true);
DragAcceptFiles(Panel2->Handle,true);
但這樣只有游標顯示正常而已,OnDropFiles 事件完全沒有觸發 >_<
請問版大或其它大大知不知道更改後該如何讓 OnDropFiles 觸發呢?
小弟同樣的先謝謝各位大大囉 ^_^
Londer你好 : 承之前回覆,你的現在的問題就應該用我的法二解決了! 還是假設現在 class="code">
In Unit1.h ~~
class TForm1 : public TForm
{
__published: // IDE-managed Components
TPanel *Panel1; <--Add
TPanel *Panel2; <--Add
void __fastcall FormCreate(TObject *Sender);
private: // User declarations
TWndMethod OldPanel1WndProc; <--Add
void __fastcall Panel1WndProc(TMessage& Message); <--Add
TWndMethod OldPanel2WndProc; <--Add
void __fastcall Panel2WndProc(TMessage& Message); <--Add
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
In Unit1.cpp ~~
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
OldPanel1WndProc=Panel1->WindowProc;
Panel1->WindowProc=Panel1WndProc;
OldPanel2WndProc=Panel2->WindowProc;
Panel2->WindowProc=Panel2WndProc;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Panel1WndProc(TMessage& Message)
{
if (Message.Msg==WM_DROPFILES) {
int count=DragQueryFile((HDROP)Message.WParam,0xFFFFFFFF,NULL,0); // 取得拖曳過來的個數 for (int i=0;iCaption=sFileName;
delete []sFileName;
}
} OldPanel1WndProc(Message);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Panel2WndProc(TMessage& Message)
{
if (Message.Msg==WM_DROPFILES) {
int count=DragQueryFile( (HDROP)Message.WParam,0xFFFFFFFF,NULL,0); // 取得拖曳過來的個數 for (int i=0;iCaption=sFileName;
delete []sFileName;
}
} OldPanel2WndProc(Message);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
DragAcceptFiles(Panel1->Handle,true);
DragAcceptFiles(Panel2->Handle,true);
}
//---------------------------------------------------------------------------
Conclusion
1.這個方法就是分別針對Panel1及Panel2各寫一次FileDrog的處理程式,使之都有能力處理FileDrog
2.Form沒寫,當然沒有這種能力
3.萬一有很多元件的話,如Panel1、Panel2、.....,則要盡量將事件共同引用,才不用各寫一次
4.我的寫法可能和之前略有不同,但意義同 5.如有程式寫作面的疑問,請再自行survey站上文章,無法在此詳述太多 !
> >!
|
Londer
一般會員
![](./myimg/board/mystar_empty.gif)
![](images/icon_photo_none.gif) 發表:5 回覆:32 積分:7 註冊:2003-01-08
發送簡訊給我
|
哇~~感謝 m8815010 版主大大~~您真的是太強了 ^_^
您這種寫法完全不需用到 Message Map,簡直是更勝從前啊 ^_^
而且功能完全符合小弟的需求呢~我已經無法用言語來形容我的感激之意了 ^_^
但除了說謝謝之外,我真的不知道我還能做什麼 ^_^
所以還是要向您說:非常感謝 感激 感恩版大的熱心解答喔 ^_^
|
Londer
一般會員
![](./myimg/board/mystar_empty.gif)
![](images/icon_photo_none.gif) 發表:5 回覆:32 積分:7 註冊:2003-01-08
發送簡訊給我
|
哇~~感謝 m8815010 版主大大~~您真的是太強了 ^_^
您這種寫法完全不需用到 Message Map,簡直是更勝從前啊 ^_^
而且功能完全符合小弟的需求呢~我已經無法用言語來形容我的感激之意了 ^_^
但除了說謝謝之外,我真的不知道我還能做什麼 ^_^
所以還是要向您說:非常感謝+感激+感恩版大的熱心解答喔 ^_^
< >< >< >< >< >< >< >< >< >< >< >< >
|