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.