]>
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)
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
22 #include "wx/msw/private.h" // includes <windows.h>
23 #include "wx/msw/registry.h"
24 #include <shellapi.h> // needed for SHELLEXECUTEINFO
26 // ----------------------------------------------------------------------------
27 // Launch document with default app
28 // ----------------------------------------------------------------------------
30 bool wxLaunchDefaultApplication(const wxString
& document
, int flags
)
34 WinStruct
<SHELLEXECUTEINFO
> sei
;
35 sei
.lpFile
= document
.t_str();
37 sei
.nShow
= SW_SHOWNORMAL
; // SW_SHOWDEFAULT not defined under CE (#10216)
39 sei
.nShow
= SW_SHOWDEFAULT
;
42 // avoid Windows message box in case of error for consistency with
43 // wxLaunchDefaultBrowser() even if don't show the error ourselves in this
45 sei
.fMask
= SEE_MASK_FLAG_NO_UI
;
47 if ( ::ShellExecuteEx(&sei
) )
53 // ----------------------------------------------------------------------------
54 // Launch default browser
55 // ----------------------------------------------------------------------------
57 bool wxDoLaunchDefaultBrowser(const wxString
& url
, const wxString
& scheme
, int flags
)
62 if ( flags
& wxBROWSER_NEW_WINDOW
)
64 // ShellExecuteEx() opens the URL in an existing window by default so
65 // we can't use it if we need a new window
66 wxRegKey
key(wxRegKey::HKCR
, scheme
+ wxT("\\shell\\open"));
69 // try the default browser, it must be registered at least for http URLs
70 key
.SetName(wxRegKey::HKCR
, wxT("http\\shell\\open"));
75 wxRegKey
keyDDE(key
, wxT("DDEExec"));
76 if ( keyDDE
.Exists() )
78 // we only know the syntax of WWW_OpenURL DDE request for IE,
79 // optimistically assume that all other browsers are compatible
81 static const wxChar
*TOPIC_OPEN_URL
= wxT("WWW_OpenURL");
83 wxRegKey
keyTopic(keyDDE
, wxT("topic"));
84 bool ok
= keyTopic
.Exists() &&
85 keyTopic
.QueryDefaultValue() == TOPIC_OPEN_URL
;
88 ddeCmd
= keyDDE
.QueryDefaultValue();
94 // for WWW_OpenURL, the index of the window to open the URL
95 // in may be -1 (meaning "current") by default, replace it
96 // with 0 which means "new" (see KB article 160957), but
97 // don't fail if there is no -1 as at least for recent
98 // Firefox versions the default value already is 0
99 ddeCmd
.Replace(wxT("-1"), wxT("0"),
100 false /* only first occurrence */);
102 // and also replace the parameters: the topic should
103 // contain a placeholder for the URL and we should fail if
104 // we didn't find it as this would mean that we have no way
105 // of passing the URL to the browser
106 ok
= ddeCmd
.Replace(wxT("%1"), url
, false) == 1;
111 // try to send it the DDE request now but ignore the errors
114 const wxString ddeServer
= wxRegKey(keyDDE
, wxT("application"));
115 if ( wxExecuteDDE(ddeServer
, TOPIC_OPEN_URL
, ddeCmd
) )
118 // this is not necessarily an error: maybe browser is
119 // simply not running, but no matter, in any case we're
120 // going to launch it using ShellExecuteEx() below now and
121 // we shouldn't try to open a new window if we open a new
129 WinStruct
<SHELLEXECUTEINFO
> sei
;
130 sei
.lpFile
= url
.c_str();
131 sei
.lpVerb
= wxT("open");
132 sei
.nShow
= SW_SHOWNORMAL
;
133 sei
.fMask
= SEE_MASK_FLAG_NO_UI
; // we give error message ourselves
135 if ( ::ShellExecuteEx(&sei
) )