線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:2856
推到 Plurk!
推到 Facebook!

從外部視窗(如檔案總管)拖曳檔案到form裡

 
anpino
版主


發表:31
回覆:477
積分:231
註冊:2003-01-02

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-11-19 14:16:19 IP:218.32.xxx.xxx 未訂閱
這需要使用函式append winProc  
    // (1) 在form 的class 內加入以下程式碼:    class TForm1 : public TForm
{
...........
public:
        void __fastcall OnDropFiles(TWMDropFiles & Msg);
        // 自訂一個接收檔案後, 處理檔案的函式. 在這裡我訂為OnDropFiles.
protected:
    BEGIN_MESSAGE_MAP
                VCL_MESSAGE_HANDLER(WM_DROPFILES, TWMDropFiles, OnDropFiles)
                // WM_DROPFILES : 拖曳檔案時, Window 會自動送出的訊息.並執行OnDropFiles函式.TWMDropFiles 為OnDropFiles函式的參數型態.        END_MESSAGE_MAP(TForm) 
};    // (2) 
void __fastcall TForm1::FormCreate(TObject *Sender)
{        DragAcceptFiles(Handle,true);
    // 將form 註冊為可拖曳.
}    void __fastcall TForm1::OnDropFiles(TWMDropFiles & Msg)
{
        DWORD nFileNameSize=DragQueryFile( (HDROP)Msg.Drop,0,NULL,0); // 取得拖曳過來的檔案大小
        char * sFileName=new char[nFileNameSize 1];
        DragQueryFile((HDROP)Msg.Drop,0,sFileName,nFileNameSize 1); // 取得拖曳過來的檔案的檔名:sFileName
        
         // 你的檔案處理程式碼            delete []sFileName;    }
 
數學系是內功很強(邏輯/分析) 資工系是招式很多(程式技巧) 就像令狐沖VS東方不敗:D [url="http://anpino.begin.8d8d.com"]Programmer's Guide[/url] 發表人 - anpino 於 2003/11/19 15:35:10
anpino
版主


發表:31
回覆:477
積分:231
註冊:2003-01-02

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-11-27 14:42:11 IP:218.32.xxx.xxx 未訂閱
這裡沒辦法上傳程式, 所以我把程式放在: http://delphi.ktop.com.tw/topic.php?TOPIC_ID=41161 數學系是內功很強(邏輯/分析) 資工系是招式很多(程式技巧) 就像令狐沖VS東方不敗:D
anpino
版主


發表:31
回覆:477
積分:231
註冊:2003-01-02

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-11-19 12:01:04 IP:211.23.xxx.xxx 未訂閱
//---------------------------------------------- // 方法三 //----------------------------------------------    
class TForm1 : public TForm
{
    ...
public: // User declarations
    void __fastcall AppWndProc(TMessage& Message);
};    __fastcall TForm1::TForm1(TComponent* Owner): TForm(Owner)
{
    WindowProc = AppWndProc;
    // 覆寫Windows 訊息處理函式。
     // 詳見 MSDN 與 BCB HELP 中對 WindowProc 與 WndProc 的說明。
}    void __fastcall TForm1::FormCreate(TObject *Sender)
{
    DragAcceptFiles(Handle,true);
    // 將form 註冊為可拖曳.
}    void __fastcall TForm1::AppWndProc(TMessage& Message)
{
    if (Message.Msg == WM_DROPFILES )
    {
        DWORD nFileNameSize=DragQueryFile( (HDROP)Message.WParam,0,NULL,0); 
        // 取得拖曳過來的檔名長度
        // 允許拖曳多個檔案, 詳見MSDN 中對 DragQueryFile 的說明。                char * sFileName=new char[nFileNameSize 1];
        DragQueryFile((HDROP)Message.WParam,0,sFileName,nFileNameSize 1); // 取得拖曳過來的檔案的檔名:sFileName            // 你的檔案處理程式碼            delete []sFileName;
    }            WndProc(Message);
    // 擲回Windows 預設訊息處理函式, 處理其他訊息。
    // 詳見 MSDN 與 BCB HELP 中對 WindowProc 與 WndProc 的說明。
}
------------------------------- 數學系是內功很強(邏輯/分析) 資工系是招式很多(程式技巧) 就像令狐沖VS東方不敗:D Anpinos Middle Earth http://anpino.hp.infoseek.co.jp/ -------------------------------
anpino
版主


發表:31
回覆:477
積分:231
註冊:2003-01-02

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-11-19 12:04:12 IP:211.23.xxx.xxx 未訂閱
//********************************************* //  補充 //********************************************* 方法一與方法二都是針對"整個"form的總訊息做處理。 若要單獨針對"某個元件"(Component)做拖曳, 可用方法三實作:    
class TForm1 : public TForm
{
    ...
public: // User declarations
    void __fastcall ComponentWndProc(TMessage& Message);
};    __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner)
{
    (Component)->WindowProc = ComponentWndProc;
}    void __fastcall TForm1::FormCreate(TObject *Sender)
{
    DragAcceptFiles((Component)->Handle,true);
    // 將(Component) 註冊為可拖曳.
}    void __fastcall TForm1::ComponentWndProc(TMessage& Message)
{
    if (Message.Msg == WM_DROPFILES )
    {
        DWORD nFileNameSize=DragQueryFile( (HDROP)Message.WParam,0,NULL,0); 
        char * sFileName=new char[nFileNameSize 1];
        DragQueryFile((HDROP)Message.WParam,0,sFileName,nFileNameSize 1); // 取得拖曳過來的檔案的檔名:sFileName            // 你的檔案處理程式碼            delete []sFileName;
    }    
    (Component)->WndProc(Message);
}
------------------------------- 數學系是內功很強(邏輯/分析) 資工系是招式很多(程式技巧) 就像令狐沖VS東方不敗:D Anpinos Middle Earth http://anpino.hp.infoseek.co.jp/ -------------------------------
系統時間:2024-04-29 3:13:50
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!