From 0ea5fc66924303d1bf73ba283a383e2aadee02f2 Mon Sep 17 00:00:00 2001 From: neodarz Date: Sat, 11 Aug 2018 20:21:34 +0200 Subject: Initial commit --- .../x-cvsweb-markup/index.html | 98 ++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 cvs/cvsweb.cgi/code/tool/open_file/open_file.cpp?rev=1.2&content-type=text/x-cvsweb-markup/index.html (limited to 'cvs/cvsweb.cgi/code/tool/open_file/open_file.cpp?rev=1.2&content-type=text') 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 @@ + + + +code/tool/open_file/open_file.cpp - view - 1.2 + +
[BACK] Return to open_file.cpp + CVS log [TXT][DIR] Up to Nevrax / code / tool / open_file

File: Nevrax / code / tool / open_file / open_file.cpp (download)
+Revision 1.2, Fri Dec 8 10:21:10 2000 UTC (18 months, 3 weeks ago) by corvazier +
Branch: MAIN +
CVS Tags: HEAD
Changes since 1.1: +10 -3 + lines
+no message
+
+

// 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;
+}
+
\ No newline at end of file -- cgit v1.2.1