获取 NumericUpDown 编辑部分的句柄
NumericUpDown
有 2 个句柄/控件:外部旋转框和内部类似编辑文本框的控件。
我需要获取内部文本框控件的句柄。 NumericUpDown.Handle
给出外部句柄。
我在 Google 上找到的最接近的内容是此论坛对话。诀窍是使用 UDM_GETBUDDY = WM_USER+106 = 0x0400+106
消息,该消息返回好友窗口的句柄,在我们的例子中是文本编辑。
最初的输出是这样的:
control.Capture = true;
IntPtr outer = User32.GetCapture();
IntPtr inner = new IntPtr(User32.SendMessage(outer, (0x0400 + 106), 0, 0));
但后来OP说这不起作用,所以有人建议使用GetWindow(outer, GW_CHILD)
。其中 GW_CHILD = 5
control.Capture = true;
IntPtr outer = User32.GetCapture();
IntPtr inner = User32.GetWindow(outer, 5);
对于这两种方法,我总是得到 inner = 0
,这显然不是正确的答案。然而,OP说方法2似乎有效,所以我可能做错了什么。
顺便说一句,“捕获”机制似乎没什么用,因为我可以简单地使用:
IntPtr outer = control.Handle;
返回相同的值。
那么,关于如何获取内部文本框句柄有什么想法吗?
A NumericUpDown
has 2 handles/controls: the outer spinbox, and the inner edit textbox-like control.
I need to get the handle of the inner textbox control. NumericUpDown.Handle
gives the outer handle.
The closest I found on Google to that is this this forum conversation. The trick is to use the UDM_GETBUDDY = WM_USER+106 = 0x0400+106
message which returns the handle of the buddy window, in our case the text edit.
The output was something like this at first:
control.Capture = true;
IntPtr outer = User32.GetCapture();
IntPtr inner = new IntPtr(User32.SendMessage(outer, (0x0400 + 106), 0, 0));
But then the OP said this wasn't working, so someone suggested to use GetWindow(outer, GW_CHILD)
. where GW_CHILD = 5
control.Capture = true;
IntPtr outer = User32.GetCapture();
IntPtr inner = User32.GetWindow(outer, 5);
For both of these methods, I always end up with inner = 0
, which is obviously not the right answer. However, OP stated method 2 seemed to work, so I might be doing something wrong.
By the way, the "capture" mechanic seems to be useless, as I can simply use:
IntPtr outer = control.Handle;
Which returns the same.
So, any ideas on how to get the inner textbox handle?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它在Winforms中的实现方式非常不同,没有伙伴控制。获取对文本框部分的引用很容易做到,尽管它违反了一些封装规则。这并不是什么问题,NumericUpDown 会及时冻结并且永远不会改变。
戳该 TextBox 控件的属性时要小心,并非所有事件都已实现。
It is implemented very differently in Winforms, no buddy control. Getting a reference to the text box portion is easy to do, although it violates several encapsulation rules. Not really a problem, NumericUpDown is frozen in time and will never change.
Be careful with poking properties for that TextBox control, not all of its events are implemented.