 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Randel Bjorkquist Guest
|
Posted: Tue Jan 27, 2004 3:19 pm Post subject: How to get the Open with... window |
|
|
Hey All,
I'm using the "ShellExecute" function to open a given file. But if the file
has an unknown extention, or one that isn't associated with an application,
how do I get the "Open With..." window to pop up.
Here is my current code that only opens the file if there is an associated
program to open it with.
//--------------------------------------------------------------------------
-
void __fastcall Tfrm_Main::SpeedButton1Click(TObject *Sender)
{
AnsiString TestFileName = "C:\Temp\";
TDataSet* Data = dm_Picture->ds_Picture->DataSet;
TestFileName += Data->FieldByName("FileName")->AsString;
ShellExecute(NULL, "open", TestFileName.c_str(), NULL, NULL, SW_SHOW);
}
Thanks for any and all help,
Randel Bjorkquist
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Tue Jan 27, 2004 8:06 pm Post subject: Re: How to get the Open with... window |
|
|
"Randel Bjorkquist" <rbjorkquist (AT) coilcraft (DOT) com> wrote
| Quote: | I'm using the "ShellExecute" function to open a given file. But
if the file has an unknown extention, or one that isn't associated
with an application, how do I get the "Open With..." window
to pop up.
|
One way is to call ShellExecute() with the "openwith" verb, ie:
void __fastcall Tfrm_Main::SpeedButton1Click(TObject *Sender)
{
//...
if( ShellExecute(NULL, "open", TestFileName.c_str(), NULL, NULL,
SW_SHOW) == SE_ERR_NOASSOC )
ShellExecute(NULL, "openwith", TestFileName.c_str(), NULL, NULL,
SW_SHOW);
//...
}
Alternatively, run RUNDLL32.EXE instead:
void __fastcall Tfrm_Main::SpeedButton1Click(TObject *Sender)
{
//...
if( ShellExecute(NULL, "open", TestFileName.c_str(), NULL, NULL,
SW_SHOW) == SE_ERR_NOASSOC )
WinExec( ("rundll32.exe shell32.dll,OpenAs_RunDLL " +
TestFileName).c_str(), SW_NORMAL);
//...
}
Gambit
|
|
| Back to top |
|
 |
Randel Bjorkquist Guest
|
Posted: Wed Jan 28, 2004 1:53 pm Post subject: Re: How to get the Open with... window |
|
|
Hey Remy,
Thanks for the help, but I get a compiling error when I try to use the
"if-statement" from your example. Also, I tried using just the "openwith",
and nothing happens. I tried it on files that I knew an application
existed, like a Microsoft Word document and I also tried it on the Code
Guard files. I don't get anything to pop up. What am I doing wrong?
Randel
----------------------------------------------------------------------------
-
COMPILER ERROR
//--------------------------------------------------------------------------
-
[C++ Error] Main.cpp(249): E2034 Cannot convert 'int' to 'void *'
//--------------------------------------------------------------------------
-
PARTIAL CODE THAT GENERATES THE ABOVE COMPILER ERROR
//--------------------------------------------------------------------------
-
void __fastcall Tfrm_Main::SpeedButton1Click(TObject *Sender)
{
:
if(ShellExecute(NULL, "open", TestFileName.c_str(), NULL, NULL, SW_SHOW)
== SE_ERR_NOASSOC){
ShellExecute(NULL, "openwith", TestFileName.c_str(), NULL, NULL,
SW_SHOW);
}//end of "if-statement"
:
}//end of "Tfrm_Main::SpeedButton1Click" method
"Remy Lebeau (TeamB)" <gambit47.no.spam (AT) no (DOT) spam.yahoo.com> wrote
| Quote: |
"Randel Bjorkquist" <rbjorkquist (AT) coilcraft (DOT) com> wrote in message
news:4016819e (AT) newsgroups (DOT) borland.com...
I'm using the "ShellExecute" function to open a given file. But
if the file has an unknown extention, or one that isn't associated
with an application, how do I get the "Open With..." window
to pop up.
One way is to call ShellExecute() with the "openwith" verb, ie:
void __fastcall Tfrm_Main::SpeedButton1Click(TObject *Sender)
{
//...
if( ShellExecute(NULL, "open", TestFileName.c_str(), NULL, NULL,
SW_SHOW) == SE_ERR_NOASSOC )
ShellExecute(NULL, "openwith", TestFileName.c_str(), NULL,
NULL,
SW_SHOW);
//...
}
Alternatively, run RUNDLL32.EXE instead:
void __fastcall Tfrm_Main::SpeedButton1Click(TObject *Sender)
{
//...
if( ShellExecute(NULL, "open", TestFileName.c_str(), NULL, NULL,
SW_SHOW) == SE_ERR_NOASSOC )
WinExec( ("rundll32.exe shell32.dll,OpenAs_RunDLL " +
TestFileName).c_str(), SW_NORMAL);
//...
}
Gambit
|
|
|
| Back to top |
|
 |
Randel Bjorkquist Guest
|
Posted: Wed Jan 28, 2004 3:40 pm Post subject: Re: How to get the Open with... window |
|
|
Hey Remy,
This is what I finally got to work, but I don't understand why I have to do
it this way. Why do I have to type cast the "SheelExecute" function to an
int?
CODE THAT WORKS
//--------------------------------------------------------------------------
if((int)ShellExecute(NULL, "open", TestFileName.c_str(), NULL, NULL,
SW_SHOW) == SE_ERR_NOASSOC){
WinExec( ("rundll32.exe shell32.dll,OpenAs_RunDLL " +
TestFileName).c_str(), SW_NORMAL);
}//end of "if-statement"
//--------------------------------------------------------------------------
If I don't, I get the compiler error
COMPILER ERROR
//--------------------------------------------------------------------------
[C++ Error] Main.cpp(249): E2034 Cannot convert 'int' to 'void *'
//--------------------------------------------------------------------------
Lastly, I just cannot get this line of code to do anything. It wont open
any kind of file.
ShellExecute(NULL, "openwith", TestFileName.c_str(), NULL, NULL, SW_SHOW);
Can you help me understand what I'm missing?
Thanks in advance,
Randel
"Randel Bjorkquist" <rbjorkquist (AT) coilcraft (DOT) com> wrote
| Quote: | Hey Remy,
Thanks for the help, but I get a compiling error when I try to use the
"if-statement" from your example. Also, I tried using just the
"openwith",
and nothing happens. I tried it on files that I knew an application
existed, like a Microsoft Word document and I also tried it on the Code
Guard files. I don't get anything to pop up. What am I doing wrong?
Randel
--------------------------------------------------------------------------
--
-
COMPILER ERROR
//--------------------------------------------------------------------------
-
[C++ Error] Main.cpp(249): E2034 Cannot convert 'int' to 'void *'
//--------------------------------------------------------------------------
-
PARTIAL CODE THAT GENERATES THE ABOVE COMPILER ERROR
//--------------------------------------------------------------------------
-
void __fastcall Tfrm_Main::SpeedButton1Click(TObject *Sender)
{
:
if(ShellExecute(NULL, "open", TestFileName.c_str(), NULL, NULL, SW_SHOW)
== SE_ERR_NOASSOC){
ShellExecute(NULL, "openwith", TestFileName.c_str(), NULL, NULL,
SW_SHOW);
}//end of "if-statement"
:
}//end of "Tfrm_Main::SpeedButton1Click" method
"Remy Lebeau (TeamB)" <gambit47.no.spam (AT) no (DOT) spam.yahoo.com> wrote in
message
news:4016c30b$1 (AT) newsgroups (DOT) borland.com...
"Randel Bjorkquist" <rbjorkquist (AT) coilcraft (DOT) com> wrote in message
news:4016819e (AT) newsgroups (DOT) borland.com...
I'm using the "ShellExecute" function to open a given file. But
if the file has an unknown extention, or one that isn't associated
with an application, how do I get the "Open With..." window
to pop up.
One way is to call ShellExecute() with the "openwith" verb, ie:
void __fastcall Tfrm_Main::SpeedButton1Click(TObject *Sender)
{
//...
if( ShellExecute(NULL, "open", TestFileName.c_str(), NULL, NULL,
SW_SHOW) == SE_ERR_NOASSOC )
ShellExecute(NULL, "openwith", TestFileName.c_str(), NULL,
NULL,
SW_SHOW);
//...
}
Alternatively, run RUNDLL32.EXE instead:
void __fastcall Tfrm_Main::SpeedButton1Click(TObject *Sender)
{
//...
if( ShellExecute(NULL, "open", TestFileName.c_str(), NULL, NULL,
SW_SHOW) == SE_ERR_NOASSOC )
WinExec( ("rundll32.exe shell32.dll,OpenAs_RunDLL " +
TestFileName).c_str(), SW_NORMAL);
//...
}
Gambit
|
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Wed Jan 28, 2004 6:50 pm Post subject: Re: How to get the Open with... window |
|
|
"Randel Bjorkquist" <rbjorkquist (AT) coilcraft (DOT) com> wrote
| Quote: | This is what I finally got to work, but I don't understand why
I have to do it this way. Why do I have to type cast the
"SheelExecute" function to an int?
|
Because ShellExecute() returns an HINSTANCE which is a void*, whereas
SE_ERR_NOASSOC is an integer value instead. You could also cast
SE_ERR_NOASSOC into an HINSTANCE instead:
if( ShellExecute(NULL, "open", TestFileName.c_str(), NULL, NULL,
SW_SHOW) == (HINSTANCE)SE_ERR_NOASSOC )
| Quote: | Lastly, I just cannot get this line of code to do anything.
It wont open any kind of file.
|
Then ignore it. Use RunDll32 instead.
Gambit
|
|
| Back to top |
|
 |
Randel Bjorkquist Guest
|
Posted: Thu Jan 29, 2004 3:02 pm Post subject: Re: How to get the Open with... window |
|
|
Remy,
I just wanted to make sure I wasn't missing something with trying to use the
ShellExecute(NULL, "openwith", TestFileName.c_str(), NULL, NULL, SW_SHOW);
As for the HINSTANCE, the Borland help defines it like this
extern PACKAGE int HInstance;
So I thought it was an int and not a void *.
I still don't understand the HINSTANCE, but at this time I guess it doesn't
matter.
But in any case, with your help I've got it working like I want it to.
Thank you very much,
Randel Bjorkquist
"Remy Lebeau (TeamB)" <gambit47.no.spam (AT) no (DOT) spam.yahoo.com> wrote
| Quote: |
"Randel Bjorkquist" <rbjorkquist (AT) coilcraft (DOT) com> wrote in message
news:4017d7da$1 (AT) newsgroups (DOT) borland.com...
This is what I finally got to work, but I don't understand why
I have to do it this way. Why do I have to type cast the
"SheelExecute" function to an int?
Because ShellExecute() returns an HINSTANCE which is a void*, whereas
SE_ERR_NOASSOC is an integer value instead. You could also cast
SE_ERR_NOASSOC into an HINSTANCE instead:
if( ShellExecute(NULL, "open", TestFileName.c_str(), NULL, NULL,
SW_SHOW) == (HINSTANCE)SE_ERR_NOASSOC )
Lastly, I just cannot get this line of code to do anything.
It wont open any kind of file.
Then ignore it. Use RunDll32 instead.
Gambit
|
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Thu Jan 29, 2004 7:35 pm Post subject: Re: How to get the Open with... window |
|
|
"Randel Bjorkquist" <rbjorkquist (AT) coilcraft (DOT) com> wrote
| Quote: | I just wanted to make sure I wasn't missing something with
trying to use the
ShellExecute(NULL, "openwith", TestFileName.c_str(), NULL, NULL, SW_SHOW);
|
There are situations where it can work, though. I just don't remember which
ones they are. The Rundll32 option should always work, though.
| Quote: | As for the HINSTANCE, the Borland help defines it like this
extern PACKAGE int HInstance;
|
That is simply because Borland declares many API handles as integers in the
VCL instead of as pointers.
Gambit
|
|
| Back to top |
|
 |
nicolasr Guest
|
Posted: Fri Jan 30, 2004 12:00 pm Post subject: Re: How to get the Open with... window |
|
|
Hi,
I noticed a big difference in the WinAPI help that ships with BCB
and the online help at MSDN. This is an excerpt from the current
ShellExecute documentation that might interest you:
<quote>
Returns a value greater than 32 if successful, or an error value that
is less than or equal to 32 otherwise. The following table lists the
error values. The return value is cast as an HINSTANCE for
backward compatibility with 16-bit Windows applications. It is
not a true HINSTANCE, however. The only thing that can be
done with the returned HINSTANCE is to cast it to an int and
compare it with the value 32 or one of the error codes below...
</quote>
Nick
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Fri Jan 30, 2004 6:31 pm Post subject: Re: How to get the Open with... window |
|
|
"nicolasr" <nicolasrNOSPAMATSIGNgmx.net> wrote
| Quote: | I noticed a big difference in the WinAPI help that
ships with BCB and the online help at MSDN.
|
The help files that ship with BCB are considerably outdated.
Gambit
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|