-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelp_win.cpp
More file actions
39 lines (34 loc) · 1.49 KB
/
help_win.cpp
File metadata and controls
39 lines (34 loc) · 1.49 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
// Windows CHM help launcher. Opens wxmine.chm in HTML Help Viewer using the
// HtmlHelp API (hhctrl.ocx). The CHM is shipped alongside wxmine.exe by the
// CMake POST_BUILD step, so we resolve it relative to the running executable
// rather than assuming a CWD.
//
// Mirrors help_mac.mm's ShowMacHelpBook(anchor) so callers can use one name
// per platform: ShowWinHelp(anchor) / ShowMacHelpBook(anchor).
#include <windows.h>
#include <htmlhelp.h>
#include <string>
extern "C" void ShowWinHelp(const char *anchor)
{
wchar_t exePath[MAX_PATH];
DWORD n = GetModuleFileNameW(nullptr, exePath, MAX_PATH);
if (n == 0 || n == MAX_PATH) return;
std::wstring chm(exePath, n);
size_t slash = chm.find_last_of(L"\\/");
chm.resize(slash == std::wstring::npos ? 0 : slash + 1);
chm += L"wxmine.chm";
if (anchor && *anchor) {
// HtmlHelpW wants "path::/topic.htm" for HH_DISPLAY_TOPIC. Widen the
// anchor from UTF-8; topic filenames in the CHM are ASCII so a plain
// MultiByteToWideChar suffices.
int wlen = MultiByteToWideChar(CP_UTF8, 0, anchor, -1, nullptr, 0);
if (wlen > 0) {
std::wstring wanchor(wlen - 1, L'\0');
MultiByteToWideChar(CP_UTF8, 0, anchor, -1, &wanchor[0], wlen);
std::wstring target = chm + L"::/" + wanchor;
HtmlHelpW(GetDesktopWindow(), target.c_str(), HH_DISPLAY_TOPIC, 0);
return;
}
}
HtmlHelpW(GetDesktopWindow(), chm.c_str(), HH_DISPLAY_TOPIC, 0);
}