Article View: borland.public.cppbuilder.nativeapi
Article #15658Re: Open with dialog
From: Remy Lebeau (TeamB)
Date: Thu, 19 Jun 2003 23:40
Date: Thu, 19 Jun 2003 23:40
60 lines
2899 bytes
2899 bytes
"Adam Versteegen" <no@email.com> wrote in message
news:3ef23b06@newsgroups.borland.com...
> When using ShellExecute or ShellExecuteEx is there
> a way to display the 'open with' windows dialog if
> the file passed in is a non recognised file extension?
ShellExecute() is not smart enough to do that automatically. Since you have
to explicitally tell it which particular verb to execute for the file,
you'll have to determine that yourself manually before calling
ShellExecute(). You should look in the Registry directly to see what the
available verbs for the file extension are. If "open" is available, then
use that as normal, otherwise use the shell's built-in "openas" verb
instead. For example (untested):
AnsiString ext = ".ext";
bool isOpenAvailable = false;
HKEY hKey = NULL
if( RegOpenKeyEx(HKEY_CLASSES_ROOT, ext.c_str(), 0, KEY_QUERY_VALUE,
&hKey) == ERROR_SUCCESS )
{
char progid[256] = {0};
DWORD dwSize = sizeof(progid);
RegQueryValueEx(hKey, "", NULL, NULL,
reinterpret_cast<LPBYTE>(progid), &dwSize);
RegCloseKey(hKey);
if( progid[0] != '\0' )
{
if( RegOpenKeyEx(HKEY_CLASSES_ROOT, progid, 0, KEY_QUERY_VALUE,
&hKey) == ERROR_SUCCESS )
{
HKEY hTempKey = NULL;
isOpenAvailable = ( RegOpenKeyEx(hKey, "shell\\open", 0,
KEY_QUERY_VALUE, &hTempKey) == ERROR_SUCCESS );
if( hTempKey ) RegCloseKey(hTempKey);
RegCloseKey(hKey);
}
}
}
if( isOpenAvailable )
ShellExecute(NULL, "open", ...);
else
ShellExecute(NULL, "openas", ...);
An alternative I have seen posted before, but have not tried myself, is to
just call ShelExecute() with "open" regardless, and then call it with
"openas" only if "open" failed:
if( ShellExecute(NULL, "open", ...) <= 32 )
ShellExecute(NULL, "openas", ...);
Gambit
Technical Details
Message-ID:
<3ef248f7$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-08!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mailReferences:
<3ef23b06@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,863d8bda245bcc45 X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-06-19 16:41:48 PST From: "Remy Lebeau \(TeamB\)" <gambit47@yahoo.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <3ef23b06@newsgroups.borland.com> Subject: Re: Open with dialog Date: Thu, 19 Jun 2003 16:40:23 -0700 Lines: 63 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 207.175.226.26 Message-ID: <3ef248f7$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1056065783 207.175.226.26 (19 Jun 2003 16:36:23 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-08!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail