BCB6 DBGrid - can't catch WM_VSCROLL event

Hi, I'm trying to catch WM_VSCROLL event in DBGrid component of BCB6. It didn't fire CatchMessage. I'm using the following code :

void __fastcall TForm1::FormCreate(TObject *Sender)
{
  Application->OnMessage = AppMessage;
}



void __fastcall TForm1::CatchMessage(tagMSG &Msg, bool &Handled)
{
  if( Msg.message == WM_VSCROLL )
  {
   Handled = true;
  }
}

Open in new window



What is necessary to do to control vertical scrool bar of DBGrid?
Leo01010101Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

George TokasCommented:
Hi Leo, sorry for the delay...
I saw this question and your mail but I am recovering from flu these days and also don't have yet full access to the internet because of provider change...
I encountered the same problem and myself not only with BCB but also with .NET components, so it doesn't be a C++ Builder specific issue...
I am checking that and I will reply - I hope - later today...

Best Regards,
George.
0
George TokasCommented:
Based on: http://delphi.about.com/cs/adptips2002/a/bltip1102_3.htm
Drop an ApplicationEvents component in your form...
Somewhere in your code after the application show itself for the first time (meaning everything is initialized as needed) add:
ApplicationEvents1->Activate();
Double click applicationevents onMessage handler and add:
void __fastcall TForm1::ApplicationEvents1Message(tagMSG &Msg,
      bool &Handled)
{
        __int16 i;
        if(Msg.message == WM_MOUSEWHEEL)
        {
                Msg.message = WM_KEYDOWN;
                Msg.lParam = 0;
                i = HIWORD(Msg.wParam);
                if( i > 0)
                {
                        Msg.wParam = VK_UP;
                }
                else
                {
                        Msg.wParam = VK_DOWN;
                }

                Handled = False;
        }
}
//---------------------------------------------------------------------------
The above code changing wheel scroll behaviour to normal scroll...
VS is using that since version 2010 and if I'm not mistaken -previous versions suffered from the same "illness".

Best regards,
George.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Leo01010101Author Commented:
Hi George I made it as you described. I placed ApplicationEvents1->Activate(); in FormCreate Event.  I checked that ApplicationEvents1Message() didn't fire at all? What could be a reason? This ApplicationEvents component should be placed on a main form or on a form with DBGrid?
0
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

George TokasCommented:
FormCreate is called before form displayed...
That is why I am dropping a TTimer enabled by default and with an interval between 50-100ms...
When timer ticks means that (almost) everything (depending on threads used by you or the application itself) is initialized as needed and it is ready to go on...
This is a habit from the old C and linear programming days...
You can use this way and activate the appevents there... DON'T FORGET to disable the timer first of all, cause it will not be needed any more...
Try adding application events and in the form where the DBGrid is.
I tested it here in the same form not in multiform solution...
Even though it is named applicationevents maybe is limited on the form dropped...

George.
0
George TokasCommented:
Also:
When timer ticks means also that ALL FORMS initialized like the main one...
So you can access appevents on another form (to activate) like:
FormX->ApplicationEventsX->Activate();
If you have shared headers this will work...
If not the TTimer trick is working and there...

George.
0
Leo01010101Author Commented:
Yes, it's working. Now scrolling by using mouse wheel is OK, Thanks. Is it possible to solve scrolling DBGrid records by scroll bar without changing a selected record?

Best regards
Leo
0
George TokasCommented:
I am not sure about this...
Have to check it out though using Scroll() method...
As I saw the functionality you need is present with .NET DataGridView...
I am sure there is a way to do the same...
Both components are wrappers around a Win API component...

George.
0
George TokasCommented:
Also need to check it out using later versions of BCB...
Will try later today using XE4...

George.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.