-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexamples.html
More file actions
229 lines (175 loc) · 7.85 KB
/
examples.html
File metadata and controls
229 lines (175 loc) · 7.85 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Programming examples</TITLE>
</HEAD>
<BODY BGCOLOR="Black" TEXT="White" LINK="#FF8040" VLINK="#BF152F" ALINK="#E14900" BACKGROUND="images/background1.jpg">
<H2 align=center>Programmming examples</H2>
<BR><BR><BR>
<P align=left>
<UL>Here are some small example snippets of code:</P>
<LI>Calling <A HREF="examples.html#HTMLHelp">HTMLHelp()</A> from Borland C++</P>
<LI><A HREF="examples.html#LaunchApp">LaunchApp()</A> with wait</P>
<LI><A HREF="examples.html#BrowseForFolder">BrowseForFolder()</A> with initial folder</P>
<LI><A HREF="examples.html#TFileOpenDialog">TFileOpenDialog</A> with multiple selection</P>
</UL>
<BR>
<BR>
<HR>
<BR>
<BR>
<DL>
<HR><BR>
<DT><A NAME = "HTMLHelp"></A><B>Calling HtmlHelp() from Borland C++</B>
<DD>The HTMLHelp.lib file provided by Microsoft cannot directly be used in Borland C++,
but the HTMLHelp control can be dynamicaly loaded and it's functions called.<br>
New version of the htmlhelp.h file can be downloaded from OWLNext site:
<a href="http://owlnext.sourceforge.net/add_ons/add_fil.zip">http://owlnext.sourceforge.net/add_ons/add_fil.zip</a><br>
<pre>
<code>
typedef HWND WINAPI (*HtmlHelpFunc)( HWND hwndCaller, LPCSTR pszFile,
UINT uCommand, DWORD dwData );
const char pszHelpOCXCtrl [] = <font color="yellow">"hhctrl.ocx"</font>;
hHelpOCX = ::LoadLibrary(pszHelpOCXCtrl);
if (!hHelpOCX) {
::MessageBox(hwndCaller, <font color="yellow">"Cannot use the html help!"</font>, <font color="yellow">"Error"</font>, MB_OK);
return;
}
HTMLHelp = (HtmlHelpFunc)::GetProcAddress(hHelpOCX, ATOM_HTMLHELP_API_ANSI);
<font color="aqua">// Now call HTMLHelp functions:</font>
HTMLHelp(hWnd, <font color="yellow">"myhelp.chm"</font>, HH_DISPLAY_TOPIC, <font color="yellow">0</font>);
HTMLHelp(hWnd, <font color="yellow">"myhelp.chm"</font>, HH_HELP_CONTEXT, id);
</code>
</pre>
<HR><BR>
<DT><A NAME = "LaunchApp"></A><B>LaunchApp()</B>
<DD>This is an example how to call external application (like PKZip or a MSDOS batch file)
and wait till it completes it's execution.
<PRE>
<CODE>
<B>void</B> LaunchApp(<B>const</B> <B>char</B> *program, <B>char</B> *cmdline, <B>const</B> <B>char</B> *path)
{
<B>char</B> *buf = <FONT COLOR="YELLOW">0</FONT>;
<B>if</B> (cmdline) <FONT COLOR="AQUA">// The lpCommandLine parameter may be modified by the call to CreateProcess(),</FONT>
{ <FONT COLOR="AQUA">// so make a temporary buffer to pass it safely</FONT>
buf = <B>new</B> <B>char</B>[strlen(cmdline) + <FONT COLOR="YELLOW">1</FONT>];
strcpy(buf, cmdline);
}
STARTUPINFO info;
ZeroMemory(&info, <B>sizeof</B>(STARTUPINFO));
info.cb = <B>sizeof</B>(STARTUPINFO);
PROCESS_INFORMATION process_info;
CreateProcess(program, buf, <FONT COLOR="YELLOW">0</FONT>, <FONT COLOR="YELLOW">0</FONT>, <B>false</B>, CREATE_NEW_CONSOLE, <FONT COLOR="YELLOW">0</FONT>, path, &info, &process_info);
WaitForSingleObject(process_info.hProcess, INFINITE);
<B>delete</B> [] buf;
}
</CODE>
</PRE>
<HR><BR>
<DT><A NAME = "BrowseForFolder"></A><B>BrowseForFolder()</B>
<DD>The Windows API function BrowseForFolder() is used to prompt the user for a folder.
This code example demonstrates how to use function, and how to set the initial folder.
The code taken from the <A HREF="http://msdn.microsoft.com/library/default.asp" TARGET="_blank">MSDN</A>
<A HREF="http://support.microsoft.com/support/kb/articles/q179/3/78.asp" TARGET="_blank">article</A>,
and modified to use the <A HREF="owl.html">OWL</A>/<A HREF="owlnext.html">OWLNext</A> TShell class.
<PRE>
<CODE>
<FONT COLOR="AQUA"><I>// Callback for the BrowseForFolder, which purpose is to set the initial folder
</I></FONT>
<B>int</B> CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM <FONT COLOR="AQUA"><I>/*lParam*/</I></FONT>, LPARAM lpData)
{
<B>switch</B> (uMsg)
{
<B>case</B> BFFM_INITIALIZED:
::SendMessage(hwnd, BFFM_SETSELECTION, (WPARAM)TRUE, lpData);
<B>break</B>;
}
<B>return</B> <FONT COLOR="YELLOW">0</FONT>;
}
<FONT COLOR="AQUA"><I>// The initial folder, and the result of the function are contained in buf
</I></FONT>
<B>bool</B> BrowseForFolder(HWND hWnd, <B>char</B> *buf)
{
<FONT COLOR="AQUA"><I>// Global pointer to the shell's IMalloc interface.
</I></FONT>
LPMALLOC g_pMalloc;
<FONT COLOR="AQUA"><I>// Get the shell's allocator.
</I></FONT>
<B>if</B> (!SUCCEEDED(TShell::SHGetMalloc(&g_pMalloc)))
<B>return</B> <B>false</B>;
BROWSEINFO bi;
LPITEMIDLIST pidlMyComputer; <FONT COLOR="AQUA"><I>// PIDL for MyComputer folder
</I></FONT>
LPITEMIDLIST pidlBrowse; <FONT COLOR="AQUA"><I>// PIDL selected by user
</I></FONT>
<FONT COLOR="AQUA"><I>// Get the PIDL for the Programs folder.
</I></FONT>
<B>if</B> (!SUCCEEDED(TShell::SHGetSpecialFolderLocation(hWnd, CSIDL_DRIVES, &pidlMyComputer)))
<B>return</B> <B>false</B>;
<FONT COLOR="AQUA"><I>// Fill in the BROWSEINFO structure.
</I></FONT>
bi.hwndOwner = hWnd;
bi.pidlRoot = pidlMyComputer;
bi.pszDisplayName = buf;
bi.lpszTitle = <FONT COLOR="YELLOW">"Select root folder"</FONT>;
bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_RETURNFSANCESTORS;
bi.lpfn = BrowseCallbackProc;
bi.lParam = (LPARAM)buf;
<FONT COLOR="AQUA"><I>// Browse for a folder and return its PIDL.
</I></FONT>
pidlBrowse = TShell::SHBrowseForFolder(&bi);
<B>bool</B> result = (pidlBrowse != <FONT COLOR="YELLOW">0</FONT>);
<B>if</B> (result)
{
<B>if</B> (!TShell::SHGetPathFromIDList(pidlBrowse, buf))
result = <B>false</B>;
<FONT COLOR="AQUA"><I>// Free the PIDL returned by SHBrowseForFolder.
</I></FONT>
g_pMalloc->Free(pidlBrowse);
}
<FONT COLOR="AQUA"><I>// Clean up.
</I></FONT>
g_pMalloc->Free(pidlMyComputer);
<B>return</B> result;
}
</CODE>
</PRE>
<HR><BR>
<DT><A NAME = "TFileOpenDialog"></A><B>TFileOpenDialog</B> with multiple files selection
<DD>When both the flags <B>OFN_EXPLORER</B> and <B>OFN_ALLOWMULTISELECT</B> are used in FileOpen dialog,
and more than one file is selected, the returned result has the following format: The path to the directory,
followed by the filenames of the selected files, using '\0' as delimiters. The last filename is followed by two '\0'.
Here is an example how to work with the <A HREF="owl.html">OWL</A> class <B>TFileOpenDialog</B>:
<PRE>
<CODE>
TOpenSaveDialog::TData FileData;
FileData.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_EXPLORER | OFN_ALLOWMULTISELECT;
FileData.SetFilter(<FONT COLOR="YELLOW">"VRML Files (*.vrml;*.wrl;*.wrz)|*.vrml;*.wrl;*.wrz|All Files (*.*)|*.*|"</FONT>);
FileData.DefExt = <FONT COLOR="YELLOW">"wrl"</FONT>;
<B>if</B> (TFileOpenDialog(<B>this</B>, FileData).Execute() == IDOK)
{
<B>char</B> buf[_MAX_PATH + <FONT COLOR="YELLOW">1</FONT>];
<B>char</B> *p = FileData.FileName + strlen(FileData.FileName) + <FONT COLOR="YELLOW">1</FONT>;
<B>do</B>
{
strcpy(buf, FileData.FileName);
<B>if</B> (*p) <FONT COLOR="AQUA">// The case of multiple file selection</FONT>
{
strcat(buf, <FONT COLOR="YELLOW">"\\"</FONT>);
strcat(buf, p);
}
<FONT COLOR="AQUA">// Process the file</FONT>
MessageBox(buf);
<FONT COLOR="AQUA">// go to next file name</FONT>
<B>if</B> (*p)
p = p + strlen(p) + <FONT COLOR="YELLOW">1</FONT>;
} <B>while</B> (*p);
}
</CODE>
</PRE>
</DL>
<BR><A HREF="index.html">
<IMG SRC="images/flowchart.gif" WIDTH="48" HEIGHT="48" BORDER="0" ALT="Back to home">
Back to main</A>
</BODY>
</HTML>