diff options
| -rw-r--r-- | mousew16.c | 92 |
1 files changed, 85 insertions, 7 deletions
@@ -29,6 +29,8 @@ /** Whether to enable wheel mouse handling. */ #define USE_WHEEL 1 +/** Also send the native win32 messages (aka MSH_MOUSEWHEEL) for wheel. */ +#define USE_WHEEL32 0 /** If win386 is available, hook int2f to detect DOS/Windows screen switches * and reconfigure the int33 driver. */ #define USE_WIN386 1 @@ -67,6 +69,17 @@ static short prev_delta_x, prev_delta_y; /** Maximum X and Y coordinates expected from the int33 driver. */ static unsigned short max_x, max_y; #if USE_WHEEL +# if USE_WHEEL32 + /** Win95's 32-bit MSG struct, exposed via *32 functions in USER(16). */ + typedef struct MSG32 { + MSG; + WORD wParamHigh; + } MSG32; + /** "Native" wheel mouse message, either MSH_MOUSEWHEEL or WM_MOUSEWHEEL */ + static UINT wheel_msg_ms; + /** "Native" horizontal wheel message, usually WM_MOUSEHWHEEL */ + static UINT wheel_msg_ms_horz; +# endif /** Some delay-loaded functions from USER.EXE to provide wheel mouse events. */ static struct { /** Handle to the USER module itself. */ @@ -84,6 +97,9 @@ static struct { HOOKPROC WINAPI (*SetWindowsHook)( int, HOOKPROC ); BOOL WINAPI (*UnhookWindowsHook)( int, HOOKPROC ); HWND WINAPI (*WindowFromPoint)( POINT ); +# if USE_WHEEL32 + LONG WINAPI (*DispatchMessage32)( MSG32 FAR *, BOOL ); +# endif } userapi; /** This is the private message that we send on wheel movement and is * going to be intercepted by the hook, which will translate into scroll msgs. */ @@ -295,6 +311,64 @@ static void post_simulated_scroll_msgs(POINT cursor, int z, BOOL horizontal) #endif } +static BOOL send_native_wheel_msgs(HWND hWnd, DWORD time, POINT cursor, int z, BOOL horizontal) +{ +#if USE_WHEEL32 + MSG32 msg; + LRESULT result; + + // We really need 32-bit DispatchMessage here. + // Both native wheel messages use the hiword of wParam, + // but on 16-bit Windows, wParam is 16-bit! + // Using undocumented USER16's DispatchMessage32 allows us to specify + // the high part of wParam without having to thunk into USER32 + + if (!userapi.DispatchMessage32) { +#if TRACE_WHEEL + dprintf(DPREFIX "%s: no win32\n", __func__); +#endif + return FALSE; + } + + // Use corresponding message type + msg.hwnd = hWnd; + msg.message = horizontal ? wheel_msg_ms_horz : wheel_msg_ms; + + if (!msg.message) { +#if TRACE_WHEEL + dprintf(DPREFIX "%s: no native msg for %s wheel\n", __func__, horizontal ? "horz" : "ver"); +#endif + return FALSE; + } + + // Put the sign-extended z argument in wParam + z = -120 * z; // aka WHEEL_DELTA + msg.wParam = z; + msg.wParamHigh = z < 0 ? -1 : 0; // don't think we need full 32-bit arithmetic here + + // And fill in the rest of the MSG as normal + msg.lParam = MAKELPARAM(cursor.x, cursor.y); + msg.time = time; + msg.pt = cursor; + + result = userapi.DispatchMessage32(&msg, TRUE /* we want 32-bit MSG */); + +#if TRACE_WHEEL + if (result) { + dprintf(DPREFIX "%s: replied to native msg with %d, skip scrolling\n", __func__, result); + } else { + dprintf(DPREFIX "%s: didn't reply to native msg\n", __func__); + } +#endif + + return result; +#else + // No native messages in win16 + (void) hWnd; (void) time; (void) cursor; (void) z; (void) horizontal; + return FALSE; +#endif /* USE_WHEEL32 */ +} + /** GetMsgProc hook, called for every message before being returned by GetMessage. */ LRESULT CALLBACK WheelHookProc(int code, WPARAM wParam, LPARAM lParam) { @@ -306,13 +380,11 @@ LRESULT CALLBACK WheelHookProc(int code, WPARAM wParam, LPARAM lParam) BOOL horizontal = msg->wParam; int z = msg->lParam; - // TODO In theory we could try sending "native" MSH_MOUSEWHEEL msg here - // which some early nt/95 software supports (in addition to 98's WM_MOUSEWHEEL) - // but I think the fake scroll messages work well enough. - // To properly send MSH_MOUSEWHEEL, we'd need to thunk into 32-bit - // SendMessage because such win95 software will expect 32-bit WPARAM. - - post_simulated_scroll_msgs(msg->pt, z, horizontal); + // Try to send the native messages first + if (!send_native_wheel_msgs(msg->hwnd, msg->time, msg->pt, z, horizontal)) { + // But if they're not intercepted, do the simulated scrolling + post_simulated_scroll_msgs(msg->pt, z, horizontal); + } // Prevent us from intercepting this message if fwd'd msg->message = WM_NULL; @@ -599,6 +671,12 @@ VOID FAR PASCAL Enable(LPFN_MOUSEEVENT lpEventProc) wheel_msg_private = userapi.RegisterWindowMessage("VBMOUSE_WHEEL"); +#if USE_WHEEL32 + userapi.DispatchMessage32 = (LPVOID) GetProcAddress(userapi.hUser, "DispatchMessage32"); + wheel_msg_ms = userapi.RegisterWindowMessage("MSWHEEL_ROLLMSG"); + wheel_msg_ms_horz = 0; // TODO +#endif + wheel_hook_proc_next = userapi.SetWindowsHook(WH_GETMESSAGE, (HOOKPROC)WheelHookProc); } #endif |
