Drag n' Drop 'any file'

This is a discussion on Drag n' Drop 'any file' within the C++ Programming forums, part of the General Programming Boards category; .... and have the prog. open it. My question is, is there method of doing that and if so, using ...

  1. #1
    Registered User
    Join Date
    Dec 2006
    Location
    Scranton, Pa
    Posts
    252

    Drag n' Drop 'any file'

    .... and have the prog. open it. My question is, is there method of doing that and if so,
    using what library?

    I don't want any user input for this particular utility, just drag n' drop any file onto the console window.

  2. #2
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465

    ╔╗╔╦══╦╗╔╦══╦╗
    ║╚╝║╔╗║╚╝║╔╗║║
    ║╔╗║╠╣║╔╗║╠╣╠╣
    ╚╝╚╩╝╚╩╝╚╩╝╚╩╝

    codez http://code.google.com/p/zxcvbn/

  3. #3
    Registered User
    Join Date
    Dec 2006
    Location
    Scranton, Pa
    Posts
    252
    Thanks, though I was referring to something much simpler; a console program. ie:

    Code:
    ifstream fin(getFile, ios::in | ios::beg );
    
    // whereas 'getFile' is a wildcard; any file dropped onto window
    I know that it can be done (but I don't know how) and I hope that it doesn't turn out to be some convoluted mess of code.

  4. #4
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Well, just dragging shell objects onto the console window effectively pastes their filename, which can be read by standard means. And then you can just use the ifstream on what you have read. Very simple really.

    ╔╗╔╦══╦╗╔╦══╦╗
    ║╚╝║╔╗║╚╝║╔╗║║
    ║╔╗║╠╣║╔╗║╠╣╠╣
    ╚╝╚╩╝╚╩╝╚╩╝╚╩╝

    codez http://code.google.com/p/zxcvbn/

  5. #5
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    902
    If you mean drag and drop the file onto the executable icon, then you're talking about parameters. But I don't think that's what you're talking about.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  6. #6
    Registered User
    Join Date
    Dec 2006
    Location
    Scranton, Pa
    Posts
    252
    Quote Originally Posted by Tonto
    Well, just dragging shell objects onto the console window effectively pastes their filename, which can be read by standard means. And then you can just use the ifstream on what you have read. Very simple really.
    I'm must be dumber than I thought since either I'm failing to get my point across or I'm misunderstanding the answers to my question.

    if;

    Code:
    char FileName[256];
    
    ifstream fin(FileName, ios::in | ios::beg );
       std::cout << FileName;
    ... simply dropping any file onto the console window would effectively paste the fileName, then wouldn't the cout << FileName; spit out that file's name...?

  7. #7
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Code:
    char FileName[256];
    
    // Now drop fiole onto window, opeartor >> will pick it up
    std::cin >> FileName;
    
    ifstream fin(FileName, ios::in | ios::beg );
       std::cout << FileName;

    ╔╗╔╦══╦╗╔╦══╦╗
    ║╚╝║╔╗║╚╝║╔╗║║
    ║╔╗║╠╣║╔╗║╠╣╠╣
    ╚╝╚╩╝╚╩╝╚╩╝╚╩╝

    codez http://code.google.com/p/zxcvbn/

  8. #8
    Registered User
    Join Date
    Dec 2006
    Location
    Scranton, Pa
    Posts
    252
    Thanks, but it doesn't seem to work.

    Code:
    int main ()
    {
    char FileName[256];
    
    // Now drop file onto window, operator >> will pick it up
    std::cin >> FileName;
    
    ifstream fin(FileName, ios::in | ios::beg );
       std::cout << FileName;  // does not print filename
    // safe to assume file isn't being id'd.
       cin.get();
       fin.close();
    
         return 0;
      }

  9. #9
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    try it like this
    Code:
    #include <iostream>
    #include <string>
    
    int main ()
    {
    	std::string FileName;
    
    	std::getline(std::cin, FileName);
    	// NOW drop the file into the console window
    
    	std::cout << FileName; // prints filename
    
    
    	std::cin.get();
    	std::cin.ignore();
    
    	return 0;
    }
    "I saw a sign that said 'Drink Canada Dry', so I started"
    -- Brendan Behan

    Free Compiler: Visual C++ 2005 Express
    If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?

  10. #10
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,434
    > Thanks, but it doesn't seem to work.
    What are you trying to do - drop the files onto an executable in explorer, then explorer launches that program with the files as parameters?

    If so, look at argc and argv in main()
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  11. #11
    Registered User
    Join Date
    Dec 2006
    Location
    Scranton, Pa
    Posts
    252
    Quote Originally Posted by ChaosEngine
    try it like this
    Code:
    #include <iostream>
    #include <string>
    
    int main ()
    {
    	std::string FileName;
    
    	std::getline(std::cin, FileName);
    	// NOW drop the file into the console window
    
    	std::cout << FileName; // prints filename
    
    
    	std::cin.get();
    	std::cin.ignore();
    
    	return 0;
    }

    Thanks, Chaos. That somewhat works, still have to actually open console window and then drop the file. I'll go with that until I can discover just how to drop file onto the exe. window and have the file registered. Meanwhile, I'll continue on with the code that I do know how to write.

    Quote Originally Posted by Salem
    What are you trying to do - drop the files onto an executable in explorer, then explorer launches that program with the files as parameters?

    If so, look at argc and argv in main()
    I've looked at argc/argv main, but can't really figure out how that can be used to automatically pick up and open any file simply by the drop on an unopened exe. window. My last computer was a tandy1000 and coding back then was mostly limited to Dos so bear with me if I seem a little behind the times. I'm mostly doing this (coding stuff) to keep the old grey matter; use it or lose it as they say (whoever the hell they are). Anyways, if you have an example, that'd be appreciated since what I've read thru on the net doesn't seem to supply the answer. Thanks for the input.

  12. #12
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    automatically pick up and open any file
    By this do you mean automatically pickup any type of file such as a bitmap, text, MS Doc file etc. AND open it? In other words, have the console executable properly open the file regardless of the file type that is dropped on it?

  13. #13
    Registered User
    Join Date
    Dec 2006
    Location
    Scranton, Pa
    Posts
    252
    Quote Originally Posted by BobS0327
    By this do you mean automatically pickup any type of file such as a bitmap, text, MS Doc file etc. AND open it? In other words, have the console executable properly open the file regardless of the file type that is dropped on it?
    Yes, exactly. Regardless of name or type, have that file opened on drop and allow following code to run (no user input at all).

    so, instead of f.open ("thisfile.txt", ios::in) needing to be written out as code, a wildcard entry such as (anyfile, ios::in).

  14. #14
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,434
    Well that depends what you mean by "open".

    Code:
    int main ( int argc, char *argv[] ) {
      for ( int i = 1 ; i < argc ; i++ ) {
        cout << argv[i] << endl;
        // now do f.open(argv[i] etc etc
      }
      system("pause");
      return 0;
    }
    Now if you want to do something different with BMP, DOC, TXT whatever, then that's up to you.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  15. #15
    Registered User
    Join Date
    Dec 2006
    Location
    Scranton, Pa
    Posts
    252
    Thank you, gentlemen (for your patience, in particular). With your help, I think I've got it all straight in my head now. For a change, the remainder of my code seems to be going rather smoothly.


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  2. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 07:51 PM
  3. Drag and Drop using CImageList, Device contexts and BitBlt
    By MJWhiteman2 in forum Windows Programming
    Replies: 0
    Last Post: 03-03-2005, 06:22 AM
  4. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 01:58 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21