#define _WIN32_WINNT 0x0400
#include <windows.h>
#define IE_HANDLER
// Quelltext für Visual C++ 6.0
// Funktion: Rollrad für alle (älteren Programme)
// h#s 12/02
// In Einstellung "DEBUG" ist der Compiler-Schalter "/GZ" zu entfernen!
#pragma comment(linker,"/ALIGN:4096 /DLL /MERGE:.rsrc=.rdata")
#pragma comment(linker,"/SECTION:.shared,RWS /RELEASE /NODEFAULTLIB")
#pragma data_seg(".shared")
HHOOK g_hHook=0; // Initialisierung ist notwendig
int g_ScrollWidth; // denn diese hier gehen ins BSS-Segment
HWND lernwnd;
int lerncount;
int lernnext;
//#pragma data_seg()
HHOOK g_HookProcess; // Initialisierung für NT-Ladbarkeit ->bss_seg
BYTE CheckScrollBar(HWND Wnd) {
/* Liefert 0 (kein Rollbalken), 1 (horizontal) oder 2 (vertikal) */
TCHAR classname[12];
GetClassName(Wnd,classname,sizeof(classname)/sizeof(TCHAR));
if (lstrcmpi("ScrollBar",classname)) return 0;
if (GetWindowLong(Wnd,GWL_STYLE) & SBS_VERT) return 2;
return 1;
}
BYTE HasSiblingScrollBar(HWND Wnd, HWND *WScroll) {
/*Stellt fest, ob das Fenster <Wnd> Rollbalken als Nachbarn hat,
welche an das übergeordnete Fenster WM_HScroll oder WM_VScroll
senden könnten. Wenn ja, wird das Handle in <WScroll> geschrieben.
Findet auch die links befindlichen Rollbalken in RTL-Fenstern.*/
HWND hsw,vsw;
BYTE ret=0;
for (Wnd=GetWindow(Wnd,GW_HWNDFIRST); Wnd; Wnd=GetWindow(Wnd,GW_HWNDNEXT)) {
switch (CheckScrollBar(Wnd)) {
case 1: hsw=Wnd; ret|=1; break;
case 2: vsw=Wnd; ret|=2; break;
}
}
if (ret) *WScroll=ret&2?vsw:hsw; // vertikaler hat Vorrang
return ret;
}
BYTE Point_Finder(HWND Wnd, HWND *WScroll) {
/* Ermittelt das Fenster, das sich RECHTS oder UNTEN befindet */
HWND tmp;
POINT P;
RECT R;
tmp=GetParent(Wnd);
if (tmp==0) return 0;
if (tmp==GetDesktopWindow()) return 0;
GetWindowRect(Wnd,&R);
// nach rechts gucken
P.x=R.right+GetSystemMetrics(SM_CXVSCROLL)/2;
P.y=(R.top+R.bottom)/2;
tmp=WindowFromPoint(P);
if (tmp && CheckScrollBar(tmp)==2) {
*WScroll=tmp;
return 2;
}
// nach unten gucken
P.x=(R.left+R.right)/2;
P.y=R.bottom+GetSystemMetrics(SM_CYHSCROLL)/2;
tmp=WindowFromPoint(P);
if (tmp && CheckScrollBar(tmp)==1) {
*WScroll=tmp;
return 1;
}
return 0;
}
void resetlern(HWND wnd) {
lernwnd=wnd;
lerncount=0;
lernnext=0;
}
LRESULT CALLBACK LowLevelMouseProc(int code, WPARAM wParam, LPARAM lParam) {
#define mlhs ((LPMSLLHOOKSTRUCT)lParam)
HWND wnd,tmp;
LPMSLLHOOKSTRUCT x;
int rol;
int ScrollWidth;
DWORD style;
WORD msg;
WORD hitcode;
BOOL pa; // Seitenweise-Flag
WPARAM wpar;
LPARAM lpar;
TCHAR s[32];
if (code!=HC_ACTION) goto exi;
if (wParam!=WM_MOUSEWHEEL) goto exi;
x=mlhs;
rol=(short)HIWORD(mlhs->mouseData);
wnd=WindowFromPoint(mlhs->pt);
if (!wnd) goto exi;
GetClassName(wnd,s,sizeof(s)/sizeof(TCHAR));
ScrollWidth=GetProfileInt("wheel32",s,0);
if (wnd==lernwnd && (rol==lernnext || lernnext==0)) {
lernnext=-rol;
lerncount++;
if (lerncount>=5) {
TCHAR buf[8];
ScrollWidth=ScrollWidth ? 0 : g_ScrollWidth;
MessageBeep(ScrollWidth ? MB_OK : MB_ICONHAND);
wsprintf(buf,"%d",ScrollWidth);
WriteProfileString("wheel32",s,ScrollWidth ? buf : NULL);
resetlern(wnd);
}
}else resetlern(wnd);
if (!ScrollWidth) goto exi;
style=GetWindowLong(wnd,GWL_STYLE);
hitcode=(WORD)SendMessage(wnd,WM_NCHITTEST,0,MAKELONG(mlhs->pt.x,mlhs->pt.y));
#ifdef IE_HANDLER
{
RECT R;
if (!lstrcmp(s,"Internet Explorer_Server")) {
style=WS_VSCROLL;
if (hitcode==HTCLIENT) {
GetClientRect(wnd,&R);
ClientToScreen(wnd,(LPPOINT)(&R.right));
if (mlhs->pt.x>R.right-GetSystemMetrics(SM_CXVSCROLL)) hitcode=HTVSCROLL;
}
}
}
#endif
msg=WM_VSCROLL;
pa=FALSE;
switch (hitcode) {
case HTCLIENT: {
if (style&(WS_VSCROLL|WS_HSCROLL)==WS_HSCROLL) msg=WM_HSCROLL;
}break;
case HTHSCROLL: {
msg=WM_HSCROLL;
}break;
case HTVSCROLL: {
pa=TRUE;
}break;
default: goto exi;
}
lpar=0;
if (style&(WS_HSCROLL|WS_VSCROLL)==0) {
lpar=(LPARAM)wnd;
tmp=wnd;
switch (CheckScrollBar(wnd)) {
case 1: msg=WM_HSCROLL; break;
case 2: pa=TRUE; break;
default: switch (Point_Finder(wnd,&tmp)) {
case 1: msg=WM_HSCROLL; break;
case 2: break;
default: switch (HasSiblingScrollBar(wnd,&tmp)) {
case 0: goto exi;
case 1: msg=WM_HSCROLL;
}
}
}
wnd=GetParent(tmp);
if (!wnd) goto exi;
}
if (pa) {
if (ScrollWidth<0) rol=-rol; // nur Vorzeichen
}else rol*=ScrollWidth; // Wert mit Vorzeichen
// MessageBeep(rol>0?MB_ICONEXCLAMATION:MB_OK);
wpar=SB_LINEUP; if (pa) wpar=SB_PAGEUP;
if (rol<0) {
wpar=SB_LINEDOWN; if (pa) wpar=SB_PAGEDOWN;
rol=-rol;
}
for(;rol>0;rol-=120) PostMessage(wnd,msg,wpar,lpar);
return 1;
exi:
return CallNextHookEx(g_hHook,code,wParam,lParam);
#undef mlhs
}
BOOL __stdcall _DllMainCRTStartup(
HINSTANCE hinstDLL, // handle to DLL module
DWORD fdwReason, // reason for calling function
LPVOID lpvReserved) { // reserved
switch (fdwReason) {
case DLL_PROCESS_ATTACH: {
DisableThreadLibraryCalls(hinstDLL);
if (!g_hHook) {
g_ScrollWidth=(int)GetProfileInt("Windows","MouseWheelScroll",2);
g_HookProcess=g_hHook=SetWindowsHookEx(WH_MOUSE_LL,
LowLevelMouseProc,hinstDLL,0);
if (!g_hHook) return FALSE; // vermutlich Win9x
}
}break;
case DLL_PROCESS_DETACH: {
if (g_HookProcess) UnhookWindowsHookEx(g_HookProcess);
}
}
return TRUE;
}
Vorgefundene Kodierung: ANSI (CP1252) | 4
|
|