Hello,I'm trying to redirect mouse wheel message to controls in order to allow scroll without clicking on them (You just need to move mouse on control that you want to scroll).It works good with TcxRichEdit but I'm encountering some problems with TcxGrid.
I've attached a complete sample that you can test. There's also an image inside zip archive with all you need to do in order to recreate the issue (step by step).Furthermore, sample project contains a "debug TcxRichEdit" where you can send messages by using "DebugMessage" method.Please ask if you need other informations.Thanks to everyone.
How to redirect mouse wheel message to a cxGrid
Answers approved by DevExpress Support
Hello,
I believe a similar question has been already discussed in our Support Center. Please refer to the Q276698: How to scroll unbound cxGrid with mousewheel when grid is unfocused ticket for the information.
Hello Poul,
To process your recent post more efficiently, I created a separate ticket on your behalf: T195976: How to redirect mouse wheel message to a cxGrid with VCL 14.2. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.
Here's how I solved this problem. I dropped an ApplicationEvents control on my main form and then hooked the OnMessage event as follows:
Delphiprocedure TMainForm.ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean);
var
mousePos : TPoint;
wc : TWinControl;
AGridSite : TCxGridSite;
begin
//mouse wheel scrolling for the control under the mouse
if Msg.Message = WM_MOUSEWHEEL then
begin
mousePos.x := Word(Msg.LParam);
mousePos.y := HiWord(Msg.LParam);
wc := FindVCLWindow(mousePos);
if wc = nil then
begin
Handled := False;
end
else
if wc is TCxGridSite then
begin
AGridSite := wc as TCxGridSite;
if (AGridSite.GridView.ClassType = TcxGridDBTableView) or
(AGridSite.GridView.ClassType = TcxGridTableView) then
begin
if Msg.WParam > 0 then
AGridSite.GridView.Site.ScrollContent(dirUp)
else
AGridSite.GridView.Site.ScrollContent(dirDown);
Handled := true;
end
end
else
begin
if wc.handle <> Msg.hwnd then
begin
SendMessage(wc.handle, WM_MOUSEWHEEL, Msg.WParam, Msg.LParam);
Handled := true;
end;
end;
end;
end;
This allows my unfocused cxGrid and cxDBGrids to scroll when the mouse is over them.
YMMV.
I should have noted that I'm using Delphi XE and 14.2.2 and this has worked with all releases of DevExpress.