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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code to double click associated file. load program and open file

Status
Not open for further replies.

kes103

Programmer
Jun 28, 2003
26
US
I would like to find out how to code my program so that it will load an associated file after it is double clicked. That is, after double clicking the file the program loads and then opens the file that was double clicked. I know this must be very basic coding for someone. Thanks in advance for any help on this subject.
 
Try this:
Put a TOpenDialog Component on you form.

Then, where you want the file to load:
For BCB 2009 and 2010:
Code:
UnicodeString FilePath = FileDialog1->Execute();
TFileStream F = new TFileStream(FilePath,fmOpenReadOnly);
// if F is not NULL, File is now open for reading

for earlier Versions of C++Builder:
Code:
AnsiString FilePath = FileDialog1->Execute();
TFileStream F = new TFileStream(FilePath,fmOpenReadOnly);
// if F is not NULL, File is now open for reading

What this goes is run a file open dialog and returns the file path of the selected file to FilePath, then opens as a readonly stream F, which you can then read from using F->Read(void* buffer, int count);

 
Thank you Prattarat. But, how can I get my program to tell if it was opened by a doubleclick on an associated file?
 
I apologize, I misunderstood the nature of your question. I have not ever done what you are looking for in C++ Builder, (Visual Basic, yes but not C++) but I would take a look at the ShellExecute function in the help function as a starting point.
 
Your app should accept a filename as a parameter on the commandline, and in Windows (Explorer) the association should be set up.
 
Thank you, TonHu.
Could you provide some sample code.
 
Ooops! Solved it.
You have to use the ParmStr() function.
And the parameter or index for the associated file is 1.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top