From e33e19d0587146859d48a134ec9fd94e7b7ba5cd Mon Sep 17 00:00:00 2001 From: "FWoltermann@gmail.com" Date: Thu, 8 Dec 2011 14:53:40 +0000 Subject: Initial upload --- nGenEx/WebBrowser.cpp | 133 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 nGenEx/WebBrowser.cpp (limited to 'nGenEx/WebBrowser.cpp') diff --git a/nGenEx/WebBrowser.cpp b/nGenEx/WebBrowser.cpp new file mode 100644 index 0000000..a5f5b94 --- /dev/null +++ b/nGenEx/WebBrowser.cpp @@ -0,0 +1,133 @@ +/* Project nGenEx + Destroyer Studios LLC + Copyright © 1997-2006. All Rights Reserved. + + SUBSYSTEM: nGenEx.lib + FILE: WebBrowser.cpp + AUTHOR: John DiCamillo + + + OVERVIEW + ======== + Helper class to find and launch user's default web browser +*/ + +#include "MemDebug.h" +#include "WebBrowser.h" + +// +--------------------------------------------------------------------+ + +WebBrowser::WebBrowser() +{ + FindDefaultBrowser(); + FindOpenCommand(); +} + +WebBrowser::~WebBrowser() +{ +} + +// +--------------------------------------------------------------------+ + + +void +WebBrowser::OpenURL(const char* url) +{ + if (url) { + char cmdline[256]; + + if (command.contains("%1")) { + strcpy(cmdline, command.replace("%1", url).data()); + } + else { + strcpy(cmdline, Text(command + " " + url).data()); + } + + STARTUPINFO s; + ZeroMemory(&s, sizeof(s)); + s.cb = sizeof(s); + + PROCESS_INFORMATION pi; + ZeroMemory(&pi, sizeof(pi)); + + if (CreateProcess(NULL, cmdline, 0, 0, 0, 0, 0, 0, &s, &pi)) { + CloseHandle(pi.hProcess); + CloseHandle(pi.hThread); + } + else { + ::Print("Unable to launch web browser for url '%s'\n", url); + } + } +} + +// +--------------------------------------------------------------------+ + +void +WebBrowser::FindDefaultBrowser() +{ + HKEY hkey; + char value[256] = ""; + DWORD dwSize; + + ZeroMemory(value, 256); + + if (RegOpenKeyEx(HKEY_CLASSES_ROOT, + ".html", + 0, + KEY_READ, + &hkey) == ERROR_SUCCESS) { + + dwSize = 256; + RegQueryValueEx(hkey, + "", + NULL, + NULL, + (LPBYTE) value, + &dwSize); + + RegCloseKey(hkey); + + if (dwSize > 0) { + ::Print("Default Web Browser: %s\n", value); + browser = value; + } + } +} + +// +--------------------------------------------------------------------+ + +void +WebBrowser::FindOpenCommand() +{ + HKEY hkey; + char value[256] = ""; + DWORD dwSize; + + ZeroMemory(value, 256); + + if (RegOpenKeyEx(HKEY_CLASSES_ROOT, + browser + "\\shell\\open\\command", + 0, + KEY_READ, + &hkey) == ERROR_SUCCESS) { + + dwSize = 256; + RegQueryValueEx(hkey, + "", + NULL, + NULL, + (LPBYTE) value, + &dwSize); + + RegCloseKey(hkey); + + if (dwSize > 0) { + ::Print("Browser Shell Open Command: %s\n", value); + command = value; + } + } +} + +// +--------------------------------------------------------------------+ + + -- cgit v1.1