2012-07-12 52 views
2

我有一個表單接受要拖放的文件,以及放置在同一表單上的TPanel控件上的TWebBrowser控件。防止TWebBrowser接受丟棄的文件

最主要的是,當我在窗體上放置一個文件時,它的路徑被添加到一個TEdit控件中。但是,當用戶在表單上拖放文件時,有時他們可能會將其放到TWebBrowser上,這會根據文件類型爲用戶保存或運行文件。這是我實際上不希望發生的事情,我只想讓TWebBrowser忽略掉落的文件或按照表單處理它。

這是我使用治療WM_DROPFILES消息代碼:

procedure TMainForm.AcceptFiles(var msg : TMessage); 
const 
    cnMaxFileNameLen = 255; 
var 
    i, 
    nCount  : integer; 
    acFileName : array [0..cnMaxFileNameLen] of char; 
begin 
    // find out how many files we're accepting 
    nCount := DragQueryFile(msg.WParam, 
          $FFFFFFFF, 
          acFileName, 
          cnMaxFileNameLen); 

    // query Windows one at a time for the file name 
    for i := 0 to nCount-1 do 
    begin 
    DragQueryFile(msg.WParam, i, 
        acFileName, cnMaxFileNameLen); 

    // do your thing with the acFileName 
    //MessageBox(Handle, acFileName, '', MB_OK); 
    Edit1.Text := acFileName; 
    end; 

    // let Windows know that you're done 
    DragFinish(msg.WParam); 
end; 

預先感謝您。任何線索將不勝感激。

回答