Programming with Microsoft Visual C++.NET 6ed [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Programming with Microsoft Visual C++.NET 6ed [Electronic resources] - نسخه متنی

George Shepherd, David Kruglinski

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
توضیحات
افزودن یادداشت جدید








Extended Command Processing


In addition to the ON_COMMAND message map macro, the MFC library provides an extended variation, ON_COMMAND_EX. The extended command message map macro provides two features not supplied by the regular command message—a command ID function parameter and the ability to reject a command at run time, sending it to the next object in the command route. If the extended command handler returns TRUE, the command goes no further; if it returns FALSE, the application framework looks for another command handler.

The command ID parameter is useful when you want one function to handle several related command messages. You might invent some of your own uses for the rejection feature.

The code wizards available from Class View's Properties window can't help you with extended command handlers, so you have to do the coding yourself, outside the AFX_MSG_MAP brackets. Assume that IDM_ZOOM_1 and IDM_ZOOM_2 are related command IDs defined in

Resource.h . Here's the class code you need to process both messages with one function, OnZoom:

BEGIN_MESSAGE_MAP(CMyView, CView)
ON_COMMAND_EX(IDM_ZOOM_1, OnZoom)
ON_COMMAND_EX(IDM_ZOOM_2, OnZoom)
END_MESSAGE_MAP()
BOOL CMyView::OnZoom(UINT nID)
{
if (nID == IDM_ZOOM_1) {
// code specific to first zoom command
}
else {
// code specific to second zoom command
}
// code common to both commands
return TRUE; // Command goes no further
}

Here's the function prototype:

afx_msg BOOL OnZoom(UINT nID);

Other MFC message map macros are helpful for processing ranges of commands, as you might see in dynamic menu applications. These macros include ON_COMMAND_RANGE, ON_COMMAND_EX_RANGE, and ON_UPDATE_COMMAND_UI_RANGE.

If the values of IDM_ZOOM_1 and IDM_ZOOM_2 were consecutive, you could rewrite the CMyView message map as follows:

BEGIN_MESSAGE_MAP(CMyView, CView)
ON_COMMAND_EX_RANGE(IDM_ZOOM_1, IDM_ZOOM_2, OnZoom)
END_MESSAGE_MAP()

Now OnZoom is called for both menu commands, and the handler can determine the command from the integer parameter.


/ 319