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!

App related with file extension

Status
Not open for further replies.

dominochmiel

Programmer
Jan 28, 2003
40
PL
I need to know how can i connect my application with file extension. In short I need to now how to open graphic file in my app just clicking on file icon. Thanks for help.
 
Look at the ShellExecute API. See faq101-1952 for more details and an example. James P. Cottingham

When a man sits with a pretty girl for an hour, it seems like a minute. But let him sit on a hot stove for a minute and it's longer than any hour. That's relativity.
[tab][tab]Albert Einstein explaining his Theory of Relativity to a group of journalists.
 
if the particular file type is associated with your program you can parse the command string that is passed to your program. I have a text editor that I made that checks arguments like this

char commandlinebuff [256];
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR CmdLine, int)
{
strcpy (commandlinebuff, CmdLine);
}

the window OS will send a command such as
"yourprogram image.bmp"

this is how I handle it from the main form.cpp

if (strlen (commandlinebuff))
{
strcpy (buff1, ExtractFilePath(commandlinebuff).c_str ());

if (strlen (buff1))
chdir (buff1);

strcpy (loadedfilename, commandlinebuff);

OpenFile (loadedfilename);
}

you must change the file associations in the os before the Os will open the file with your program.

look up the parameter list for winmain in the help

tomcruz.net
 
I used CmdLine and it's always empty.Maybe because I'm using win xp.In help i found under password CmdLine i found ParamStr but it gives me only directory to exe of my app.
 
ParamStr returns the parameter from the command line that corresponds to Index, or an empty string if Index is greater than ParamCount. For example, an Index value of 2 returns the second command-line parameter.

string1 = ParamStr(0)
string2 = ParamStr(1)
string3 = ParamStr(2)
stringN = ParamStr(N)

ParamStr has multiple values embedded
check the values of the above strings
sometimes you have to concatenate several
strings to get the full path name.

tomcruz.net

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top