开发者

WMDropFiles problem on win7

开发者 https://www.devze.com 2023-04-02 02:05 出处:网络
I\'ve implemented the following procedure and it works properly when I compile it on my computer running windows vista, computer #1. If I share the created .exe file to another computer running win7,

I've implemented the following procedure and it works properly when I compile it on my computer running windows vista, computer #1. If I share the created .exe file to another computer running win7, computer #2, it runs fine aswell. The problem is when I let the computer #2 compile it, it wont simply recognize that anything's dropped on the application. There's no response at all in this code. It's built and compiled without errors or warnings. I've been searching the net for a while without finding anything that explains why this happens or someone else with开发者_如何学编程 this problem.

Both computers use Delphi 2010 with the same components installed.

  1. Is this the way to go to allow the user to drop files onto the application? If not, how should it be done nowdays?
  2. Any ideas why it works when it's compiled on computer #1 but not computer #2? (The program works properly on both computers when compiled on computer #1)

Any help or comment is highly appreciated.

procedure TfMainForm.WMDROPFILES(var msg: TWMDropFiles);
const
  MaxLength = 255;

var
  nFiles : integer;
  i : integer;
  fileName : array [0..MaxLength] of char;
  fileNames : TStringArray;

begin
  // Get number of files dropped
  nFiles := DragQueryFile(msg.Drop,  $FFFFFFFF, fileName, MaxLength);

  // Get filenames
  SetLength(fileNames, nFiles);
  for i := 0 to nFiles - 1 do begin
    DragQueryFile(msg.Drop, i, fileName, MaxLength);
    fileNames[i] := fileName;
  end;

    // Add files
  projectHandler.addFiles(fileNames);

  //release memory
  DragFinish(msg.Drop);
end;


I'm going to take a wild guess that if you are running from within the IDE on computer #2. I bet that if you compile on computer #2 but start the executable from explorer rather than from the IDE, it works. The final piece of the jigsaw is that I bet you are running your IDE on computer #2 as administrator.

On Vista and Windows 7 you can't send messages to a process with a higher integrity level. If your process is being run as administrator then it will have a higher integrity level than explorer and so won't accept the dropped files.

If my guess is correct I recommend that you stop running Delphi as administrator, it doesn't need this.

As for whether or not WM_DROPFILES is a reasonable approach, I see no problems with using it.


At http://www.web-developer.de/content/download/7387/137496/file/Listings.zip you can find an example written using Delphi XE (compiles with D2010 as well). The subfolder "2_WmDropFiles" contains a project "WmDropFiles.dpr" that shows how to an app that runs elevated can receive files from an app which does not run elevated. The comments etc. are in German, so please use Google translate when in doubt.

Hope this helps, Olaf

0

精彩评论

暂无评论...
验证码 换一张
取 消