KarlisB
asked on
Mouse wheel on dbgrid
Hi to solve scroll problem in dbgrid (delphi 7) I use:
procedure TForm1.ApplicationEvents1M essage(var Msg: tagMSG;
var Handled: Boolean);
var
i:smallint;
begin
if msg.message=WM_MOUSEWHEEL then
begin
msg.message:=WM_KEYDOWN;
msg.lParam:=0;
i:=hiword(msg.wParam);
if i>0 then
msg.wParam:=VK_UP
else
msg.wParam:=VK_DOWN;
handled:=false;
end;
end;
Thats solution is ok but I want, let that work only when mouse pointer is on dbgrid !!!
procedure TForm1.ApplicationEvents1M
var Handled: Boolean);
var
i:smallint;
begin
if msg.message=WM_MOUSEWHEEL then
begin
msg.message:=WM_KEYDOWN;
msg.lParam:=0;
i:=hiword(msg.wParam);
if i>0 then
msg.wParam:=VK_UP
else
msg.wParam:=VK_DOWN;
handled:=false;
end;
end;
Thats solution is ok but I want, let that work only when mouse pointer is on dbgrid !!!
ASKER
No not working for test I make :
c:= ControlAtPos(ClientToScree n(Mouse.Cu rsorPos), true, true);
if (c <> nil) and (c is TDBGrid) then
label1.Caption := 'YES dbgrid'
else
label1.Caption := 'NOT dbgrid';
and when I moving mouse cursor on my app he not only in DBGRID showing 'YES dbgrid' ok to better tell my prob I add screenshot
http://www.diana.lv/EE.jpg
up from dbgrid are comboboxs in conmobox default scrool work well!!! Maybe this solution were presing up or down buttons on scrolling is not the best, but I to test much of them from internet, but no one work good. Example: http://www.swissdelphicenter.ch/torry/showcode.php?id=2142
this is the best but hee work incorrectly, always when start scrooling first change always to move to inverse and then normal!!! maybe anybody have beter solution????
c:= ControlAtPos(ClientToScree
if (c <> nil) and (c is TDBGrid) then
label1.Caption := 'YES dbgrid'
else
label1.Caption := 'NOT dbgrid';
and when I moving mouse cursor on my app he not only in DBGRID showing 'YES dbgrid' ok to better tell my prob I add screenshot
http://www.diana.lv/EE.jpg
up from dbgrid are comboboxs in conmobox default scrool work well!!! Maybe this solution were presing up or down buttons on scrolling is not the best, but I to test much of them from internet, but no one work good. Example: http://www.swissdelphicenter.ch/torry/showcode.php?id=2142
this is the best but hee work incorrectly, always when start scrooling first change always to move to inverse and then normal!!! maybe anybody have beter solution????
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Just thought of something. The grid must also be on Form1 in order for this to work. The reason is that the ScreentoClient and ControlAtPos returns results specific to Form1. If the grid is on another form, we need some way to return results specific to that form. Will get back to you.
Change the following lines:
p:= ScreenToClient(msg.pt);
c:= ControlAtPos(p, true, true);
TO:
p:= Screen.ActiveForm.ScreenTo Client(msg .pt);
c:= Screen.ActiveForm.ControlA tPos(p, true, true);
p:= ScreenToClient(msg.pt);
c:= ControlAtPos(p, true, true);
TO:
p:= Screen.ActiveForm.ScreenTo
c:= Screen.ActiveForm.ControlA
ASKER
No don`t work I think the problemi is when I open combobox he is over dbgrid!!!!
another screenshot!!!
http://www.diana.lv/EE.jpg
another screenshot!!!
http://www.diana.lv/EE.jpg
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Now I'm confused. The example I gave you works fine when you are over the grid with the mouse pointer. Are you saying that when the combobox is expanded and it overlaps the grid, then it doesn't work? Surely that is how it should be? if the combo is open, then it should respond to mousewheel events, not the grid. Please clarify what you want.
If you want to scroll the grid even if the combobox dropdown overlaps it, then replace this:
Handled := false;
with this:
c.Perform(WM_KEYDOWN, Msg.wParam, 0);
Handled := true;
Handled := false;
with this:
c.Perform(WM_KEYDOWN, Msg.wParam, 0);
Handled := true;
Forced accept.
Computer101
EE Admin
Computer101
EE Admin
procedure TForm1.ApplicationEvents1M
var i:smallint;
c: TControl;
begin
if Msg.message = WM_MOUSEWHEEL then
begin
c:= ControlAtPos(ClientToScree
if (c <> nil) and (c is TDBGrid) then
begin
Msg.message := WM_KEYDOWN;
Msg.lParam := 0;
i := HiWord(Msg.wParam) ;
if (i > 0)
then Msg.wParam := VK_UP
else Msg.wParam := VK_DOWN;
Handled := False;
end
else Handled:= true;
end;
end;
Regards
Pierre