typedef HWND WINAPI (*HtmlHelpFunc)( HWND hwndCaller, LPCSTR pszFile,
UINT uCommand, DWORD dwData );
const char pszHelpOCXCtrl [] = "hhctrl.ocx";
hHelpOCX = ::LoadLibrary(pszHelpOCXCtrl);
if (!hHelpOCX) {
::MessageBox(hwndCaller, "Cannot use the html help!", "Error", MB_OK);
return;
}
HTMLHelp = (HtmlHelpFunc)::GetProcAddress(hHelpOCX, ATOM_HTMLHELP_API_ANSI);
// Now call HTMLHelp functions:
HTMLHelp(hWnd, "myhelp.chm", HH_DISPLAY_TOPIC, 0);
HTMLHelp(hWnd, "myhelp.chm", HH_HELP_CONTEXT, id);
void LaunchApp(const char *program, char *cmdline, const char *path)
{
char *buf = 0;
if (cmdline) // The lpCommandLine parameter may be modified by the call to CreateProcess(),
{ // so make a temporary buffer to pass it safely
buf = new char[strlen(cmdline) + 1];
strcpy(buf, cmdline);
}
STARTUPINFO info;
ZeroMemory(&info, sizeof(STARTUPINFO));
info.cb = sizeof(STARTUPINFO);
PROCESS_INFORMATION process_info;
CreateProcess(program, buf, 0, 0, false, CREATE_NEW_CONSOLE, 0, path, &info, &process_info);
WaitForSingleObject(process_info.hProcess, INFINITE);
delete [] buf;
}
// Callback for the BrowseForFolder, which purpose is to set the initial folder
int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM /*lParam*/, LPARAM lpData)
{
switch (uMsg)
{
case BFFM_INITIALIZED:
::SendMessage(hwnd, BFFM_SETSELECTION, (WPARAM)TRUE, lpData);
break;
}
return 0;
}
// The initial folder, and the result of the function are contained in buf
bool BrowseForFolder(HWND hWnd, char *buf)
{
// Global pointer to the shell's IMalloc interface.
LPMALLOC g_pMalloc;
// Get the shell's allocator.
if (!SUCCEEDED(TShell::SHGetMalloc(&g_pMalloc)))
return false;
BROWSEINFO bi;
LPITEMIDLIST pidlMyComputer; // PIDL for MyComputer folder
LPITEMIDLIST pidlBrowse; // PIDL selected by user
// Get the PIDL for the Programs folder.
if (!SUCCEEDED(TShell::SHGetSpecialFolderLocation(hWnd, CSIDL_DRIVES, &pidlMyComputer)))
return false;
// Fill in the BROWSEINFO structure.
bi.hwndOwner = hWnd;
bi.pidlRoot = pidlMyComputer;
bi.pszDisplayName = buf;
bi.lpszTitle = "Select root folder";
bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_RETURNFSANCESTORS;
bi.lpfn = BrowseCallbackProc;
bi.lParam = (LPARAM)buf;
// Browse for a folder and return its PIDL.
pidlBrowse = TShell::SHBrowseForFolder(&bi);
bool result = (pidlBrowse != 0);
if (result)
{
if (!TShell::SHGetPathFromIDList(pidlBrowse, buf))
result = false;
// Free the PIDL returned by SHBrowseForFolder.
g_pMalloc->Free(pidlBrowse);
}
// Clean up.
g_pMalloc->Free(pidlMyComputer);
return result;
}
TOpenSaveDialog::TData FileData;
FileData.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_EXPLORER | OFN_ALLOWMULTISELECT;
FileData.SetFilter("VRML Files (*.vrml;*.wrl;*.wrz)|*.vrml;*.wrl;*.wrz|All Files (*.*)|*.*|");
FileData.DefExt = "wrl";
if (TFileOpenDialog(this, FileData).Execute() == IDOK)
{
char buf[_MAX_PATH + 1];
char *p = FileData.FileName + strlen(FileData.FileName) + 1;
do
{
strcpy(buf, FileData.FileName);
if (*p) // The case of multiple file selection
{
strcat(buf, "\\");
strcat(buf, p);
}
// Process the file
MessageBox(buf);
// go to next file name
if (*p)
p = p + strlen(p) + 1;
} while (*p);
}