6 Replies - 3701 Views - Last Post: 30 June 2010 - 03:16 PM Rate Topic: -----

#1 mocha1316  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 29-June 10

Help With Drag and Drop onto Executable

Posted 29 June 2010 - 02:02 PM

I need want to be able to drag and drop any file onto the executable and have the program return the dropped file path. I am using Windows Vista and have tried the following code but it doesn't work for me, when I drag the file over the executable it doesn't accept it, it just move the file beside the main executable. I included many headers just in case they were the cause, but to no avail it still didn't work.

If somebody could help me that would be MUCH appreciated.

#include <iostream>
#include <windows.h>
#include <shellapi.h>
#include <fstream>

using namespace std;
 
int main(int argc, char *argv[])
{

   if(argc < 2)
   {
	cout << "Drag and drop your files to the main executable" << endl;
	cin.get();
	return 0;
   }
   else
   {
       cout << "Successful\n";
       cout << "The File Location is: " << argv[1];
       cin.get();
   }
   return 0;
}


This post has been edited by mocha1316: 29 June 2010 - 06:51 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Help With Drag and Drop onto Executable

#2 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: Help With Drag and Drop onto Executable

Posted 30 June 2010 - 07:58 AM

Well I did this little test:

dragme.cpp
#include <iostream>

int main(int argc, char *args[]) {
    std::cout << "Arg count: " << argc << std::endl;
    for (int i = 0; i < argc; ++i) {
        std::cout << "arg[" << i << "] =\"" << args[i] <<"\"" << std::endl;
    }
    std::cin.get();
    return 0;
}


called it dragme.exe and when I drag and drop a file on it, things seem to work just fine for me on Windows 7.

I was thinking that you had to set something up with the properties of the file but I did not. It just seems to work.
Was This Post Helpful? 1
  • +
  • -

#3 mocha1316  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 29-June 10

Re: Help With Drag and Drop onto Executable

Posted 30 June 2010 - 10:25 AM

View PostNickDMax, on 30 June 2010 - 06:58 AM, said:

Well I did this little test:

dragme.cpp
#include <iostream>

int main(int argc, char *args[]) {
    std::cout << "Arg count: " << argc << std::endl;
    for (int i = 0; i < argc; ++i) {
        std::cout << "arg[" << i << "] =\"" << args[i] <<"\"" << std::endl;
    }
    std::cin.get();
    return 0;
}


called it dragme.exe and when I drag and drop a file on it, things seem to work just fine for me on Windows 7.

I was thinking that you had to set something up with the properties of the file but I did not. It just seems to work.

Thanks for the fairly quick reply.
First off i guess you meant on line 6 argv[i].
When I try to drag a file over it, it still pushes it aside.
I have included a screen shot of the problem.
Perhaps it is because I am using MS Visual C++ Express.
Is there a setting or something that you know about (or anybody else for that matter) that could be causing this problem?

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

#4 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Help With Drag and Drop onto Executable

Posted 30 June 2010 - 10:40 AM

First, this has nothing to do with the code or IDE. Drag and dropping a file over an executable is like invoking the executable with the filepath as the first argument. You can certainly open up a console and do this manually. Not hard.

So drag and dropping is a Windows thing. One thing that I think Windows does is prevent drag dropping when involving two different security..umm, whatever the name is. But let's say you have one security level for your executable. And there is another security level for the file in question. (For example, exe is allowed for your user, the file requires admin rights). Then, I think Windows prevents drag and dropping.

There's some tests you can do. For example, if you already know that you are dropping a file that requires admin privileges into an explorer window without such privileges...But can drag drop that pdb file onto the executable? How about creating a text file and dropping it? Is it a problem for all files?
Was This Post Helpful? 0
  • +
  • -

#5 mocha1316  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 29-June 10

Re: Help With Drag and Drop onto Executable

Posted 30 June 2010 - 11:42 AM

Well Oler1s, I have concluded that no files work when dragged and dropped. I am running Vista though which may be the cause. I read online that it might because of a security filter that Vista has, I'm not sure if OSs pre. or post. Vista have the problem. Thanks anyway NickDMax and Oler1s for your help.
Was This Post Helpful? 0
  • +
  • -

#6 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: Help With Drag and Drop onto Executable

Posted 30 June 2010 - 01:40 PM

Quote

First off i guess you meant on line 6 argv[i].


well no. I meant just exactly what is there. However notice that I named the array args[] and not argv[] -- you can use a different name (I think argv is the standard).

Based upon your BMP I would say you need to play arround with the OS a little. Put the exe on your desktop and try it from there. It looks as though you are trying to do it from a CD? You may also need to try while not in that particular mode of windows explorer.

Its not a programming thing, its an OS thing. So play with it a bit. The program I gave does work under windows 7 when I put the exe on my desktop and just drag random files to it.
Was This Post Helpful? 0
  • +
  • -

#7 mocha1316  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 29-June 10

Re: Help With Drag and Drop onto Executable

Posted 30 June 2010 - 03:16 PM

Sorry about that NickDMax, When I was copying it out I was caught in my usual practice.
From what I can tell it is ALL to do with the OS; Vista being the real problem.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1