Starshatter_Open
Open source Starshatter engine
Main Page
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
WebBrowser.cpp
Go to the documentation of this file.
1
/* Project nGenEx
2
Destroyer Studios LLC
3
Copyright © 1997-2006. All Rights Reserved.
4
5
SUBSYSTEM: nGenEx.lib
6
FILE: WebBrowser.cpp
7
AUTHOR: John DiCamillo
8
9
10
OVERVIEW
11
========
12
Helper class to find and launch user's default web browser
13
*/
14
15
#include "
MemDebug.h
"
16
#include "
WebBrowser.h
"
17
18
// +--------------------------------------------------------------------+
19
20
WebBrowser::WebBrowser
()
21
{
22
FindDefaultBrowser
();
23
FindOpenCommand
();
24
}
25
26
WebBrowser::~WebBrowser
()
27
{
28
}
29
30
// +--------------------------------------------------------------------+
31
32
33
void
34
WebBrowser::OpenURL
(
const
char
* url)
35
{
36
if
(url) {
37
char
cmdline[256];
38
39
if
(
command
.
contains
(
"%1"
)) {
40
strcpy_s(cmdline,
command
.
replace
(
"%1"
, url).
data
());
41
}
42
else
{
43
strcpy_s(cmdline,
Text
(
command
+
" "
+ url).data());
44
}
45
46
STARTUPINFO s;
47
ZeroMemory(&s,
sizeof
(s));
48
s.cb =
sizeof
(s);
49
50
PROCESS_INFORMATION pi;
51
ZeroMemory(&pi,
sizeof
(pi));
52
53
if
(CreateProcess(NULL, cmdline, 0, 0, 0, 0, 0, 0, &s, &pi)) {
54
CloseHandle(pi.hProcess);
55
CloseHandle(pi.hThread);
56
}
57
else
{
58
::Print
(
"Unable to launch web browser for url '%s'\n"
, url);
59
}
60
}
61
}
62
63
// +--------------------------------------------------------------------+
64
65
void
66
WebBrowser::FindDefaultBrowser
()
67
{
68
HKEY hkey;
69
char
value[256] =
""
;
70
DWORD dwSize;
71
72
ZeroMemory(value, 256);
73
74
if
(RegOpenKeyEx(HKEY_CLASSES_ROOT,
75
".html"
,
76
0,
77
KEY_READ,
78
&hkey) == ERROR_SUCCESS) {
79
80
dwSize = 256;
81
RegQueryValueEx(hkey,
82
""
,
83
NULL,
84
NULL,
85
(LPBYTE) value,
86
&dwSize);
87
88
RegCloseKey(hkey);
89
90
if
(dwSize > 0) {
91
::Print
(
"Default Web Browser: %s\n"
, value);
92
browser
= value;
93
}
94
}
95
}
96
97
// +--------------------------------------------------------------------+
98
99
void
100
WebBrowser::FindOpenCommand
()
101
{
102
HKEY hkey;
103
char
value[256] =
""
;
104
DWORD dwSize;
105
106
ZeroMemory(value, 256);
107
108
if
(RegOpenKeyEx(HKEY_CLASSES_ROOT,
109
browser
+
"\\shell\\open\\command"
,
110
0,
111
KEY_READ,
112
&hkey) == ERROR_SUCCESS) {
113
114
dwSize = 256;
115
RegQueryValueEx(hkey,
116
""
,
117
NULL,
118
NULL,
119
(LPBYTE) value,
120
&dwSize);
121
122
RegCloseKey(hkey);
123
124
if
(dwSize > 0) {
125
::Print
(
"Browser Shell Open Command: %s\n"
, value);
126
command
= value;
127
}
128
}
129
}
130
131
// +--------------------------------------------------------------------+
132
133
nGenEx
WebBrowser.cpp
Generated on Tue Jun 5 2012 20:46:42 for Starshatter_Open by
1.8.1