]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/utilswin.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/utilswin.cpp
3 // Purpose: Various utility functions only available in Windows GUI
4 // Author: Vadim Zeitlin
6 // Created: 21.06.2003 (extracted from msw/utils.cpp)
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #include "wx/wxprec.h"
21 #include "wx/msw/private.h" // includes <windows.h>
22 #include "wx/msw/registry.h"
23 #include <shellapi.h> // needed for SHELLEXECUTEINFO
25 // ----------------------------------------------------------------------------
26 // Launch document with default app
27 // ----------------------------------------------------------------------------
29 bool wxLaunchDefaultApplication(const wxString
& document
, int flags
)
33 WinStruct
<SHELLEXECUTEINFO
> sei
;
34 sei
.lpFile
= document
.t_str();
36 sei
.nShow
= SW_SHOWNORMAL
; // SW_SHOWDEFAULT not defined under CE (#10216)
38 sei
.nShow
= SW_SHOWDEFAULT
;
41 // avoid Windows message box in case of error for consistency with
42 // wxLaunchDefaultBrowser() even if don't show the error ourselves in this
44 sei
.fMask
= SEE_MASK_FLAG_NO_UI
;
46 if ( ::ShellExecuteEx(&sei
) )
52 // ----------------------------------------------------------------------------
53 // Launch default browser
54 // ----------------------------------------------------------------------------
56 bool wxDoLaunchDefaultBrowser(const wxString
& url
, const wxString
& scheme
, int flags
)
61 if ( flags
& wxBROWSER_NEW_WINDOW
)
63 // ShellExecuteEx() opens the URL in an existing window by default so
64 // we can't use it if we need a new window
65 wxRegKey
key(wxRegKey::HKCR
, scheme
+ wxT("\\shell\\open"));
68 // try the default browser, it must be registered at least for http URLs
69 key
.SetName(wxRegKey::HKCR
, wxT("http\\shell\\open"));
74 wxRegKey
keyDDE(key
, wxT("DDEExec"));
75 if ( keyDDE
.Exists() )
77 // we only know the syntax of WWW_OpenURL DDE request for IE,
78 // optimistically assume that all other browsers are compatible
80 static const wxChar
*TOPIC_OPEN_URL
= wxT("WWW_OpenURL");
82 wxRegKey
keyTopic(keyDDE
, wxT("topic"));
83 bool ok
= keyTopic
.Exists() &&
84 keyTopic
.QueryDefaultValue() == TOPIC_OPEN_URL
;
87 ddeCmd
= keyDDE
.QueryDefaultValue();
93 // for WWW_OpenURL, the index of the window to open the URL
94 // in may be -1 (meaning "current") by default, replace it
95 // with 0 which means "new" (see KB article 160957), but
96 // don't fail if there is no -1 as at least for recent
97 // Firefox versions the default value already is 0
98 ddeCmd
.Replace(wxT("-1"), wxT("0"),
99 false /* only first occurrence */);
101 // and also replace the parameters: the topic should
102 // contain a placeholder for the URL and we should fail if
103 // we didn't find it as this would mean that we have no way
104 // of passing the URL to the browser
105 ok
= ddeCmd
.Replace(wxT("%1"), url
, false) == 1;
110 // try to send it the DDE request now but ignore the errors
113 const wxString ddeServer
= wxRegKey(keyDDE
, wxT("application"));
114 if ( wxExecuteDDE(ddeServer
, TOPIC_OPEN_URL
, ddeCmd
) )
117 // this is not necessarily an error: maybe browser is
118 // simply not running, but no matter, in any case we're
119 // going to launch it using ShellExecuteEx() below now and
120 // we shouldn't try to open a new window if we open a new
128 WinStruct
<SHELLEXECUTEINFO
> sei
;
129 sei
.lpFile
= url
.c_str();
130 sei
.lpVerb
= wxT("open");
131 sei
.nShow
= SW_SHOWNORMAL
;
132 sei
.fMask
= SEE_MASK_FLAG_NO_UI
; // we give error message ourselves
134 if ( ::ShellExecuteEx(&sei
) )