Using subclass technology to increase mouse scrolling for DBGrid

Source: Internet
Author: User

Author: Yifei (Yunga Jun)

Mailbox: yifei1900@163.com

For DBGrid, add the mouse scrolling function to the demo, the core code is as follows:

//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "MainFormUnit.h"
//---------------------------------------------------------------------------
#pragma package (smart_init)
#pragma resource "*.DFM"
Tmainform *mainform;
//---------------------------------------------------------------------------
Farproc Oldproc = NULL; WindowProc for saving the old DBGrid control
//---------------------------------------------------------------------------
/**
* Declaration of the new DBGrid WindowProc
*/
Lresult CALLBACK Dbgridproc (HWND hwnd,uint umsg,wparam Wparam,lparam)
{
Processing window Messages of interest
if (umsg = = WM_MouseWheel) {
if (short) HiWord (WParam) > 0) {
::P ostmessage (hwnd,wm_vscroll,sb_lineup,0);
} else {
::P ostmessage (hwnd,wm_vscroll,sb_linedown,0);
}
}
Call the original DBGrid WindowProc
Return (:: CallWindowProc (Oldproc,hwnd,umsg,wparam,lparam));
}
//---------------------------------------------------------------------------
__fastcall tmainform::tmainform (tcomponent* Owner)
: Tform (Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall tmainform::formshow (tobject *sender)
{
this->adocn->connectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data source="
+ Extractfilepath (application->exename) + "Data.mdb"; Persist security Info=true ";
This->adocn->connected = true;
This->dataset->open ();
Set up a new form function
Oldproc = (FARPROC):: SetWindowLong (This->dbgrid->handle,gwl_wndproc, (long) dbgridproc);
}
//---------------------------------------------------------------------------
void __fastcall Tmainform::formclose (tobject *sender, tcloseaction &action)
{
Restore form functions
:: SetWindowLong (This->dbgrid->handle,gwl_wndproc, (long) oldproc);
this->adocn->connected = false;
}
//---------------------------------------------------------------------------

Today happened to see the 2CCC site has to DBGrid to increase the scrolling function of the code, think of this function is really very practical (but their demo code is really not good, not a little practical), and search the network found only Delphi and VB examples, so I wrote a copy of the BCB code , there is no way to use the demo code on the network, using a more practical method.

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.