2 * Help Viewer Implementation
4 * Copyright 2005 James Hawkins
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 /* Window type defaults */
34 #define WINTYPE_DEFAULT_X 280
35 #define WINTYPE_DEFAULT_Y 100
36 #define WINTYPE_DEFAULT_WIDTH 740
37 #define WINTYPE_DEFAULT_HEIGHT 640
39 typedef struct tagHHInfo
41 HH_WINTYPEW *pHHWinType;
47 static LPWSTR HH_ANSIToUnicode(LPCSTR ansi)
52 count = MultiByteToWideChar(CP_ACP, 0, ansi, -1, NULL, 0);
53 unicode = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR));
54 MultiByteToWideChar(CP_ACP, 0, ansi, -1, unicode, count);
61 static BOOL HH_AddToolbar(HHInfo *pHHInfo)
68 static BOOL HH_AddNavigationPane(HHInfo *pHHInfo)
75 static BOOL HH_AddHTMLPane(HHInfo *pHHInfo)
82 LRESULT CALLBACK Help_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
91 hdc = BeginPaint(hWnd, &ps);
99 return DefWindowProcW(hWnd, message, wParam, lParam);
105 static BOOL HH_CreateHelpWindow(HHInfo *pHHInfo)
108 HINSTANCE hInstance = pHHInfo->hInstance;
110 DWORD dwStyles, dwExStyles;
111 DWORD x, y, width, height;
113 static const WCHAR windowClassW[] = {
114 'H','H',' ', 'P','a','r','e','n','t',0
117 static const WCHAR windowTitleW[] = {
118 'H','T','M','L',' ','H','e','l','p',0
121 wcex.cbSize = sizeof(WNDCLASSEXW);
122 wcex.style = CS_HREDRAW | CS_VREDRAW;
123 wcex.lpfnWndProc = (WNDPROC)Help_WndProc;
126 wcex.hInstance = hInstance;
127 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
128 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW);
129 wcex.hbrBackground = (HBRUSH)(COLOR_BACKGROUND + 1);
130 wcex.lpszMenuName = NULL;
131 wcex.lpszClassName = windowClassW;
132 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
134 RegisterClassExW(&wcex);
136 dwStyles = WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
137 dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR |
138 WS_EX_WINDOWEDGE | WS_EX_APPWINDOW;
140 /* these will be loaded from the CHM file in the future if they're provided */
141 x = WINTYPE_DEFAULT_X;
142 y = WINTYPE_DEFAULT_Y;
143 width = WINTYPE_DEFAULT_WIDTH;
144 height = WINTYPE_DEFAULT_HEIGHT;
146 hWnd = CreateWindowExW(dwExStyles, windowClassW, windowTitleW, dwStyles,
147 x, y, width, height, NULL, NULL, hInstance, NULL);
151 ShowWindow(hWnd, SW_SHOW);
154 /* store the pointer to the HH info struct */
155 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)pHHInfo);
157 pHHInfo->pHHWinType->hwndHelp = hWnd;
161 static void HH_CreateFont(HHInfo *pHHInfo)
165 GetObjectW(GetStockObject(ANSI_VAR_FONT), sizeof(LOGFONTW), &lf);
166 lf.lfWeight = FW_NORMAL;
168 lf.lfUnderline = FALSE;
170 pHHInfo->hFont = CreateFontIndirectW(&lf);
173 static void HH_InitRequiredControls(DWORD dwControls)
175 INITCOMMONCONTROLSEX icex;
177 icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
178 icex.dwICC = dwControls;
179 InitCommonControlsEx(&icex);
182 /* Creates the whole package */
183 static BOOL HH_CreateViewer(HHInfo *pHHInfo)
185 HH_CreateFont(pHHInfo);
187 if (!HH_CreateHelpWindow(pHHInfo))
190 HH_InitRequiredControls(ICC_BAR_CLASSES);
192 if (!HH_AddToolbar(pHHInfo))
195 if (!HH_AddNavigationPane(pHHInfo))
198 if (!HH_AddHTMLPane(pHHInfo))
204 static HHInfo *HH_OpenHH(HINSTANCE hInstance, LPCWSTR szCmdLine)
206 HHInfo *pHHInfo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(HHInfo));
208 pHHInfo->pHHWinType = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(HH_WINTYPEW));
209 pHHInfo->hInstance = hInstance;
210 pHHInfo->szCmdLine = szCmdLine;
215 static void HH_Close(HHInfo *pHHInfo)
220 HeapFree(GetProcessHeap(), 0, pHHInfo->pHHWinType);
223 /* FIXME: Check szCmdLine for bad arguments */
224 int WINAPI doWinMain(HINSTANCE hInstance, LPSTR szCmdLine)
229 if (OleInitialize(NULL) != S_OK)
232 pHHInfo = HH_OpenHH(hInstance, HH_ANSIToUnicode(szCmdLine));
233 if (!pHHInfo || !HH_CreateViewer(pHHInfo))
239 while (GetMessageW(&msg, 0, 0, 0))
241 TranslateMessage(&msg);
242 DispatchMessageW(&msg);
246 HeapFree(GetProcessHeap(), 0, pHHInfo);