Link to home
Start Free TrialLog in
Avatar of BdLm
BdLmFlag for Germany

asked on

MouseWhell Event in Class TFrame

My class is a decendant of TFrame, I want to use the Mouse wheel event,
actually this code does not work ... I found it on EE.

do I have to assign the MouseWhell event to my functions ?
function TClientFrame.DoMouseWheelDown(Shift: TShiftState; MousePos: TPoint): Boolean;
begin
    inherited DoMouseWheelDown(Shift, MousePos);
    Result := False;
    // My code here for own action...
    DisplayText(7, 'WheelDown');
end;
 
function TClientFrame.DoMouseWheelUp(Shift: TShiftState; MousePos: TPoint): Boolean;
begin
    inherited DoMouseWheelUp(Shift, MousePos);
    Result := False;
    // My code here for own action...
    DisplayText(7, 'WheelUp');
end ;

Open in new window

SOLUTION
Avatar of BigRat
BigRat
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BdLm

ASKER

what line of code i should add to the constructor ?


constructor TClientFrame.create;
begin
     inherited create;

     OnMouseWheelDown :=

end;
SOLUTION
Avatar of Geert G
Geert G
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
constructor TClientFrame.create;
begin
     inherited create;

     OnMouseWheelDown :=DoMouseWheelDown;

end;
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ok, but they don't get called ... even if you assign them
neither does the MouseWheelHandler procedure
What version of Delphi are you using?

I have just put a handler in my test app (derived from TForm) and displayed a message, left the handling to the TMemo's scrolling and everything worked OK. My Delphi is 5 Standard.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hey BigRat,
you grasped my solution,
but I see looking at your solution, i missed out something

I added a Listbox and Memo and they aren't scrolling
I'm trying to solve this your way,
maybe we can end up with a combined solution ...

PS: Delphi 7 Architect, for this problem
Avatar of BdLm

ASKER

hi,

in my frame there are scrollbars at the edge and a paintbox in the center of the frame, covering almost the complete area,
the frame has mouse wheel events but the paintbox does not have one.
frame ??

best
Geert: I don't understand your problem. Both TListBox and TMemo are wrappers for the underlying Windows objects, who both have a hidden ScrollBar object associated with them. These are MouseWheel enabled, that is if a MouseWheel message arrives they send it to the Scoller if it is enabled. What you might have done is to have set Handled to true (I have in my test explicitly set it to false) in which case the subclassing in TWinControl won't send the message to the undelying Windows object.
Avatar of BdLm

ASKER

what about my paintbox .....   .-)
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
the paintbox indeed doesn't have these events as it is a graphic control

what do you want to happen with the paintbox ?
and how do the scrollbars interact with the paintbox ?
are these scrollbars part of a TScrollbox ?

Avatar of BdLm

ASKER

I put that code to my class, but no mouse wheel event has been triggert....

In this Frame I have scrolllbars to move my image in the paintbox, with the mouse wheel I want to realize a Image zoom function like eg. in PaintShop used......

Furthermore I put menue on this Frame and a Status Bar to allow the user to start a lot of image proceesing functions .....


procedure TClientFrame.FrameMouseWheel(Sender: TObject;
  Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint;
  var Handled: Boolean);
begin
    DisplayText(7, 'Wheel...');
end;
 
procedure TClientFrame.FrameMouseWheelDown(Sender: TObject;
  Shift: TShiftState; MousePos: TPoint; var Handled: Boolean);
begin
   DisplayText(7, 'Wheeldown');
end;
 
procedure TClientFrame.FrameMouseWheelUp(Sender: TObject;
  Shift: TShiftState; MousePos: TPoint; var Handled: Boolean);
begin
   DisplayText(7, 'Wheelup');
end;

Open in new window

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
oh yeah, you can draw lines in the paintbox too :)
Avatar of BdLm

ASKER

thanks a lot,
---------------------------------------------------------------------------------------
your code procedure TFrame2.MouseWheelHandler(var Msg: TMessage);
my code :  procedure TClientFrame.FrameMouseWheelDown(Sender: TObject;
  Shift: TShiftState; MousePos: TPoint; var Handled: Boolean);
----------------------------------------------------------------------------------------

I need a bit Time to think on your solution, how  to transfer it to my class.
Geert: Handling the mouse wheel message directly, instead of letting TWinControl do it (where it makes this decision about Form or Frame), is basically a good idea. It would howver be better to call the appropiate properties of the objects under the mouse position instead of explicitly testing against known objects.  

Furthermore the TWMMouseWheel structure does not exist in my Delphi 5, so I doubt it will be in Delphi 4.
However it looks like this :-

type
  TWMMouseWheel = RECORD
     Msg: Cardinal;
     fwKeys : WORD;
     zDelta : Smallint;
     CASE Integer OF
     0: (xPos: Smallint; yPos: Smallint);
     1: (ptPos: TSmallPoint; Result: Longint);
  END;
 
Avatar of BdLm

ASKER

The object TFrame has a Mousewheel property/event.
If I generate the code see   procedure TClientFrame.FrameMouseWheel  .....  above,
this code in the class is not called.
The PaintBox is ontop,  algn:=atClient of the Frame Surface , the Mouseclicks are taken from the PaintBox for several actions,
but where can I get the Mousewheel move most easily
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BdLm

ASKER

do I have to add code:

TMyPainBox = class(TPaintBox)
 
  property OnMouseWheelDown .....  
end;


Avatar of BdLm

ASKER

BTW:  I do not use a scrollbox .....
it was just a test for BigRat,
in my comment #22678176 i was trying to explain what i see as your problem :)
you mentioned scrollbars , so i assumed they were of a scrollbox in which you had put the paintbox

are these scrollbars of the Frame ?
In my TPaintBox (Delphi 5) there are no such events. Note that PaintBox is inherited from TControl and NOT TWinControl, which is the one that causes all the problems.

BdLm: The only way to do it is as Geert first suggested. Your going to have to catch the mouse wheel in the Form, and look for the control under the mouse. If it's your frame you call the handler there.
Avatar of BdLm

ASKER

I actually I only use scrollbars (position is used to calc. the image size, viewport, .......)
Avatar of BdLm

ASKER

@bigrat:  why do I have to take the event from the underlying form and can not use the
               event in the frame? I found this one  :-(
   
               why do I have to look for the sending control, can I not directly assign
               in the underlying Mousewheelfunction the Mousewheelfct of the frame?

@geert: I use the frame like a componet on serval forms, your solution means I have to add this code to every form.  

BdLm: 1) the event does not appear in the Frame. It must be caught in the Form and applied to the Frame (if you want it there) or to the corresponding object.
    2) If one has, say, two panels on the frame to which panel should the mouse wheel apply?

Geert had provided a general solution to the problem. You can of course call the handler in the Frame if you want.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
my 2.3 cents

I inherit all my forms from my own created form class
If i need to add functionality to *ALL* in *ALL* applications
this is just a 1 time job and recompile all apps :)

Once you get used to Form inheritance, you can't live without it  :-)
 
the drawback offcourse.
If you program 1 bug in the base class, you get it all over for free :-(
Avatar of BdLm

ASKER

--> Once you get used to Form inheritance, you can't live without it  :-)

did this not slow down your applications as you install functions you do not need all the time ?
Well i have a few types of form classes ...
Depending on what type of form i need
Avatar of BdLm

ASKER

I did not tell my form is a midchild ........,
 do I have to piut the MouseWheelHandler
in the midparent, pass the msg to the mdichild and then to the frame inside the mdichipd .....
i don't think it should matter

if you get a event in the mdichild form for the mousewheel then it's the same
as for normal forms

if not let me know and i'll look into it
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BdLm

ASKER

Hi,

i can get the mouse wheel in a Form meanwhile by several methodes   :-)
I made some short demo code.

I my large application MDI I failed to run any of the solutions above,
it is my turn to find the root cause.
I#ll accept your both support once I solved my task,
 If I 'll find something I#ll put it here, thanks for your help so far.

Habe a nice week end

Best
Bdlm
Avatar of BdLm

ASKER

lot of good code work done :-)