我要截获Form的MouseEnter和MouseLeave消息,但窗体上的每个控件的这个消息都被截获,怎么办?(100分)

  • 主题发起人 主题发起人 tomboy
  • 开始时间 开始时间
T

tomboy

Unregistered / Unconfirmed
GUEST, unregistred user!
&nbsp; &nbsp;procedure CMMouseEnter(var Message: TMessage); Message CM_MOUSEENTER;<br>&nbsp; &nbsp; procedure CMMouseLeave(var Message: TMessage); Message CM_MOUSELEAVE;<br>每个控件的这两个消息都会作我写的处理代码,如何只处理Form的这两个消息???
 
不是每个控件的消息都告诉你,而是进入了子控件,实际上也是离开form<br>比如form有一个button,进入button实际上也是离开form
 
所以离开form还是要告诉你的
 
你说的对极了,但如何确定鼠标在Form区域,还是不在Form区域呢?<br>我要实现OICQ的自动隐藏功能
 
Mouse.CursorPos 判断是不是在form的区域里面
 
to tomboy:<br>&nbsp; &nbsp;其实,截获Form的MouseEnter和MouseLeave消息的缺点还不仅仅是你上面说的那种情况,当你快速<br>&nbsp; &nbsp;移动鼠标时,往往根本就截获不到。请看Another_eYes大侠在下面这个帖子中的精彩发言<br>&nbsp; &nbsp;http://www.delphibbs.com/delphibbs/dispq.asp?lid=367914<br>&nbsp; &nbsp;<br>&nbsp; &nbsp;除了Another_eYes大侠提供的两个方法以外,我在提供第三个方法。这个方法虽然笨一些,但绝对<br>&nbsp; &nbsp;有效。是C++Builder代码,但由于代码比较简单,你应该能看明白<br>&nbsp; &nbsp;下面代码实现的功能和OICQ的窗口类似,鼠标移向屏幕的左上角,弹出窗口,鼠标移出窗口时,窗口<br>&nbsp; &nbsp;立即隐藏<br>&nbsp; &nbsp;放置一个TTimer控件,设置200毫秒相应一次,再声明一个全局变量bIsHide,并将其初始化为<br>&nbsp; &nbsp;bIsHide = true;表示此时窗口是隐藏状态的<br>&nbsp; &nbsp;然后,<br>&nbsp; &nbsp; void __fastcall TfrmMain::TimerTimer(TObject *Sender)<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; TPoint ScreenPos;<br>&nbsp; &nbsp; &nbsp; GetCursorPos(&amp;ScreenPos);<br>&nbsp; &nbsp; &nbsp; if(bIsHide)<br>&nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; if( ScreenPos.x == 0 &amp;&amp; ScreenPos.y == 0 )<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Left = 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Top = 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Show();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bIsHide = false;<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; if( (ScreenPos.x &lt; Left) || (ScreenPos.x &gt; Left+Width) ||<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (ScreenPos.y &lt; Top) || (ScreenPos.y &gt; Top+Height) )<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Hide();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bIsHide = true;<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; }<br>&nbsp; &nbsp; 就这么简单。
 
多人接受答案了。
 
后退
顶部