I command you with all Might I have

This is a discussion on I command you with all Might I have within the C++ Programming forums, part of the General Programming Boards category; Well I was looking for a way to detect command lines and files opened with my application Just a simple ...

  1. #1
    Registered User Need_O2's Avatar
    Join Date
    Jan 2008
    Posts
    13

    I command you with all Might I have

    Well I was looking for a way to detect command lines
    and files opened with my application

    Just a simple way if possible
    or a header that does it easly

    something like: string s = GetCommandLine() xD (kidding)
    Last edited by Need_O2; 04-16-2008 at 01:10 PM.

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,470
    Well I was looking for a way to detect command lines
    and files opened with my application
    your application does not know what it is doing?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    Registered User Need_O2's Avatar
    Join Date
    Jan 2008
    Posts
    13
    I open it with a file for example you know
    Like opening paint files with mspaint
    I want to detect what I opened it with

    Did I miss the no beginners allowed sign ?

  4. #4
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,470
    Quote Originally Posted by Need_O2 View Post
    I open it with a file for example you know
    Like opening paint files with mspaint
    I want to detect what I opened it with
    I still do not undestand what you are trying to say.

    Could you explain step by step the procedure you have in mind and exact step where you have difficalties?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  5. #5
    Registered User Need_O2's Avatar
    Join Date
    Jan 2008
    Posts
    13
    Start -> Run -> $My application path$ $File to open with Path$
    so I opened the "File to open with" with my application
    So I want to store $File to open with Path$ in a string to know what I opened with it

    like
    mspaint "C:\Pictures\Lieandsorrow.jpeg"
    lieandsorrow.jpeg gets opened with mspaint
    mspaint knows about "C:\Pictures\Lieandsorrow.jpeg" and it opens it
    I want the "knows about" part

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I'm also confused about what you want to do: Are you asking "how do I get the command line arguments", or something else? The former is described in the FAQ section in the blue line above this thread.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    I think the OP is trying to open a file from Windows Explorer, for example, and then determine which program was launched to open the file.

    The only way I can think of to do this is to get the command-line string that was used to execute every running program, and search through those for the filename in question. I'm not sure how to do this, or if it's even possible.

    [edit] Didn't see the last two posts. It's what happens with tabs.

    I think matsp might be right. Here's the FAQ. http://faq.cprogramming.com/cgi-bin/...&id=1043284392
    [/edit]
    Last edited by dwks; 04-16-2008 at 01:27 PM.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  8. #8
    Registered User
    Join Date
    May 2006
    Posts
    903
    I'm confused as well but as matsp suggests it seems that you what you are looking for are command line arguments.

  9. #9
    Registered User Need_O2's Avatar
    Join Date
    Jan 2008
    Posts
    13
    you mean "Run a program from within a program"
    hmm didnt see FAQs before
    They seem much usefull

    Thanks !!!

  10. #10
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    You might also want to read the FAQ I posted in my edit. http://faq.cprogramming.com/cgi-bin/...&id=1043284392
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  11. #11
    Registered User Need_O2's Avatar
    Join Date
    Jan 2008
    Posts
    13
    I simply wanted make me able to right click a file and say open with <My app name>
    since I know some about editing class options from registry. making app open the file opened it with was last thing to do

    (LoL I don't know how to edit registry with c ...)

    Really how to edit registry ?

    is there a simple way like game maker ? (at least Im sure it would be possible with a header)

    it was like
    SetRegistryRoot(0) // like (not exactly): 0 = local machine,1 = classes root
    RegistryWriteStringEx("path","variable","string") // creates all if doesnt exist (no path = creates path, no variable = creates variable)


    And how to copy a file xD ?
    Last edited by Need_O2; 04-16-2008 at 01:48 PM.

  12. #12
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    I see what you're wanting to do, and I am not sure how to do it now that I think about it.

    For those who may know heres a rewording of what is trying to be done:

    Think about when you double click a JPG file. Windows automatically opens up the right program and that program knows which file you opened. The OP wants to know how to make his program work like that. So if a text editor is made and you double click a TXT file, your custom program will open that file. The problem is, how does your program know what file you double clicked.

    [edit]
    The more I think about it, there must be something similar to the standard "command line arguments".
    [/edit]
    Last edited by Vicious; 04-16-2008 at 02:09 PM.
    What is C++?

  13. #13
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,470
    The problem is, how does your program know what file you double clicked.
    It parses main argv array or WinMain lpCmdLine parameter
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  14. #14
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    That makes sence. So one would simply check for the existance of the arguments and parse out a file name to open.
    What is C++?

  15. #15
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Probably, if there is more than one command line argument, the second argument is assumed to be the file to open. So when the program starts, you check the number of command line arguments, and try to load the file if it is specified.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

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