Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Qt scrollbar grippers 1.1: Fix control detection #1140

Merged
merged 4 commits into from
Oct 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 46 additions & 7 deletions mods/fix-qt-scrollbar-grippers.wh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// @id fix-qt-scrollbar-grippers
// @name Fix Qt scrollbar grippers
// @description Fixes scrollbar grippers in Qt 6.1+
// @version 1.0
// @version 1.1
// @author kawapure
// @github https://github.com/kawapure
// @twitter https://twitter.com/kawaipure
Expand Down Expand Up @@ -32,31 +32,45 @@ for injection.

In Windhawk, go to the "Advanced" tab and scroll down to
"Custom process inclusion list". In that box, put the filename of the `.exe`.
The mod will immediately apply to those programs after you click "Save".
The mod will immediately apply to those programs after you click "Save", although the best results usually require a restart
of that program because Qt may cache the bitmap, causing the element to sometimes appear unmodified.
*/
// ==/WindhawkModReadme==

#include <windhawk_api.h>
#include <windhawk_utils.h>
#include <uxtheme.h>
#include <vsstyle.h>
#include <winerror.h>

// Undocumented export from UXTheme to get the class from a theme handle.
HRESULT STDMETHODCALLTYPE (*GetThemeClass)(HTHEME hTheme, LPCWSTR pszClassIdList, int cchClass);

using DrawThemeBackgroundEx_t = decltype(&DrawThemeBackgroundEx);
DrawThemeBackgroundEx_t DrawThemeBackgroundEx_orig;
HRESULT WINAPI DrawThemeBackgroundEx_hook(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, LPCRECT pRect, const DTBGOPTS *pOptions)
{
HRESULT result = DrawThemeBackgroundEx_orig(hTheme, hdc, iPartId, iStateId, pRect, pOptions);

if (iPartId == SBP_THUMBBTNHORZ || iPartId == SBP_THUMBBTNVERT)
WCHAR szClassName[512];
HRESULT hrGetString = GetThemeClass(hTheme, szClassName, 512);

if (
SUCCEEDED(hrGetString) &&
wcsicmp(szClassName, L"ScrollBar") == 0 &&
(iPartId == SBP_THUMBBTNHORZ || iPartId == SBP_THUMBBTNVERT)
)
{
if (iPartId == SBP_THUMBBTNHORZ)
Wh_Log(L"dtb: is SBP_THUMBBTNHORZ");
else if (iPartId == SBP_THUMBBTNVERT)
Wh_Log(L"dtb: is SBP_THUMBBTNVERT");

Wh_Log(L"iStateId: %d", iStateId);

int gripperPart = iPartId == SBP_THUMBBTNHORZ
? SBP_GRIPPERHORZ
: SBP_GRIPPERVERT;
? SBP_GRIPPERHORZ
: SBP_GRIPPERVERT;

SIZE gripperSize = { 0 };
GetThemePartSize(hTheme, hdc, gripperPart, iStateId, nullptr, TS_TRUE, &gripperSize);
Expand All @@ -67,6 +81,7 @@ HRESULT WINAPI DrawThemeBackgroundEx_hook(HTHEME hTheme, HDC hdc, int iPartId, i
)
{
Wh_Log(L"drawing gripper");
Wh_Log(L"is dimensions %dx%d", pRect->right - pRect->left, pRect->bottom - pRect->top);

DrawThemeBackground(hTheme, hdc, gripperPart, iStateId, pRect, nullptr);
}
Expand All @@ -81,11 +96,35 @@ BOOL Wh_ModInit()
{
Wh_Log(L"Init");

Wh_SetFunctionHook(
HMODULE hModUxtheme = GetModuleHandleW(L"uxtheme.dll");

if (!hModUxtheme)
{
Wh_Log(L"UXTheme module not loaded. Mod failed to load.");
return FALSE;
}

// UXTheme ordinal export #74 = GetThemeClass: Gets the class name opened by that theme handle.
*(void **)&GetThemeClass = (void *)GetProcAddress(hModUxtheme, MAKEINTRESOURCEA(74));

if (!GetThemeClass)
{
Wh_Log(
L"GetThemeClass not exported by UXTheme. The mod may not be compatible with "
L"your version of Windows."
);
return FALSE;
}

if (!Wh_SetFunctionHook(
(void *)DrawThemeBackgroundEx,
(void *)DrawThemeBackgroundEx_hook,
(void **)&DrawThemeBackgroundEx_orig
);
))
{
Wh_Log(L"Failed to install DrawThemeBackgroundEx hooks. Mod failed to load.");
return FALSE;
}

return TRUE;
}
Expand Down