×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

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

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

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

(OP)
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.

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

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);

 

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

(OP)
Thank you Prattarat. But, how can I get my program to tell if it was opened by a doubleclick on an associated file?

RE: Code to double click associated file. load program and open 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.

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

Your app should accept a filename as a parameter on the commandline, and in Windows (Explorer) the association should be set up.

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

(OP)
Thank you, TonHu.
Could you provide some sample code.
 

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

(OP)
Ooops! Solved it.
You have to use the ParmStr() function.
And the parameter or index for the associated file is 1.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close