- UID
- 1
- 积分
- 15892
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-1-3
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
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(). |
|