aboutsummaryrefslogtreecommitdiff
path: root/cvs/cvsweb.cgi/code/tool/open_file/open_file.cpp?rev=1.2&content-type=text/x-cvsweb-markup/index.html
blob: ae82c6847201377ef113e8c32703982cd7e18d63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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>&nbsp;(<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 &lt;windows.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;

LONG GetRegKey(HKEY key, LPCTSTR subkey, LPTSTR retdata)
{
 &nbsp; &nbsp;HKEY hkey;
 &nbsp; &nbsp;LONG retval = RegOpenKeyEx(key, subkey, 0, KEY_QUERY_VALUE, &amp;hkey);

 &nbsp; &nbsp;if (retval == ERROR_SUCCESS) 
 &nbsp; &nbsp; &nbsp; &nbsp;{
 &nbsp; &nbsp; &nbsp; &nbsp;long datasize = MAX_PATH;
 &nbsp; &nbsp; &nbsp; &nbsp;TCHAR data[MAX_PATH];
 &nbsp; &nbsp; &nbsp; &nbsp;RegQueryValue(hkey, NULL, data, &amp;datasize);
 &nbsp; &nbsp; &nbsp; &nbsp;lstrcpy(retdata,data);
 &nbsp; &nbsp; &nbsp; &nbsp;RegCloseKey(hkey);
 &nbsp; &nbsp;}

 &nbsp; &nbsp;return retval;
}

bool OpenFile (LPCTSTR filename, LPCTSTR ext, int showcmd)
{
 &nbsp; &nbsp;TCHAR key[MAX_PATH + MAX_PATH];

 &nbsp; &nbsp;// First try ShellExecute()
 &nbsp; &nbsp;HINSTANCE result = ShellExecute(NULL, &quot;open&quot;, filename, NULL,NULL, showcmd);

 &nbsp; &nbsp;// If it failed, get the .htm regkey and lookup the program
 &nbsp; &nbsp;if ((UINT)result &lt;= HINSTANCE_ERROR) 
 &nbsp; &nbsp; &nbsp; &nbsp;{
 &nbsp; &nbsp; &nbsp; &nbsp;if (GetRegKey(HKEY_CLASSES_ROOT, ext, key) == ERROR_SUCCESS) 
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;lstrcat(key, &quot;\\shell\\open\\command&quot;);

 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (GetRegKey(HKEY_CLASSES_ROOT,key,key) == ERROR_SUCCESS) 
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TCHAR *pos;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pos = strstr(key, &quot;\&quot;%1\&quot;&quot;);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (pos == NULL) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // No quotes found
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pos = strstr(key, &quot;%1&quot;); &nbsp; &nbsp; &nbsp; // Check for %1, without quotes 
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (pos == NULL) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // No parameter at all...
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pos = key+lstrlen(key)-1;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*pos = '\0'; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Remove the parameter
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*pos = '\0'; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Remove the parameter

 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;lstrcat(pos, &quot; &quot;);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;lstrcat(pos, filename);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int res = WinExec(key,showcmd);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return (res&gt;31);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}
 &nbsp; &nbsp; &nbsp; &nbsp;}
 &nbsp; &nbsp;}
 &nbsp; &nbsp; &nbsp; &nbsp;else
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return true;

 &nbsp; &nbsp; &nbsp; &nbsp;return false;
}

int APIENTRY WinMain(HINSTANCE hInstance,
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HINSTANCE hPrevInstance,
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LPSTR &nbsp; &nbsp; lpCmdLine,
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int &nbsp; &nbsp; &nbsp; nCmdShow)
{
 &nbsp; &nbsp; &nbsp; &nbsp;// TODO: Place code here.
 &nbsp; &nbsp; &nbsp; &nbsp;if (strcmp (lpCmdLine, &quot;&quot;)==0)
 &nbsp; &nbsp; &nbsp; &nbsp;{
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MessageBox (NULL, &quot;Open a file with the default application.\nUsage: open_file [filepath]&quot;, &quot;Open file&quot;, MB_OK|MB_ICONINFORMATION);
 &nbsp; &nbsp; &nbsp; &nbsp;}
 &nbsp; &nbsp; &nbsp; &nbsp;else
 &nbsp; &nbsp; &nbsp; &nbsp;{
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;char ext[512];
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_splitpath (lpCmdLine, NULL, NULL, NULL, ext);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;OpenFile(lpCmdLine, ext, SW_SHOW);
 &nbsp; &nbsp; &nbsp; &nbsp;}

 &nbsp; &nbsp; &nbsp; &nbsp;return 0;
}
</PRE>