Let Delphi DBGrid support the mouse wheel

Source: Internet
Author: User

Most of the mouse now has a mouse wheel, for example, when we browse the Web page, the mouse wheel move up and down, the page will automatically scroll up and down. The mouse wheel does bring a lot of convenience to our operation, but in most of Delphi control only support Mousedown,mouseup,mousemove events, and not directly support MouseWheel events, We have this problem when we help customers design a viewing program. This viewer data is placed in a DBGrid, the data is more than the entire screen, if you move up and down with the mouse wheel, the DBGrid cursor only in the visible range of movement, beyond the screen data must use the keyboard or the right scroll bar, causing great inconvenience to users, The customer strongly requests support for mouse wheel operation. But what about viewing the DBGrid event properties without support for the mouse wheel?

We know that the Windows operating system is message driven, so if the mouse wheel scrolling up and down, there must be a corresponding event, after looking for information, we learned that when the mouse wheel scrolling up and down occurs is the WM_MouseWheel event, so if we capture this event, Can you handle the mouse wheel event?

Just do it, so let's add a OnMouseWheel event for DBGrid and create a new DBGrid component that supports the mouse wheel.

Let's create a new application, call Mydbgrid bar, select Menu File-new Application, and then select Menu File-new-component

Because our new component is inherited from DBGrid, Ancestor type chooses Tdbgrid,class name to fill in our component names Tmydbgrid, the resulting component is placed on the Samples page, and the component's frame is generated when you click OK.

Now we start to do the most critical part. When the mouse wheel scrolls up and down, a WM_MOUSEWHEEL message is sent, MouseWheel message has several parameters,

1.fwkeys= LoWord (WParam), which indicates whether various virtual keys are pressed, has the following values:

Value Description
Mk_control Press the CTRL key
Mk_lbutton Press the left mouse button
Mk_mbutton Press the middle mouse button
Mk_rbutton Press the right mouse button
Mk_shift Press the SHIFT key

2.zDelta = (short) hiword (WParam)

The distance the mouse wheel scrolls, if forward is positive, and backward is negative.

3. Xpos = (short) loword (LParam)

ypos= (short) hiword (LParam)

The position of the mouse.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.