Thread: Open file with program by default..

  1. #1
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378

    Open file with program by default..

    hey...i'm curious about the whole "file type associations" thing. like, if you have a filetype windows doesn't recognize, you can assign whatever program to be the default one to open it. but when your writing your program, say we're going to text files | a text editor, what would you code into the editor so that you could double click the file and it would be opened with the program? similar to how when you double click on a .txt file, its opened in notepad (/ default txt editor)?

    thanks
    Registered Linux User #380033. Be counted: http://counter.li.org

  2. #2
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Our good freind Magos made a "Java runner" which associates his program with the .class extension.

    Thread here: http://cboard.cprogramming.com/showthread.php?t=69444
    Source here: http://magos.thejefffiles.com/JavaRunner.zip

    You might enjoy it

  3. #3
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    yes, but...when a file is double clicked, i want my program to open it. lol not for it to simply open my program and then i have to open the file once in my program. i'll take a look at it, but i need code for automatically opening the file for my program.. lol i'm not word about file type associations.
    Registered Linux User #380033. Be counted: http://counter.li.org

  4. #4
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    I think you when you open a file, the program the it opens with is passed the file name as a command line argument. So you would just need to handle command line arguments appropriately
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Ummmmmm....

    Tonto has already supplied the code you need. Can't ask for more than that.

    Find and read the

    RegisterExtention()

    function in the link provided.



    Or am I missing something?
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  6. #6
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    >> So you would just need to handle command line arguments appropriately

    yah...thats what i've been asking how to do. lol
    Registered Linux User #380033. Be counted: http://counter.li.org

  7. #7
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    yah...thats what i've been asking how to do. lol
    I don't recall you asking how to handle command-line arguments, so... no it's not.

    Code:
    int main(int argc, char *argv[]);
    That's the main prototype.

    argv is an array of strings. Each string is one of the tokens entered at the command line. argv[0] points to the name of the program as it was called. argv[1] is the first comman-line argument, and so forth.

    argc is the number of tokens that were entered.

  8. #8
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Command line arguments?! You never mentioned that . Well, such things are also covered in Magos' code too. Because there's no argc/argv in WinMain, you can use the lpCmdLine argument, or the GetCommandLine() API, and the tokenize it like argv does, the CommandLineToArgvW API.

  9. #9
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    theerrre we go haha..i was wondering how to handle it w/o argc/v..

    i'll do some searches on those and see what i can come up with. thanks
    Registered Linux User #380033. Be counted: http://counter.li.org

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  2. Basic program design, passing pointer to a function
    By heras in forum C Programming
    Replies: 14
    Last Post: 04-02-2008, 03:21 AM
  3. Last program!!
    By buckwheat88 in forum C++ Programming
    Replies: 12
    Last Post: 01-17-2006, 12:31 PM
  4. how to make certain file types open IN your program
    By DarkViper in forum Windows Programming
    Replies: 4
    Last Post: 02-06-2003, 11:37 PM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM