Home All Groups Group Topic Archive Search About

SendMessage mouse click to treeview node

Author
24 Nov 2007 2:47 PM
R.A.F.
Hi,

I would like simulate a mouse click on on of my treeview nodes when my
form opens.

for that i was thinking to use the same simple way as under C++ :
SendMessage(TreeView.Nodes[0].Handle, WM_LBUTTONDOWN,0,0);

but it does not work. i do not get any error message and application
runs normally... just my first node is not selected (clicked).

i want to do that because like that, another childform will be selected
based on my treeview node clicked.

thanks a lot,

RAF

Author
24 Nov 2007 4:22 PM
Nicholas Paldino [.NET/C# MVP]
RAF,

    SendMessage is not the way to simulate a mouse click.  It only sends the
message to the control.  A mouse click involves a hardware interrupt,
followed by the OS sending a number of messages to the target window, not
just one button down message.

    In order to send a click to the tree view, you should find the position
of the node you want to send the mouse click to, and then call the SendInput
API function through the P/Invoke layer.


--
          - Nicholas Paldino [.NET/C# MVP]
          - mvp@spam.guard.caspershouse.com

Show quote
"R.A.F." <noemail@nospam.com> wrote in message
news:uh4v3jqLIHA.4476@TK2MSFTNGP06.phx.gbl...
> Hi,
>
> I would like simulate a mouse click on on of my treeview nodes when my
> form opens.
>
> for that i was thinking to use the same simple way as under C++ :
> SendMessage(TreeView.Nodes[0].Handle, WM_LBUTTONDOWN,0,0);
>
> but it does not work. i do not get any error message and application runs
> normally... just my first node is not selected (clicked).
>
> i want to do that because like that, another childform will be selected
> based on my treeview node clicked.
>
> thanks a lot,
>
> RAF
Author
24 Nov 2007 4:42 PM
Kerem Gümrükcü
>In order to send a click to the tree view, you should find the position of
>the node you want to send the mouse click to, and then call the SendInput
>API function through the P/Invoke layer.

Yes, i agree,...would be the best solution for this!

Regards

Kerem

--
-----------------------
Beste Grüsse / Best regards / Votre bien devoue
Kerem Gümrükcü
Microsoft Live Space: http://kerem-g.spaces.live.com/
Latest Open-Source Projects: http://entwicklung.junetz.de
-----------------------
"This reply is provided as is, without warranty express or implied."
Author
24 Nov 2007 7:07 PM
R.A.F.
Sorry Nicholas but i did not find anything in VS2008 help about
SendInput API.

By the way, why do you not support the SendMessage method for such topic ?

I finally adapt it from C++ to C# and it works great :-)

RAF

Nicholas Paldino [.NET/C# MVP] wrote:
Show quote
> RAF,
>
>    SendMessage is not the way to simulate a mouse click.  It only sends
> the message to the control.  A mouse click involves a hardware
> interrupt, followed by the OS sending a number of messages to the target
> window, not just one button down message.
>
>    In order to send a click to the tree view, you should find the
> position of the node you want to send the mouse click to, and then call
> the SendInput API function through the P/Invoke layer.
>
>
Author
24 Nov 2007 7:34 PM
Nicholas Paldino [.NET/C# MVP]
RAF,

    Here is a link to the documentation for SendInput:

http://msdn2.microsoft.com/en-us/library/ms646310.aspx

    The reason I don't like calling SendMessage in this case is that you are
only sending the left mouse button down message.  However, a true mouse
click consists of a click event, as well as a mouse down and a mouse up
event and possibly more.  The control is also free to respond to any of
these messages as it sees fit.

    It just so happens that sending the message is doing what you want, but
it isn't the same as sending a mouse click.

--
          - Nicholas Paldino [.NET/C# MVP]
          - mvp@spam.guard.caspershouse.com

Show quote
"R.A.F." <noemail@nospam.com> wrote in message
news:OYxx%230sLIHA.1212@TK2MSFTNGP05.phx.gbl...
> Sorry Nicholas but i did not find anything in VS2008 help about SendInput
> API.
>
> By the way, why do you not support the SendMessage method for such topic ?
>
> I finally adapt it from C++ to C# and it works great :-)
>
> RAF
>
> Nicholas Paldino [.NET/C# MVP] wrote:
>> RAF,
>>
>>    SendMessage is not the way to simulate a mouse click.  It only sends
>> the message to the control.  A mouse click involves a hardware interrupt,
>> followed by the OS sending a number of messages to the target window, not
>> just one button down message.
>>
>>    In order to send a click to the tree view, you should find the
>> position of the node you want to send the mouse click to, and then call
>> the SendInput API function through the P/Invoke layer.
>>
Author
26 Nov 2007 11:53 AM
KWienhold
Show quote
On 24 Nov., 15:47, "R.A.F." <noem...@nospam.com> wrote:
> Hi,
>
> I would like simulate a mouse click on on of my treeview nodes when my
> form opens.
>
> for that i was thinking to use the same simple way as under C++ :
> SendMessage(TreeView.Nodes[0].Handle, WM_LBUTTONDOWN,0,0);
>
> but it does not work. i do not get any error message and application
> runs normally... just my first node is not selected (clicked).
>
> i want to do that because like that, another childform will be selected
> based on my treeview node clicked.
>
> thanks a lot,
>
> RAF

Maybe I'm missing something here, but if you want to make sure that
that a specific node is selected when your form opens, why not simply
set the SelectedNode property of the tree?
Since the most common way to use a tree for navigation is to handle
the AfterSelect event, this should result in the same behavior as
actually clicking on the node.

hth,
Kevin Wienhold

AddThis Social Bookmark Button