Link to home
Start Free TrialLog in
Avatar of sandlot
sandlot

asked on

Open App w/File

My application needs to have the user click on a button and open a specific application with a selected file...So that when this application launches the file is opened inside of it..Does anyone know how to do this?

I attempted Shellexecute but all that got me was the application opened w/o the file.
Avatar of jkr
jkr
Flag of Germany image

How did you use 'ShellExecute()'?

ShellExecute ( NULL, "open", "c:\\mypath\\myfile.doc", NULL, NULL, SW_SHOWNORMAL);

should do it...
Avatar of RONSLOW
RONSLOW

That sounds like an answer, jkr
That sounds like an answer, jkr
Well, the 'answer' still implies a question ;-)
maybe u can use "WinExec"
ShellExecute searches for the verb you specified in the registry. So if the verb is not defined then you can't open teh document. The verb is nothing more then a command line option definition - if you now how you can run your program from the command line, specifying what document to open  then you can easy define such verb. You can do this through Windows Explorer - Run windows Explorer, choose View\options from the menu and there choos "File Types" or you can write directly to the registry
Avatar of sandlot

ASKER

I understand how shellexecutes work, I am a little  unfamiliar with registry commands. However in respose to jkr,

ShellExecute ( NULL, "open", "c:\\mypath\\myfile.doc", NULL, NULL, SW_SHOWNORMAL);

that will open myfile.doc with the default doc application, if I am not mistaken, and I need it to open up with a specific application...So here is exactly what I need to do

I have an IshellBrowser Window that navigates to a path on the local drive..where a bunch of image files exist...I have several image applications and the icon for each of these are displayed on different buttons.. when I select a file, and click on a button, I want the application that corresponds to that icon to open the selected file....is this possible, I know I have to go into the registry somehow, but am unsure of how to do this so that I can pass in the selected file..

Thanks for any further comments..  
>>when I select a file, and click on a button, I want the
>>application that corresponds to that icon to open the
>>selected file

That's exactly how 'ShellExecute()' works - it searches the registry for the specified extension (see 'FindExecutable()') and then invokes the application that is registered for this file type...
Avatar of sandlot

ASKER

I'm sorry let me clarify again as that snippet that I wrote before is misinforming.... When I select an image file and click on a button( this button will have an icon representing an application)  I have already selected an image file from the ishellbrowser window..this image file when double clicked is viewed as default through explorer right now...and it should stay that way...but when I click on the button it should open this image file with the application corresponding to this button..I will have multiple buttons corresponding to multiple applicaitions and each application has to open this image file..

Can ShellExecute perform this, is this what you were talking about...

sorry for any confusion..
ASKER CERTIFIED SOLUTION
Avatar of gelbert
gelbert

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial