|
ms
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
SendMessage mouse click to treeview nodeHi,
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 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. -- Show quote- Nicholas Paldino [.NET/C# MVP] - mvp@spam.guard.caspershouse.com "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 >In order to send a click to the tree view, you should find the position of Yes, i agree,...would be the best solution for this!>the node you want to send the mouse click to, and then call the SendInput >API function through the P/Invoke layer. 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." 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. > > 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. -- Show quote- Nicholas Paldino [.NET/C# MVP] - mvp@spam.guard.caspershouse.com "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. >>
Show quote
On 24 Nov., 15:47, "R.A.F." <noem...@nospam.com> wrote: Maybe I'm missing something here, but if you want to make sure that> 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 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 |
|||||||||||||||||||||||