Board index » delphi » onmousedown event delphi error in treeview?

onmousedown event delphi error in treeview?

i have put some code in a treview.onmousedown event.
procedure Tform1.TreeView1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
if button=mbright then
 do something (set caption for testing)

It didnt worked properly becouse code executes after
i let the mouse not in the moment i press the rigth button but thats on my
opinion onmouseup event.

Interesting thing is that procedure works fine if i am testing mbleft click.

Ok i said it is something wrong with delphi.

I tried with
 procedure mymousehandler(var Message: TWMRBUTTONDOWN); message
WM_RBUTTONDOWN;

it captures the mouse click at the moment when it is pressed but
only when it is clicked on a form. it doesnt work above a treeview. Also if
it would worked how could i see if it was clicked over the treview.

if someone knows solution of the first (error) or the second alternative
please let me know

thanks a lot

T...@homemail.com

 

Re:onmousedown event delphi error in treeview?


ok i ve got the answer on my own.
i needed a lot of time several hours to write the answer properly
so i hope if someone will stuck because of it i hope this will help him
i didnt use any of delphi onmouse down events for right mouse click(it seems
that something is wrong with it)  just a message from
windows. now when i click with a right mouse on a node it gets
focus and that rectangle that was bothering me because it stayed
on a old node until i let the right mouse button go. That s why i needed
to know how could i write a code that would execute at the moment
when i would click the right mouse button on a treeview.

you must include shellapi and assign a procedure to a
application.onmessage event when the form is created.

procedure Tmain.HandleMessage (var Msg: TMsg; var Handled: Boolean);
var point: longint;
    node : ttreenode;
begin
if (msg.message=WM_RBUTTONDOWN) and (msg.hwnd=treeview1.handle) then
 begin
  point :=msg.lParam;
  node  :=treeview1.GetNodeAt(LOWORD(point), point shr 16);

  if not (node=nil) then
   treeview1.selected:=node;

 end;
end;

Other Threads