From acfd3b1683e9413b6ff4d95c20906ce34eb151e1 Mon Sep 17 00:00:00 2001 From: ThirteenAG Date: Wed, 22 May 2024 17:39:13 +0800 Subject: [PATCH] replace messagebox with taskdialog --- source/dllmain.cpp | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/source/dllmain.cpp b/source/dllmain.cpp index e1fc5dc..efb8a2c 100644 --- a/source/dllmain.cpp +++ b/source/dllmain.cpp @@ -1,5 +1,9 @@ #include "dllmain.h" #include "exception.hpp" +#include +#include +#pragma comment(lib,"Comctl32.lib") +#pragma comment(linker,"\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") #include #include #include @@ -29,6 +33,18 @@ std::vector> updateFilenames; thread_local std::string sCurrentFindFileDirA; thread_local std::wstring sCurrentFindFileDirW; +HRESULT CALLBACK TaskDialogCallbackProc(HWND hwnd, UINT uNotification, WPARAM wParam, LPARAM lParam, LONG_PTR dwRefData) +{ + switch (uNotification) + { + case TDN_HYPERLINK_CLICKED: + ShellExecuteW(hwnd, L"open", (LPCWSTR)lParam, NULL, NULL, SW_SHOW); + break; + } + + return S_OK; +} + bool iequals(std::wstring_view s1, std::wstring_view s2) { std::wstring str1(std::move(s1)); @@ -646,8 +662,34 @@ void FindFiles(WIN32_FIND_DATAW* fd) auto e = GetLastError(); if (e != ERROR_DLL_INIT_FAILED && e != ERROR_BAD_EXE_FORMAT) // in case dllmain returns false or IMAGE_MACHINE is not compatible { + TASKDIALOGCONFIG tdc = { sizeof(TASKDIALOGCONFIG) }; + int nClickedBtn; + BOOL bCheckboxChecked; + LPCWSTR szTitle = L"ASI Loader", szHeader = L"", szContent = L""; + TASKDIALOG_BUTTON aCustomButtons[] = { { 1000, L"Continue" } }; + std::wstring msg = L"Unable to load " + std::wstring(fd->cFileName) + L". Error: " + std::to_wstring(e); - MessageBoxW(0, msg.c_str(), L"ASI Loader", MB_ICONERROR); + szHeader = msg.c_str(); + + if (e == ERROR_MOD_NOT_FOUND) + { + szContent = L"This ASI file requires a dependency that is missing from your system. To identify the missing dependency, download and run the free, open-source app, " \ + L"Dependencies.\n\n" \ + L"https://github.com/lucasg/Dependencies"; + } + + tdc.hwndParent = NULL; + tdc.dwFlags = TDF_USE_COMMAND_LINKS | TDF_ENABLE_HYPERLINKS | TDF_SIZE_TO_CONTENT | TDF_CAN_BE_MINIMIZED; + tdc.pButtons = aCustomButtons; + tdc.cButtons = _countof(aCustomButtons); + tdc.pszWindowTitle = szTitle; + tdc.pszMainIcon = TD_ERROR_ICON; + tdc.pszMainInstruction = szHeader; + tdc.pszContent = szContent; + tdc.pfCallback = TaskDialogCallbackProc; + tdc.lpCallbackData = 0; + + std::ignore = TaskDialogIndirect(&tdc, &nClickedBtn, NULL, &bCheckboxChecked); } } else