[MSPAINT] Unlink HHCTRL.OCX and use dynamic load (#5165)

Unlink HHCTRL.OCX by modifying CMakeLists.txt. Add DoHtmlHelpW helper function. CORE-18879, CORE-18867
This commit is contained in:
Katayama Hirofumi MZ 2023-03-17 07:25:51 +09:00 committed by GitHub
parent eb7550f767
commit 88733bca77
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 4 deletions

View file

@ -36,6 +36,6 @@ add_executable(mspaint ${SOURCE} rsrc.rc)
set_module_type(mspaint win32gui UNICODE)
target_link_libraries(mspaint uuid cpprt atl_classes)
set_target_cpp_properties(mspaint WITH_EXCEPTIONS)
add_importlibs(mspaint hhctrl comdlg32 shell32 user32 gdi32 advapi32 comctl32 msvcrt kernel32 rpcrt4 shlwapi ntdll)
add_importlibs(mspaint comdlg32 shell32 user32 gdi32 advapi32 comctl32 msvcrt kernel32 rpcrt4 shlwapi ntdll)
add_pch(mspaint precomp.h SOURCE)
add_cd_file(TARGET mspaint DESTINATION reactos/system32 FOR all)

View file

@ -9,12 +9,36 @@
* Stanislav Motylkov
*/
/* INCLUDES *********************************************************/
#include "precomp.h"
typedef HWND (WINAPI *FN_HtmlHelpW)(HWND, LPCWSTR, UINT, DWORD_PTR);
static HINSTANCE s_hHHCTRL_OCX = NULL; // HtmlHelpW needs "hhctrl.ocx"
static FN_HtmlHelpW s_pHtmlHelpW = NULL;
/* FUNCTIONS ********************************************************/
// A wrapper function for HtmlHelpW
static HWND DoHtmlHelpW(HWND hwndCaller, LPCWSTR pszFile, UINT uCommand, DWORD_PTR dwData)
{
WCHAR szPath[MAX_PATH];
if (!s_hHHCTRL_OCX && (uCommand != HH_CLOSE_ALL))
{
// The function loads the system library, not local
GetSystemDirectoryW(szPath, _countof(szPath));
wcscat(szPath, L"\\hhctrl.ocx");
s_hHHCTRL_OCX = LoadLibraryW(szPath);
if (s_hHHCTRL_OCX)
s_pHtmlHelpW = (FN_HtmlHelpW)GetProcAddress(s_hHHCTRL_OCX, "HtmlHelpW");
}
if (!s_pHtmlHelpW)
return NULL;
return s_pHtmlHelpW(hwndCaller, pszFile, uCommand, dwData);
}
BOOL
zoomTo(int newZoom, int mouseX, int mouseY)
{
@ -235,6 +259,16 @@ LRESULT CMainWindow::OnCreate(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHa
LRESULT CMainWindow::OnDestroy(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
GetWindowPlacement(&(registrySettings.WindowPlacement));
DoHtmlHelpW(NULL, NULL, HH_CLOSE_ALL, 0);
if (s_hHHCTRL_OCX)
{
FreeLibrary(s_hHHCTRL_OCX);
s_hHHCTRL_OCX = NULL;
s_pHtmlHelpW = NULL;
}
PostQuitMessage(0); /* send a WM_QUIT to the message queue */
return 0;
}
@ -445,7 +479,7 @@ LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bH
break;
}
case IDM_HELPHELPTOPICS:
HtmlHelp(m_hWnd, _T("help\\Paint.chm"), 0, 0);
DoHtmlHelpW(m_hWnd, L"%SystemRoot%\\Help\\mspaint.chm", HH_DISPLAY_TOPIC, 0);
break;
case IDM_FILEEXIT:
SendMessage(WM_CLOSE, wParam, lParam);