Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dragging files onto exe's

Status
Not open for further replies.

Sherak

Programmer
Sep 1, 2003
83
GB
I have a program which decypers a text in a text file, baically you open the program and paste the contents of a text file into it and it will perform an operation.

What I want to know is if I drag a txt file over the executable the program will open but how do I get the contents of the text file and perform the operation on it if you get my drift, similar to if you drag a text file and drop it on wordpad or word it open the text in the relevant editor, same as draging a image into paint etc......

thanks
 
As far as i understand the _argv and _argc vill indicate that upon opening the EXE-file.

_argc holds the number of arguments and _argv[1] holds the first argument, _argv[2] the next and so forth.

_argv[0] holds the EXE-file complete path-and-name.

SO: if you drag the file "C:\Encrypted\SomeFile.txt" to the EXE-file the EXE-file will execute.

_argc will be 2 (1 means that only _argv[0] is present)
and _argv[1] will point on a string containing "C:\Encrypted\SomeFile.txt\0" (without the quotation marks)

Thus your EXE-file needs to know what to do with that data and *pooooffffff* - it does that!

Totte
Keep making it perfect and it will end up broken.
 
Thanks, totte to the rescue as always :) nice one.......
 
What Totte said is OK if you want to drag the file onto the icon of your application, but if you want to drag and drop the file into the Window of your app what you should do is something like this:
1.-Into the .h file write this in the public section
Code:
BEGIN_MESSAGE MAP
   MESSAGE_HANDLER (WM_DROPFILES, TMessage, WMDropFiles)
END_MESSAGE MAP (TComponent)

2.-In the private section write the event handler header:
Code:
void WMDropFiles (TMessage Message);
char FileName[256]; //Will save the name of the file

3.-The event handler should be something like this:
Code:
void Form1::WMDropFiles (TMessage Message)
{
  int FileCount = DragQueryFile ((HANDLE) Message.WParams, 
                                 -1, FileName, 255);
  //Where FileName is what you should add to the list
  //The param -1 is to get the total number of files dragged
}



--- LastCyborg ---
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top