Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 418953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:43:46+00:00 2026-05-12T18:43:46+00:00

As part of my Visual Studio utilities add-in SamTools , I have a mouse

  • 0

As part of my Visual Studio utilities add-in SamTools, I have a mouse input routine that catches Ctrl+MouseWheel and sends a pageup/pagedown command to the active text window. Visual Studio 2010 added a new “feature” that uses that gesture for zoom in/out (barf). Currently, my add-in does send the scrolling command, but Visual Studio still changes the font size because I’m not eating the input.

I set my hook with a call to SetWindowsHookEx. Here’s the callback code. My question is: is the best way to prevent Visual Studio from handling the Ctrl+MouseWheel input as a zoom command to simply not call CallNextHookEx when I get a mouse wheel event with the Ctrl key down?

(Please bear in mind this is some old code of mine.) 🙂

private IntPtr MouseCallback(int code, UIntPtr wParam, ref MOUSEHOOKSTRUCTEX lParam)
{
    try
    {
        // the callback runs twice for each action - this is the latch
        if (enterHook)
        {
            enterHook = false;
            if (code >= 0)
            {
                int x = lParam.mstruct.pt.X;
                int y = lParam.mstruct.pt.Y;

                uint action = wParam.ToUInt32();
                switch (action)
                {
                case WM_MOUSEWHEEL:
                    OnMouseWheel(new MouseEventArgs(MouseButtons.None, 0, x, y, ((short)HIWORD(lParam.mouseData)) / (int)WHEEL_DELTA));
                    break;

                default:
                    // don't do anything special
                    break;
                }
            }
        }
        else
        {
            enterHook = true;
        }
    }
    catch
    {
        // can't let an exception get through or VS will crash
    }

    return CallNextHookEx(mouseHandle, code, wParam, ref lParam);
}

And here’s the code that executes in response to the MouseWheel event:

void mouse_enhancer_MouseWheel( object sender, System.Windows.Forms.MouseEventArgs e )
{
    try
    {
        if ( Keyboard.GetKeyState( System.Windows.Forms.Keys.ControlKey ).IsDown && Connect.ApplicationObject.ActiveWindow.Type == vsWindowType.vsWindowTypeDocument )
        {
            int clicks = e.Delta;
            if (e.Delta < 0)
            {
                Connect.ApplicationObject.ExecuteCommand( "Edit.ScrollPageDown", "" );
            }
            else
            {
                Connect.ApplicationObject.ExecuteCommand( "Edit.ScrollPageUp", "" );
            }
        }
    }
    catch ( System.Runtime.InteropServices.COMException )
    {
        // this occurs if ctrl+wheel is activated on a drop-down list. just ignore it.
    }
}

PS: SamTools is open source (GPL) – you can download it from the link and the source is in the installer.

PSS: Ctrl+[+] and Ctrl+[-] are better for zooming. Let Ctrl+MouseWheel scroll (the vastly more commonly used command).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T18:43:47+00:00Added an answer on May 12, 2026 at 6:43 pm

    According to MSDN, it’s possible to toss mouse messages that you process. Here’s the recommendation:

    If nCode is less than zero, the hook
    procedure must return the value
    returned by CallNextHookEx.

    If nCode is greater than or equal to
    zero, and the hook procedure did not
    process the message, it is highly
    recommended that you call
    CallNextHookEx and return the value it
    returns; otherwise, other applications
    that have installed WH_MOUSE hooks
    will not receive hook notifications
    and may behave incorrectly as a
    result. If the hook procedure
    processed the message, it may return a
    nonzero value to prevent the system
    from passing the message to the target
    window procedure.

    In other words, if your mouse callback ends up using the mouse message, you don’t have to call the next CallNextHookEx — just return a nonzero value and (in theory, at least) the mouse movement should get swallowed. If that doesn’t work the way you want, comment and we can iterate.

    BTW, another possible alternative: it’s possible that VS’s mapping to the mouse wheel shows up in the Tools…Customize… UI, just like key mappings do. In that case, you could simply remap your add-in’s commands instead of working at the hook level. But it’s also posible (likely?) that this gesture is hard-coded.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database project (.dbp) open in Visual Studio 2008 as part of
I developped a package to extend Visual Studio. As part of it, I have
I just installed Visual Studio 2010 yesterday. As part of that I installed VSTO
I have a SharePoint WebPart project in visual studio. As part of the project
As part of our Visual Studio 2010 (primarly C# 4.0) development standards, we have
I writing a report in Visual Studio that takes a user input parameter and
I have built a custom web part using Visual Studio. Is it possible to
I have a web part in visual studio. The web part will contain 3
I have a web application solution existing under Visual Studio 2010. Part of this
In Visual Studio (C#) I have a form created as part of a project

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.