Solved

Open App w/File

Posted on 2000-02-24
10
155 Views
Last Modified: 2013-11-20
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.
0
Comment
Question by:sandlot
  • 3
  • 2
  • 2
  • +3
10 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 2556123
How did you use 'ShellExecute()'?

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

should do it...
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 2556232
That sounds like an answer, jkr
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 2556239
That sounds like an answer, jkr
0
 
LVL 86

Expert Comment

by:jkr
ID: 2556369
Well, the 'answer' still implies a question ;-)
0
 

Expert Comment

by:johnxi
ID: 2557202
maybe u can use "WinExec"
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 7

Expert Comment

by:tchalkov
ID: 2557489
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
0
 

Author Comment

by:sandlot
ID: 2558038
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..  
0
 
LVL 86

Expert Comment

by:jkr
ID: 2558135
>>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...
0
 

Author Comment

by:sandlot
ID: 2558516
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..
0
 
LVL 8

Accepted Solution

by:
gelbert earned 150 total points
ID: 2558575
You got two options to try:
1. If application which is attached to your button is COM server then try to create it as COM server and load your file using interface which is provided by application(possibly IPersistsFile)
2. If first step failed for any reason then you can try WinExec() (specify name of your application which you want to open file and file name in command line).

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Pressing cancel button with C# UI Automation 3 51
noX challenge 17 91
Path of Workbook 3 60
"Black Box" Testing of Control System Software 2 25
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now