to blp: 我的方法的确不太不好,但ljren_t(立志)应该没错看了下面这一段你就明白了 The SetCapture function sets the mouse capture to the specified window belonging to the current thread. Once a window has captured the mouse, all mouse input is directed to that window, regardless of whether the cursor is within the borders of that window. Only one window at a time can capture the mouse. from msdn
SetCapture VB声明 Declare Function SetCapture Lib "user32" Alias "SetCapture" (ByVal hwnd As Long) As Long 说明 将鼠标捕获设置到指定的窗口。在鼠标按钮按下的时候,这个窗口会为当前应用程序或整个系统接收所有鼠标输入 返回值 Long,之前拥有鼠标捕获的窗口的句柄 参数表 参数 类型及说明 hwnd Long,要接收所有鼠标输入的窗口的句柄 注解 我的理解:与ReleaseCapture函数一起使用,用于判断鼠标离开(mouseleave)事件
ReleaseCapture VB声明 Declare Function ReleaseCapture Lib "user32" Alias "ReleaseCapture" () As Long 说明 为当前的应用程序释放鼠标捕获 返回值 Long,TRUE(非零)表示成功,零表示失败 注解 我的理解:与SetCapture函数一起使用,用于判断鼠标离开(mouseleave)事件
SetCapture能够设置的窗口为USERCONTROL
我如何能够知道,控件外的鼠标点击呢
treeview1.visible=false
me.setfocus
但是当鼠标点击的位置在From或着没有焦点的控件上,
lostfocus事件并不会发生,
而这时,同样要求TREEVIEW消失
窗体点击事件中如果发现treeview的visible=true则令其不可见并置焦点到文本框
如果point不在usercontrol内不就是点在别的控件上了.
苯办法但管用 :)
假如点击事件发生在没有焦点的控件上,还有容器。一个窗体点击事件是不能满足的。
最主要的是,我这是个控件,这些代码要在控件中实行的。
我现在就是在控件中无法得到在控件以外的(窗体,无焦点的控件,..)的鼠标点击事件.
在usercontrol的mousedown事件里判断不就可以了,
如果point不在usercontrol内不就是点在别的控件上了. 既然point不在usercontrol内,又怎么会发生usercontrol的mousedown事件
我的方法的确不太不好,但ljren_t(立志)应该没错看了下面这一段你就明白了
The SetCapture function sets the mouse capture to the specified window belonging to the current thread. Once a window has captured the mouse, all mouse input is directed to that window, regardless of whether the cursor is within the borders of that window. Only one window at a time can capture the mouse.
from msdn
SetCapture函数在当前从属的线程中将鼠标捕获设置到指定的窗口。所有的鼠标输入都是在这个窗口上的,不管他是否在那个窗口内。是不是当我在控件中使用SetCapture(usercontrol.hwnd)后,我把这个控件放到FORM上,在FORM上单击鼠标后,会触发USERCONTROL_mousedown事件
能给我一个Sample吗,最好是在控件中使用。如果觉得分少,给你1000分都无所谓,只要问题能够解决
email:[email protected]
e_mail:[email protected]
Declare Function SetCapture Lib "user32" Alias "SetCapture" (ByVal hwnd As Long) As Long
说明
将鼠标捕获设置到指定的窗口。在鼠标按钮按下的时候,这个窗口会为当前应用程序或整个系统接收所有鼠标输入
返回值
Long,之前拥有鼠标捕获的窗口的句柄
参数表
参数 类型及说明
hwnd Long,要接收所有鼠标输入的窗口的句柄
注解
我的理解:与ReleaseCapture函数一起使用,用于判断鼠标离开(mouseleave)事件
ReleaseCapture VB声明
Declare Function ReleaseCapture Lib "user32" Alias "ReleaseCapture" () As Long
说明
为当前的应用程序释放鼠标捕获
返回值
Long,TRUE(非零)表示成功,零表示失败
注解
我的理解:与SetCapture函数一起使用,用于判断鼠标离开(mouseleave)事件
我认为这个其实应该是没有关系的,我不是要在程序中去做,
测试条件就是,我在窗体或容器上放一个那样的控件,再放些其他控件,程序一行代码都没有,
按下这个控件中的按纽,弹出TREEVIEW,点击鼠标(鼠标不在控件上),TREEVIEW消失。
所有的代码都应该在控件中。
“这是两个工程一个是控件,一个是测试.你看看吧,如有不明再说.”
[email protected]
[email protected]
[email protected]
下拉一个ListView。花一不少时日,尝试实现的一些方法,用过了SetCapture,
ReleaseCapture函数,但不是非常理想。由于在VB中,一个From的子窗体
(如TreeView、Picture、ListView控件)不可以放置在From之外(像Combo的下拉部分),
我于是决定用VC来实现,摸索了一段时间,进展不大。
如果你愿意,留个Email,方便以后一起探讨
[email protected]
这是我昨天中午敲打的文字。
使用SetCapture和ReleaseCapture可以处理鼠标事件,但是还应该考虑两个问题:
1、键盘事件。在以下几种情况下弹出窗口不能收回,如:按下Window的开始菜单快捷键,按下Alt+Tab键等;
2、弹出窗口的位置。放在UserControl里的TreeView是无法正常显示在Form里的,它的大小受到UserControl大小的限制。因此要把TreeView的hWnd的Parent设置为桌面hWnd,这又需要考虑许多问题,如坐标的转换、窗口在任务拦上的显示问题等等。
总之,要完全实现类似于Combo一样的功能,还有许多东西要做,欢迎大家多讨论!
说的不错,上面提到的这些我还都没解决,其实我觉得用VB做这样的控件不好.
1,底层API使用不方便.
2,体积庞大.
所以我一直在学VC,可能能解决这些问题.
email:[email protected]
多讨论.
Email:[email protected]
是用VB还是VC写的,能否发个源代码让我学习一下
[email protected]
[email protected]