mapx 拦截键盘输入




/*
MapInfo Products Knowledge Base
Product: MapX
Version: 4.x
Platform: Windows 9598 & Windows NT
Category: VC++ Code Samples
Summary:
Catching key strokes before they are sent to MapX in C++?
Question:
When the delete key is pressed, it deletes the selected feature on the map. Is there a way to catch and disable this functionality in C++?
当删除键按下时,它删除了图层中选定的图元。在c++中有没有一种办法来捕捉并停用此功能? 

Answer:
Below is an example of how to catch keystrokes in C++ before they are sent to the MapX Object. This is done by creating a sub class that catches the KeyDown event and handles the key before sending it to the MapX object. The sub class is derived from the CMapX class. In this example, the sub class is called CMyMapX. To implement it, create a new class derived from the CMapX Class (The class code is below). In the main class where the MapX variable is defined, change its class from CMapX to CMyMapX and change the #include "MapX.h" line to #Include "MyMapX.h". Now, in the new class, add a message map (using the class wizard) to trap the ON_WM_KEYDOWN message and fire an event in the class. Now when the delete key is pressed, it fires this event in the class which handles the key and sends it on to MapX for normal MapX processing. This logic can be used to catch any MapX events before they reach MapX.

下面的例子展示了在c++中怎样在按键消息被传递到mapx对象之前将之拦截 。
它创建了一个子类,可以拦截keydown事件并进行处理,然后发送到mapx的对象。这个子类派生自cmapx类。在这个例子中,子类是所谓cmymapx 。
要实现它,首先构造一个派生自CMapX类的新的子类(代码如下)。
接下来,改变mainclass中mapx变量的定义类型,将其类型改为CMyMapx,将#include改为#include "MyMapX.h " 。
在新类中增加了一个消息映射,(使用类向导)将on_wm_keydown消息事件处理映射到这个类中。
现在当delete 键按下时,它触发的事件将在这个类中得以处理,并随后将它传递到mapx进行正常mapx的处理。
同样的逻辑,可以用这种方式捕获任何事件,在传递到MapX之前。
*/


// MapX Sub class
class  CMyMapX :  public  CMapX
{
// Construction
public:
CMyMapX();

// Attributes
public:

// Operations
public:

// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMyMapX)
//}}AFX_VIRTUAL

// Implementation
public:
virtual 
~CMyMapX();

// Generated message map functions
protected:
//{{AFX_MSG(CMyMapX)
afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
}
;

// Class cpp file stuff
BEGIN_MESSAGE_MAP(CMyMapX, CMapX)
// {{AFX_MSG_MAP(CMyMapX)
ON_WM_KEYDOWN()
// }}AFX_MSG_MAP
END_MESSAGE_MAP()

/
//  CMyMapX message handlers

void  CMyMapX::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
//Disable the delete key
if( nChar == VK_DELETE )
return;

//Do the normal processing
CMapX::OnKeyDown(nChar, nRepCnt, nFlags);
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值