diff options
author | neodarz <neodarz@neodarz.net> | 2018-08-11 20:21:34 +0200 |
---|---|---|
committer | neodarz <neodarz@neodarz.net> | 2018-08-11 20:21:34 +0200 |
commit | 0ea5fc66924303d1bf73ba283a383e2aadee02f2 (patch) | |
tree | 2568e71a7ccc44ec23b8bb3f0ff97fb6bf2ed709 /cvs/cvsweb.cgi/code/tool/open_file/open_file.cpp?rev=1.2&content-type=text/x-cvsweb-markup | |
download | nevrax-website-self-hostable-0ea5fc66924303d1bf73ba283a383e2aadee02f2.tar.xz nevrax-website-self-hostable-0ea5fc66924303d1bf73ba283a383e2aadee02f2.zip |
Initial commit
Diffstat (limited to '')
-rw-r--r-- | cvs/cvsweb.cgi/code/tool/open_file/open_file.cpp?rev=1.2&content-type=text/x-cvsweb-markup/index.html | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/cvs/cvsweb.cgi/code/tool/open_file/open_file.cpp?rev=1.2&content-type=text/x-cvsweb-markup/index.html b/cvs/cvsweb.cgi/code/tool/open_file/open_file.cpp?rev=1.2&content-type=text/x-cvsweb-markup/index.html new file mode 100644 index 00000000..ae82c684 --- /dev/null +++ b/cvs/cvsweb.cgi/code/tool/open_file/open_file.cpp?rev=1.2&content-type=text/x-cvsweb-markup/index.html @@ -0,0 +1,98 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML> +<HEAD><style> A { color:black }</style> +<!-- hennerik CVSweb $Revision: 1.93 $ --> +<TITLE>code/tool/open_file/open_file.cpp - view - 1.2</TITLE></HEAD> +<BODY BGCOLOR="#eeeeee"> +<table width="100%" border=0 cellspacing=0 cellpadding=1 bgcolor="#aaaaaa"><tr valign=bottom><td><a href="open_file.cpp"><IMG SRC="http://www.nevrax.org/inc/img/picto-up.gif" ALT="[BACK]" BORDER="0" WIDTH="14" HEIGHT="13"></a> <b>Return to <A HREF="open_file.cpp">open_file.cpp</A> + CVS log</b> <IMG SRC="http://www.nevrax.org/inc/img/picto-news.gif" ALT="[TXT]" BORDER="0" WIDTH="13" HEIGHT="15"></td><td align=right><IMG SRC="http://www.nevrax.org/inc/img/picto-dir.gif" ALT="[DIR]" BORDER="0" WIDTH="15" HEIGHT="13"> <b>Up to <a href="/cvs/cvsweb.cgi/">Nevrax</a> / <a href="/cvs/cvsweb.cgi/code/">code</a> / <a href="/cvs/cvsweb.cgi/code/tool/">tool</a> / <a href="/cvs/cvsweb.cgi/code/tool/open_file/">open_file</a></b></td></tr></table><HR noshade><table width="100%"><tr><td bgcolor="#ffffff">File: <a href="/cvs/cvsweb.cgi/">Nevrax</a> / <a href="/cvs/cvsweb.cgi/code/">code</a> / <a href="/cvs/cvsweb.cgi/code/tool/">tool</a> / <a href="/cvs/cvsweb.cgi/code/tool/open_file/">open_file</a> / <a href="/cvs/cvsweb.cgi/code/tool/open_file/open_file.cpp">open_file.cpp</a> (<A HREF="/cvs/cvsweb.cgi/~checkout~/code/tool/open_file/open_file.cpp?rev=1.2" target="cvs_checkout" onClick="window.open('/cvs/cvsweb.cgi/~checkout~/code/tool/open_file/open_file.cpp?rev=1.2','cvs_checkout','resizeable,scrollbars');"><b>download</b></A>)<BR> +Revision <B>1.2</B>, <i>Fri Dec 8 10:21:10 2000 UTC</i> (18 months, 3 weeks ago) by <i>corvazier</i> +<BR>Branch: <b>MAIN</b> +<BR>CVS Tags: <b>HEAD</b><BR>Changes since <b>1.1: +10 -3 + lines</b><PRE> +no message +</PRE> +</td></tr></table><HR noshade><PRE>// openhtml.cpp : Defines the entry point for the application. +// + +#include <windows.h> +#include <stdlib.h> +#include <stdio.h> + +LONG GetRegKey(HKEY key, LPCTSTR subkey, LPTSTR retdata) +{ + HKEY hkey; + LONG retval = RegOpenKeyEx(key, subkey, 0, KEY_QUERY_VALUE, &hkey); + + if (retval == ERROR_SUCCESS) + { + long datasize = MAX_PATH; + TCHAR data[MAX_PATH]; + RegQueryValue(hkey, NULL, data, &datasize); + lstrcpy(retdata,data); + RegCloseKey(hkey); + } + + return retval; +} + +bool OpenFile (LPCTSTR filename, LPCTSTR ext, int showcmd) +{ + TCHAR key[MAX_PATH + MAX_PATH]; + + // First try ShellExecute() + HINSTANCE result = ShellExecute(NULL, "open", filename, NULL,NULL, showcmd); + + // If it failed, get the .htm regkey and lookup the program + if ((UINT)result <= HINSTANCE_ERROR) + { + if (GetRegKey(HKEY_CLASSES_ROOT, ext, key) == ERROR_SUCCESS) + { + lstrcat(key, "\\shell\\open\\command"); + + if (GetRegKey(HKEY_CLASSES_ROOT,key,key) == ERROR_SUCCESS) + { + TCHAR *pos; + pos = strstr(key, "\"%1\""); + if (pos == NULL) { // No quotes found + pos = strstr(key, "%1"); // Check for %1, without quotes + if (pos == NULL) // No parameter at all... + pos = key+lstrlen(key)-1; + else + *pos = '\0'; // Remove the parameter + } + else + *pos = '\0'; // Remove the parameter + + lstrcat(pos, " "); + lstrcat(pos, filename); + int res = WinExec(key,showcmd); + return (res>31); + } + } + } + else + return true; + + return false; +} + +int APIENTRY WinMain(HINSTANCE hInstance, + HINSTANCE hPrevInstance, + LPSTR lpCmdLine, + int nCmdShow) +{ + // TODO: Place code here. + if (strcmp (lpCmdLine, "")==0) + { + MessageBox (NULL, "Open a file with the default application.\nUsage: open_file [filepath]", "Open file", MB_OK|MB_ICONINFORMATION); + } + else + { + char ext[512]; + _splitpath (lpCmdLine, NULL, NULL, NULL, ext); + OpenFile(lpCmdLine, ext, SW_SHOW); + } + + return 0; +} +</PRE>
\ No newline at end of file |