Skip to content

Instantly share code, notes, and snippets.

@superllama
Last active February 25, 2020 00:36
Show Gist options
  • Save superllama/48e28a9d667304d1f9bb8468fdd3fae5 to your computer and use it in GitHub Desktop.
Save superllama/48e28a9d667304d1f9bb8468fdd3fae5 to your computer and use it in GitHub Desktop.
a throwaway C++ program that uses WinAPI calls to fix a very specific scrollbar issue caused by ActiveX controls on a specific intranet website on a specific version of Windows 10
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
//detect if the scrollbar is one of the ones affected by the bug
bool IsBrokenScrollbar(HWND hw) {
char clsname[256];
GetClassName(hw, clsname, 256);
if (strcmp(clsname, "ScrollBar")) return false;
GetClassName(GetParent(hw), clsname, 256);
if (strcmp(clsname, "DataTable5")) return false;
return true;
}
//replace the broken scrollbar's weird VB6 WndProc with a proper Win32 scrollbar WndProc
LRESULT CALLBACK CallWndProc(int code, WPARAM wp, LPARAM lp) {
CWPSTRUCT* cwp = (CWPSTRUCT*)lp;
if (code < 0) return CallNextHookEx(0, code, wp, lp);
if (cwp->message == WM_CREATE && IsBrokenScrollbar(cwp->hwnd)) {
HWND win32_scrollbar = CreateWindow("SCROLLBAR", "", 0, 0, 0, 0, 0, cwp->hwnd, 0, GetModuleHandle(0), 0);
WNDPROC win32_proc = (WNDPROC)GetWindowLong(win32_scrollbar, GWL_WNDPROC);
DestroyWindow(win32_scrollbar);
SetWindowLong(cwp->hwnd, GWL_WNDPROC, (LONG)win32_proc);
}
return CallNextHookEx(0,code,wp,lp);
}
//rundll32 entry point for hook
extern "C" LRESULT _declspec(dllexport) WINAPI Activate(HINSTANCE hi, HINSTANCE hp, char* cmd, int sc) {
HHOOK hook = SetWindowsHookEx(WH_CALLWNDPROC, (HOOKPROC)CallWndProc, (HINSTANCE)GetModuleHandle("scrollbar_fix.dll"), 0);
WaitForSingleObject(GetCurrentProcess(), INFINITE);
return 0;
}
//TO RUN: compile this DLL and run 'rundll32.exe c:\path\to\scrollbar_fix.dll,_Activate@16' after login.
//TO CLOSE: close the rundll32.exe processes associated with this process and the hook will uninstall.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment