"open with"

hi i have i file type registered to open with my program in windows but how do i detect the action of the file being opened and then provide my program with its path. i would be very happy if anyone could tell me how, thanks.
I'm testing it now just to be sure but I believe this is the lpCmdLine argument of the WinMain function. Again I'm testing now to be sure.
Yup the path to the file being opened is the third argument in the WinMain(...) function. Use that argument as the path to the file you intend to open and you should be in business.

EDIT: I changed lpCmdLine to 'Third Argument' because I noticed when I went to go test it that wxDev-C++ calls it lpszArgument. MSDN calls it lpCmdLine, the name is irrelavent though.
Last edited on
ok cool thanks but how can i tell if someone is opening my program normally or with a file
also my program doesn't start with WinMain it starts with main
If your program starts with int main(...) then it's a console app and the path that is passed to your program by Windows would be in argv[1] the same as it would be if you had launched it from a console with an argument. I just verified this.

EDIT: To answer you second question if nothing was passed to Argv[1], as in:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

int main(int argc, char *argv[])
{
    if (argv[1] == 0)
    {
        //code code code
        //Maybe Prompt the user for a path and file name?
        //code code code
    }
    else
   {
       std::string WhatEverHoldsThePath = argv[1];
    }
//code code code
return 0;
} 
Last edited on
Topic archived. No new replies allowed.