菜鸟寒号(嚎):请各位翻译,没钱,有分

超级管理员9527 2003-09-18 01:31:18
MFC Windows 程序设计:以下段落,中文版读了几遍,意思稍明白;可是思路不清(不是我中文水平不行,就是翻译狗屁不通)。原文如下(代码就不用翻译了):

TrackPopupMenu is typically called in response to WM_CONTEXTMENU messages. MFC's ON_WM_CONTEXTMENU macro maps WM_CONTEXTMENU messages to the message handler OnContextMenu. OnContextMenu receives two parameters: a CWnd pointer identifying the window in which the click occurred and a CPoint containing the cursor's screen coordinates:

afx_msg void OnContextMenu (CWnd* pWnd, CPoint point)




If necessary, you can translate the screen coordinates passed in point into client coordinates with CWnd::ScreenToClient. It might seem curious that OnContextMenu receives a pointer identifying a window since mouse messages go to the window under the cursor. However, there's a reason. Unlike other messages, WM_CONTEXTMENU messages percolate upward through the window hierarchy if a right-click occurs in a child window (for example, a push button control) and the child window doesn't process the message. Therefore, if a window contains child windows, it could receive WM_CONTEXTMENU messages with pWnd containing a pointer to one of its children.

It's important for an OnContextMenu handler to call the base class's OnContextMenu handler if it examines pWnd or point and decides not to process the message. Otherwise, WM_CONTEXTMENU messages won't percolate upward. Worse, right-clicking the window's title bar will no longer display the system menu. The following OnContextMenu handler displays the context menu referenced by pContextMenu if the button click occurs in the upper half of the window and passes it to the base class if the click occurs elsewhere:

void CChildView::OnContextMenu (CWnd* pWnd, CPoint point)
{
CPoint pos = point;
ScreenToClient (&pos);

CRect rect;
GetClientRect (&rect);
rect.bottom /= 2; // Divide the height by 2.

if (rect.PtInRect (pos)) {
pContextMenu->TrackPopupMenu (TPM_LEFTALIGN ¦
TPM_LEFTBUTTON ¦ TPM_RIGHTBUTTON, point.x, point.y,
AfxGetMainWnd ());
return;
}
CWnd::OnContextMenu (pWnd, point);
}





In a view-based application like Shapes, the WM_CONTEXTMENU handler is typically placed in the view class because that's where the objects that are subject to right clicks are displayed.

How do you get a pointer to a context menu in order to display it? One method is to construct a CMenu object and build the menu with CMenu member functions. Another is to load the menu from a resource in the same way that a top-level menu is loaded. The following menu template defines a menu that contains one submenu:

IDR_CONTEXTMENU MENU
BEGIN
POPUP ""
BEGIN
MENUITEM "©", ID_CONTEXT_COPY
MENUITEM "&Rename", ID_CONTEXT_RENAME
MENUITEM "&Delete", ID_CONTEXT_DELETE
END
END




The following statements load the menu into a CMenu object and display it as a context menu:

CMenu menu;
menu.LoadMenu (IDR_CONTEXTMENU);
CMenu* pContextMenu = menu.GetSubMenu (0);
pContextMenu->TrackPopupMenu (TPM_LEFTALIGN ¦
TPM_LEFTBUTTON ¦ TPM_RIGHTBUTTON, point.x, point.y,
AfxGetMainWnd ());





If your application uses several context menus, you can define each context menu as a separate submenu of IDR_CONTEXTMENU and retrieve CMenu pointers by varying the index passed to GetSubMenu. Or you can define each one as a separate menu resource. In any event, attaching the context menu to a CMenu object that resides on the stack ensures that the menu will be destroyed when the object goes out of scope. The menu is no longer needed after TrackPopupMenu returns, so deleting it frees up memory that can be put to other uses.

...全文
124 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
已经结贴,可是这里我看不见分,进管理,分又给了,不知道怎么回事。没得到分的给个消息,我去问斑竹
tylike 2003-09-18
  • 打赏
  • 举报
回复
用豪杰译霸!非常不错 的
haoguozhong 2003-09-18
  • 打赏
  • 举报
回复
用金山词霸看
my_mtx 2003-09-18
  • 打赏
  • 举报
回复
up
bcpl 2003-09-18
  • 打赏
  • 举报
回复
帮你翻两段先(不保证正确)

TrackPopupMenu通常在响应WM_CONTEXTMENU消息时调用。MFC的ON_WM_CONTEXTMENU宏把WM_CONTEXTMENU消息映射到消息处理函数OnContextMenu。OnContextMenu接收两个参数:一个用于识别点击发生在哪个窗口的CWnd指针,一个包含光标屏幕坐标的CPoint对象:

afx_msg void OnContextMenu (CWnd* pWnd, CPoint point)

有必要的话,你可以用CWnd::ScreenToClient函数把通过point参数传进来的屏幕坐标转为客户区坐标。由于鼠标消息通常被发送到光标之下的窗口,OnContextMenu另外接收一个用于识别窗口的指针看起来也许有点古怪。然而,这是有原因的。当右击发生在子窗口(如按钮控件),而该子窗口并不处理WM_CONTEXTMENU时,WM_CONTEXTMENU消息根据窗口的层次向上传递,这点与其它消息不同。因此,如果一个窗口包含有子窗口,它可能接收到pWnd参数为子窗口指针的WM_CONTEXTMENU消息。
vcforever 2003-09-18
  • 打赏
  • 举报
回复
太多了!
用金山词霸看吧!
whiteclouds 2003-09-18
  • 打赏
  • 举报
回复
没时间弄,自己找本字典或金山词霸看吧!其实不难,我简单看了看,稍微懂点英文就能看懂,只是可能生词多点。
flyycyu 2003-09-18
  • 打赏
  • 举报
回复
up
flyelf 2003-09-18
  • 打赏
  • 举报
回复
其实只要能看懂大概意思就可以了,何必这么执著呢,呵呵
stcrane1228 2003-09-18
  • 打赏
  • 举报
回复
可惜我没时间,E文也一般
找个外语系的给翻译
Fengq 2003-09-18
  • 打赏
  • 举报
回复
up
chen_pin 2003-09-18
  • 打赏
  • 举报
回复
Up it
bluebohe 2003-09-18
  • 打赏
  • 举报
回复
你小子分够多的,可是我英语头疼,帮不了你,建议你直接看中文,呵呵
dzqsuper 2003-09-18
  • 打赏
  • 举报
回复
楼主,现在谁也没有功夫给你弄这个了

现在都在为了钱途而工作了

我也要学习了
tanyaliji 2003-09-18
  • 打赏
  • 举报
回复
up
flinming 2003-09-18
  • 打赏
  • 举报
回复
up
FreeSeagull 2003-09-18
  • 打赏
  • 举报
回复
晕!本来只打算翻译两段的,一不小心全翻译完了。
FreeSeagull 2003-09-18
  • 打赏
  • 举报
回复
接bcpl(闲庭信步) ( )帮你翻译两段。同样,不保证完全正确。
---------------------------------------------------------------------------------
It's important for an OnContextMenu handler to call the base class's OnContextMenu handler if it examines pWnd or point and decides not to process the message.
如果OnContextMenu()检查pWnd或者point,并且决定不处理此消息,那么OnContextMenu()调用基类的OnContextMenu()很重要。
---------------------------------------------------------------------------------
Otherwise, WM_CONTEXTMENU messages won't percolate upward. Worse, right-clicking the window's title bar will no longer display the system menu.
否则,WM_CONTEXTMENU消息不会向上过滤。更坏的情况,右击窗口的标题栏,系统菜单会显示不出来。
---------------------------------------------------------------------------------
The following OnContextMenu handler displays the context menu referenced by pContextMenu if the button click occurs in the upper half of the window and passes it to the base class if the click occurs elsewhere:
如果鼠标单击发生在窗口的上半部分,下面的OnContextMenu()消息处理函数显示由pContextMenu指向的上下文菜单。如果单击发生在其他地方,消息将被发送到基类。
---------------------------------------------------------------------------------
void CChildView::OnContextMenu (CWnd* pWnd, CPoint point)
{
CPoint pos = point;
ScreenToClient (&pos);

CRect rect;
GetClientRect (&rect);
rect.bottom /= 2; // Divide the height by 2.

if (rect.PtInRect (pos)) {
pContextMenu->TrackPopupMenu (TPM_LEFTALIGN ¦
TPM_LEFTBUTTON ¦ TPM_RIGHTBUTTON, point.x, point.y,
AfxGetMainWnd ());
return;
}
CWnd::OnContextMenu (pWnd, point);
}
---------------------------------------------------------------------------------
In a view-based application like Shapes, the WM_CONTEXTMENU handler is typically placed in the view class because that's where the objects that are subject to right clicks are displayed.
在一个基于视图的应用程序,如图形程序,WM_CONTEXTMENU的处理函数典型情况下都是放置在View类里边。这是因为View类是显示那些与右键相关联的对象的地方。
---------------------------------------------------------------------------------
How do you get a pointer to a context menu in order to display it? One method is to construct a CMenu object and build the menu with CMenu member functions.
如何才能够得到一个指向上下文菜单的指针并进而显示?一种方法是建立一个CMenu对象并且利用CMenu成员函数来建立。
---------------------------------------------------------------------------------
Another is to load the menu from a resource in the same way that a top-level menu is loaded. The following menu template defines a menu that contains one submenu:
另外一种方法是从资源中加载菜单,top-level菜单就是通过这种方式建立的。下边的菜单模板定义了包含一个子菜单的菜单。
---------------------------------------------------------------------------------
IDR_CONTEXTMENU MENU
BEGIN
POPUP ""
BEGIN
MENUITEM "©", ID_CONTEXT_COPY
MENUITEM "&Rename", ID_CONTEXT_RENAME
MENUITEM "&Delete", ID_CONTEXT_DELETE
END
END
---------------------------------------------------------------------------------
The following statements load the menu into a CMenu object and display it as a context menu:
下边演示的是如何加载菜单到一个CMenu对象,并且把它作为一个上下文菜单显示出来:
---------------------------------------------------------------------------------
CMenu menu;
menu.LoadMenu (IDR_CONTEXTMENU);
CMenu* pContextMenu = menu.GetSubMenu (0);
pContextMenu->TrackPopupMenu (TPM_LEFTALIGN ¦
TPM_LEFTBUTTON ¦ TPM_RIGHTBUTTON, point.x, point.y,
AfxGetMainWnd ());

---------------------------------------------------------------------------------
If your application uses several context menus, you can define each context menu as a separate submenu of IDR_CONTEXTMENU and retrieve CMenu pointers by varying the index passed to GetSubMenu.
如果你的应用程序使用了多个上下文菜单,你可以把每一个上下文菜单作为IDR_CONTEXTMENU 的一个独立子菜单并通过变换传递给GetSubMenu()的索引来取得CMenu指针。
--------------------------------------------------------------------------------
Or you can define each one as a separate menu resource. In any event, attaching the context menu to a CMenu object that resides on the stack ensures that the menu will be destroyed when the object goes out of scope.
或者,你可以定义把每一个上下文菜单定义为一个独立的菜单资源。在任何情况下,都需要把上下文菜单粘附到一个CMenu对象上,以保证不会因为对象超过作用范围被释放而导致菜单被摧毁。
--------------------------------------------------------------------------------
The menu is no longer needed after TrackPopupMenu returns, so deleting it frees up memory that can be put to other uses.
当TrackPopupMenu()返回以后,就不再需要菜单了,于是,删除它,释放内存以供他用。

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧