找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 1353|回复: 2

[教学]:如何使用MFC显示一个context menu...

[复制链接]

已领礼包: 145个

财富等级: 日进斗金

发表于 2002-2-26 00:17:01 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
How to display a context menu using MFC?  
ID    12678  
Applies to:    AutoCAD 2000I
AutoCAD 2002
AutoCAD 2000

Date    1/31/2002  

This document is part of    MFC     


Question
How can I display and control a context menu using MFC?
Answer
Before we explain how to display a context menu using MFC, we should note that
ObjectARX APIs are available to do the job. They are much easier and systematic
to use. A sample is available with ObjectARX SDK. See <ARXSDK>\samples\mfcsamples\contextmenu
folder. Here, we discuss about another approach using MFC.

There are several steps that are required in order to display and control a
context menu. First, install a message filter function using acedRegisterFilterWinMsg().
Then in the message filter function, watch for WM_RBUTTONDOWN messages.

The attached sample displays a custom context menu if there is an entity under
the actual cursor position, and does the test on the WM_RBUTTONDOWN message.

For this implementation, DevNote #3115 was used to convert Windows coordinates
into AutoCAD UCS coordinates. After extracting the AutoCAD UCS coordinates,
acedSSGet(":E", ...) was used to find out if there is an entity at this position,
which is taken from DevNote#71216.

If there is an entity, it is blocked with the WM_RBUTTONDOWN message. AutoCAD
does not know that this message exists. In the WM_RBUTTONUP message, AutoCAD
is prepared to display the context menu. <CTRL-C> is entered twice to unhighlight
any selected entities, and a WM_LBUTTONDOWN/UP message lets AutoCAD select the
entity that is under the current cursor position. After the messages are sent,
the sample creates a timer. This is necessary to enable AutoCAD to receive and
process the sent messages.

The WM_RBUTTONUP message is blocked as well. The timer function reacts after
100 milliseconds, and it then updates the context menu to show the class name
of the selected entity (using right-click) in a menu entry and uses
CMenu::TrackPopupMenu() to display the menu. Windows does not return from this
function call until the user selected an entry or dismissed the menu.

The selected menu entry is caught in the message filter function. The program
looks for WM_COMMAND messages with the IDs. If there is a message from the menu,
it sends a command to AutoCAD using acedPostCommand().
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
发表于 2002-2-26 14:18:56 | 显示全部楼层
XDSOFT:对上述教学请给个例子
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 145个

财富等级: 日进斗金

 楼主| 发表于 2002-2-26 17:52:28 | 显示全部楼层
最初由 hotgirl 发布
[B]XDSOFT:对上述教学请给个例子 [/B]


你真粗心:),上面的教学已经写了,请到OBJECTARX安装目录下面的\samples\mfcsamples\contextmenu 文件夹,里面就是关于CONTEXT MENU应用的例子。

关于ARX的各种应用,在SAMPLES目录下都有解决方法的例子程序,去看看吧。
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-11-16 04:25 , Processed in 0.286631 second(s), 36 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表