鼠标进入和鼠标离开

     阅读 1180 次    更新时间:2014/4/18    
发信人: heiheihei (嘿嘿嘿), 信区: BCB 

发信人: heiheihei (嘿嘿嘿), 信区: BCB 


标  题: Re: 鼠标进入和鼠标离开是哪两个消息? 

发信站: BBS 水木清华站 (Mon May 31 14:49:17 1999) 

  

给你个例子,这是俺老师写的具有鼠标进入和鼠标离开事件的panel 

//sunpanel.h 

//--------------------------------------------------------------------------- 

#ifndef SunPanelH 

#define SunPanelH 

//--------------------------------------------------------------------------- 

#include  

#include  

#include  

#include  

#include  

//--------------------------------------------------------------------------- 

class PACKAGE TSunPanel : public TPanel 

{ 

private: 

     TNotifyEvent FOnMouseEnter; 

     TNotifyEvent FOnMouseLeave; 

protected: 

   void __fastcall CMMouseEnter(TMessage& msg); 

   void __fastcall CMMouseLeave(TMessage& msg); 

  BEGIN_MESSAGE_MAP 

     MESSAGE_HANDLER(CM_MOUSEENTER, TMessage, CMMouseEnter) 

     MESSAGE_HANDLER(CM_MOUSELEAVE, TMessage, CMMouseLeave) 

  END_MESSAGE_MAP(TPanel) 

public: 

    __fastcall TSunPanel(TComponent* Owner); 

__published: 

     __property TNotifyEvent OnMouseEnter = { read=FOnMouseEnter, 

  write=FOnMouseEnter, 

  default=NULL }; 

     __property TNotifyEvent OnMouseLeave = { read=FOnMouseLeave, 

  write=FOnMouseLeave, 

  default=NULL }; 

}; 

//--------------------------------------------------------------------------- 

#endif 

  

//sunpanel.cpp 

//--------------------------------------------------------------------------- 

#include  

#pragma hdrstop 

#include "SunPanel.h" 

#pragma package(smart_init) 

//--------------------------------------------------------------------------- 

// ValidCtrCheck is used to assure that the components created do not have 

// any pure virtual functions. 

// 

static inline void ValidCtrCheck(TSunPanel *) 

{ 

    new TSunPanel(NULL); 

} 

/*//--------------------------------------------------------------------------- 

__fastcall TSunPanel::TSunPanel(TComponent* Owner) 

    : TPanel(Owner) 

{ 

} */ 

//--------------------------------------------------------------------------- 

__fastcall TSunPanel::TSunPanel(TComponent* Owner) 

     : TPanel(Owner), FOnMouseEnter(NULL), FOnMouseLeave(NULL) 

  { 

  } 

  //--------------------------------------------------------------------------- 

  void __fastcall TSunPanel::CMMouseEnter(TMessage& msg) 

  { 

     if(OnMouseEnter) OnMouseEnter(this); 

  } 

  //--------------------------------------------------------------------------- 

  void __fastcall TSunPanel::CMMouseLeave(TMessage& msg) 

  { 

     if(OnMouseLeave) OnMouseLeave(this); 

  } 

  //--------------------------------------------------------------------------- 

namespace Sunpanel 

{ 

    void __fastcall PACKAGE Register() 

    { 

        TComponentClass classes[1] = {__classid(TSunPanel)}; 

        RegisterComponents("Samples", classes, 0); 

    } 

} 

//--------------------------------------------------------------------------- 

  

  

【 在 ab (阅读文章) 的大作中提到: 】 



: 是这两个么: WM_MOUSEHOVER 和 WM_MOUSELEAVE; 

: 我从 TButton 类继承生成了一个新的组件, 响应这两个消息, 

: 可是最后结果什么也没有. 

: 请指点我一下吧. 

  

  

-- 

    /// /// ////// ////  /// /// ////// ////  /// /// ////// //// 

    //  // //      //    //  // //      //    //  // //      // 

   ////// //////  //    ////// //////  //    ////// //////  // 

  //  // //      //    //  // //      //    //  // //      // 

///  ///////// ////  ///  ///////// ////  ///  ///////// //// 

  

 
 

Copyright 2003-2008 All Rights Reserved 自由风工作室 版权没有 [湘ICP备06002185号]
.