|
CCmdTarget
#include <afxwin.h> 请参阅 CCmdUI, CDocument, CDocTemplate, CWinApp,CWnd, CView,CFrameWnd, COleDispatchDriver CCmdTarget类的成员 属性 FromDispatch返回一个指向CCmdTarget对象的指针,该对象与IDispatch相联系 GetDispatch返回一个指向IDispatch对象的指针,该对象与CCmdTarget对象相关 IsResultExpected如果自动函数要返回一个值,则返回非零值 操作 BeginWaitCursor显示沙漏标 EnableAutomation允许CCmdTarget 对象的OLE自动函数 EndWaitCursor返回到前一个光标 RestoreWaitCursor重置沙漏标 可覆盖的函数 OnCmdMsg分派命令消息 OnFinalRelease在最后一个OLE对象参考被释放时清除环境 成员函数 CCmdTarget::BeginWaitCursor void BeginWaitCursor( ); 说明 本函数用于显示沙漏标(通常在命令执行时间较长时采用)。框架调用本函数显示沙漏标,告诉用户系统忙,例如在加载一个CDocument对象或把它保存到文件时。在不是处理单个消息时,BeginWaitCursor可能不象其它函数那样有效,例如OnSetCursor的处理也能改变光标形状。调用函数EndWaitCursor可以恢复此前的光标。 示例 //The following example illustrates the most common case //of displaying the hourglass cursor during some lengthy //processing of a command handler implemented in some //CCmdTaget-derived class,such as a document or view. void CMyView::OnSomeCommand( ) ![]() ...{ BeginWaitCursor( ); //display the hourglass cursor //do some lengthy processing EndWaitCursor( ); //remove the hourglass cursor } //The next example illustrates RestoreWaitCursor void CMyView::OnSomeCommand( ) ![]() ...{ BeginWaitCursor( ); //display the hourglass cursor //do some lengthy processing // The dialog box will normally change the cursor to // the standard arrow cursor,and leave the cursor in // as the standard arrow cursor when the dialog box is //closed. CMyDialog dlg;dlg.DoModal( ); // It is necessary to call RestoreWaitCursor here in order // to change the cursor back to the hourglass cursor. RestoreWaitCursor( ); // do some more lengthy processing EndWaitCursor( ); //remove the hourglass cursor } // In the above example,the dialog was clearly invoked between // the pair of calls to BeginWaitCursor and EndWaitCursor. // Sometimes it may not be clear whether the dialog is invoked // in between a pair of calls to BeginWaitCursor and EndWaitCursor .// It is permissable to call RestoreWaitCursor,even if // BeginWaitCursor was not previously called.This case is // illustrated below,where CMyView::AnotherFunction does not // need to know whether it was called in the context of an // hourglass cursor. void CMyView::AnotherFunction( ) ![]() ...{ // some processing CMyDialog dlg; dlg.DoModal( ); RestoreWaitCursor( ); //some more processing } // If the dialog is invoked from a member function of // some non-CCmdTarget,the you call CWinApp::DoWaitCursor // with a 0 parameter value to restore the hourglass cursor. void CMyObject::AnotherFunction( ) ![]() ...{ CMyDialog dlg; dlg.DoModal( ); AfxGetApp( )->DoWaitCursor(0); //same as CCmdTarget::RestoreWaitCursor } ![]() CCmdTarget::EndWaitCursor, CCmdTarget::RestoreWaitCursor, CWinApp::DoWaitCursor CCmdTarget::EnableAutomation void EnableAutomation( ); 说明 本函数设置对象的OLE自动功能。一般在对象的构造函数里调用。调用时要保证已经为类声明了分派映射。有关自动功能的更详细信息,请参阅联机文档“Visual C++程序员指南”中的” 自动客户”和“自动服务器” 请参阅 DECLARE_DISPATCH_MAP, DECLARE_OLECREATE CCmdTarget::EndWaitCursor void EndWaitCursor( ); 说明 本函数在BeginWaitCursor之后调用。它用于撤消沙漏标,并恢复以前的光标。框架在调用沙漏标之后也调用本函数。 示例 // The following example illustrates the most common case // of displaying the hourglass cursor during some lengthy // processing of a command handler implemented in some // CCmdTarget-derived class,such as a document or view. void CMyView::OnSomeCommand( ) ![]() ...{ BeginWaitCursor( ); // display the hourglass cursor // do some lengthy processing EndWaitCursor( ); // remove the hourglass cursor } // The next example illustrates RestoreWaitCursor void CMyView::OnSomeCommand( ) ![]() ...{ BeginWaitCursor( ); // display the hourglass cursor // do some lengthy processing // The dialog box will normally change the cursor to // the standard arrow cursor,and leave the cursor in // as the standard arrow cursor when the dialog box is // closed. CMyDialog dlg; dlg.DoModal( ); // It is necessary to call RestoreWaitCursor here in order // to change the cursor back to the hourglass cursor. RestoreWaitCursor( ); // do some more lengthy processing EndWaitCursor( ); // remove the hourglass cursor } // In the above example,the dialog was clearly invoked between // the pair of calls to BeginWaitCursor and EndWaitCursor. // Sometimes it may not be clear whether the dialog is invoked // in between a pair of calls to BeginWaitCursor and EndWaitCursor. // It is permissable to call RestoreWaitCursor,even if // BeginWaitCursor was not previously called.This case is // illustrated below,where CMyView::AnotherFunction does not // need to know whether it was called in the context of an // hourglass cursor. void CMyView::AnotherFunction( ) ![]() ...{ // some processing…. CMyDialog dlg; dlg.DoModal( ); RestoreWaitCursor( ); // some more processing… } // If the dialog is invoked from a member function of // some non-CCmdTarget,the you call CWinApp::DoWaitCursor // with a 0 parameter value to restore the hourglass cursor. void CMyObject::AnotherFunction( ) ![]() ...{ CMyDialog dlg; dlg.DoModal( ); AfxGetApp( )->DoWaitCursor(0); // same as CCmdTarget::RestorWaitCursor } ![]() CCmdTarget::BeginWaitCursor, CCmdTarget::RestoreWaitCursor, CWinApp::DoWaitCursor CCmdTarget::FromIDispatch static CCmdTarget* FromIDispatch( LPDISPATCH lpDispatch ); 返回值 返回一个和lpDistpatch相关的CCmdTarget对象的指针。如果该IDistpatch对象不是一个MFC IDistpatch对象,则返回NULL。 参数 lpDispatch指向IDistpatch对象的指针。 说明 本函数把从类的自动成员函数中得到的一个IDistpatch指针映射到一个实现了IDistpatch对象接口的CCmdTarget对象。函数的结果与调用函数GetIDispatch的结果相反。 请参阅 CCmdTarget::GetIDispatch, COleDispatchDriver CCmdTarget::GetIDispatch LPDISPATCH GetIDispatch( BOOL bAddRef ); 返回值 返回一个和该对象相关的IDistpatch指针。 参数 bAddRef指明是否增加对该对象的参考记数。 说明 本成员函数用于检索一个自动方法的IDistpatch指针,该自动方法返回一个IDistpatch指针或参考一个IDistpatch指针。对于那些在构造函数中调用了EnableAutomation的对象,本函数使它们自动激活,并返回一个指向IDistpatch在MFC中的实现的指针。该IDistpatch被那些通过IDistpatch接口通信的客户所使用。本函数的调用自动增加一个对该指针的参考,因而不需要调用IUnknow::AddRef。 请参阅 CCmdTarget::EnableAutomation,COleDispatchDriver,IUnknow::Release CCmdTarget::IsResultExpected BOOL IsResultExpected( ); 返回值 如果自动函数要返回一个值,则返回非零值。否则为0。 说明 本函数确定客户是否期待从它对自动函数的调用中返回一个值。OLE接口告诉MFC客户是使用了还是忽略了调用返回值。MFC则使用这些信息决定IsResultExpected的返回值。如果返回值的计算比较耗费时间或其它资源,可以在计算返回值之前调用本函数以提高效率。本函数只返回一次0,这样,如果在一个已被客户端调用的自动函数中调用了其它的自动函数,就可以获得有效的返回值。如果在没有进行自动函数调用时调用本函数,将返回非零值。 请参阅 CCmdTarget::GETIDispatch, CCmdTarget::EnableAutomation CCmdTarget::OnCmdMsgvirtual BOOL OnCmdMsg( UINT nID, int nCode, void* pExtra,AFX_CMDHANDL-ERINF O*pHandlerInfo ); 返回值 如果消息被处理了,则返回非零值;否则为0。 参数 nID命令的ID。 nCode命令的通知代码。 PExtra根据nCode的值使用。 pHandlerInfo如果非空,OnCmdMsg将填充pHandlerInfo 结构的pTarget和pmf成员,而不是分派该命令。此参数通常为NULL。 说明 本函数由框架来调用,它分派命令并处理那些提供了命令用户接口的对象的更新。这是框架的命令体系中实现的一个主要例程。在运行时,OnCmdMsg把命令分派到其它对象上或者调用CcmdTarg-et::OnCmd Msg(此函数进行真正的消息映射查找)自己处理命令。有关这个缺省命令例程的完整描述,请参阅联机文档“Visual C++程序员指南”中的“消息处理”和“映射主题”部分。偶尔需要覆盖本函数以扩展MFC框架的标准命令例程。有关命令例程体系中的更多细节,请参阅联机文档中的“技术指南21”。 请参阅 CCmdUI CCmdTarget::OnFinalRelease virtual void OnFinalRelease( ); 说明 本函数在对对象的最后一个OLE参考或对象对别人的后一个OLE参考被释放时,由框架调用。可以覆盖它以进行所需的处理。缺省的实现是删除该对象。 请参阅 COleServerItem CCmdTarget::RestoreWaitCursorvoid RestoreWaitCursor( ); 说明 本函数用于在系统光标改变后重置沙漏标(例如,在一个耗时操作的过程中打开一个消息窗口而后又关闭它。) 请参阅 CWaitCusor, CCmdTarget:: EndWaitCursor, CCmdTarget::BeginWaitCursor, CWinApp::DoWaitCursor |
相关推荐
MFC Active控件运行没问题,退出时CCmdTarget::CCmdTarget()报:line 40 断言失败,如何解决?
🏆本文收录于 《全栈Bug调优(实战版)》 专栏,该专栏专注于分享我在真实项目开发中遇到的各类疑难Bug及其深层成因,并系统提供高效、可复现的解决思路和实操方案。无论你是刚入行的新手开发者,还是拥有多年项目经验的资深工程师,本专栏都将为你提供一条系统化、高质量的问题排查与优化路径,助力你加速成长,攻克技术壁垒,迈向技术价值最大化与职业发展的更高峰🚀!
MFC:总结篇 CCmdTarget类
一.简介 CCmdTarget 类是CObject 类的子类 所有响应消息或事件的类都从它派生,例如: CWinapp CWnd CDocument CView CDocTemplate CFrameWnd等 CCmdTarget 类是 MFC 处理命令消息的基础核心 转载于:https://www.cnblogs.com/k5bg/p/11214203.html...
关于CCmdTarget及消息映射
CCmdTarget类直接继承自CObject,主管应用程序架构,其向下直接派生出CWnd,而CWnd是所有控件、框架窗口、对话框、视图类的父类。 CCmdTarget类是可以在里面使用消息映射的类,其派生的所有类都有消息映射函数。能用消息映射的类的基类都必须是CCmdTarget类。 CCmdTarget类的派生类在头文件中都必须提供DECLARE_MESSAGE_MAP()宏,在类的CPP文件中都有相应的BEGIN_MESSAGE_MAP(当前类, 直接父类)和END_MESSAGE_MAP()宏与
消息处理机制:CCmdTarget 和 消息映射表
<br />MFC的消息处理机制由两部分组成:CCmdTarget类和消息映射表。<br /> 窗口消息构成<br />所有的窗口消息由3部分组成<br />UINTMsg, <br />WPARAMwParam, <br />LPARAMlParam 为神马不用虚函数来处理消息?<br />因为,虚函数是使用类的虚函数表实现的,每个派生类都会带一个虚函数表的拷贝。虚函数表中的每个入口都是一个4字节指针,这样每个类对象就会在虚函数表中带来大量的额外字节。同时,窗口消息的个数和种类随时会发生变化,在消息改变时
Windows消息机制概述
Windows消息机制概述 消息是指什么? 消息系统对于一个win32程序来说十分重要,它是一个程序运行的动力源泉。一个消息,是系统定义的一个32位的值,他唯一的定义了一个事件,向 Windows发出一个通知,告诉应用程序某个事情发生了。例如,单击鼠标、改变窗口尺寸、按下键盘上的一个键都会使Windows发送一个消息给应用程序。 消息本身是作为一个记录传递给应用程序的,
MFC架构之CCmdTarget类
<br /> 类CCmdTarget是MFC类库中消息映射体系的一个基类。所有响应消息或事件的类都从它派生。例如,CWinApp,CWnd,CDocument,CView,CDocTemplate,CFrameWnd,等等。<br /> CCmdTarget类是MFC处理命令消息的基础、核心。MFC为该类设计了许多成员函数和一些成员数据,基本上是为了解决消息映射问题的,而且,很大一部分是针对OLE设计的。在OLE应用中,CCmdTarget是MFC处理模块状态的重要环节,它起到了传递
CCmdTarget类
该类派生于CObject,它封装了MFC的消息映射机制,希望接收系统事件和窗口消息的类都从它派生,如CDocument和CWnd分支。此外,在系统繁忙,无法响应窗口消息时,鼠标光标应该显示为沙漏形等待状态,CCmdTarget类封装了3个成员函数完成该功能。封装COM的 IDispatch接口是它的另一项主要功能。IDispatch是COM的标准接口,不含指针操作的语言(如VB)以及描述性语言(如
CCmdTarget - MSDN6翻译交流
BUG和建议请提出,谢谢!CCmdTargetCCmdTarget is the base class for the Microsoft Foundation Class Library message-map architecture. A message map routes commands or messages to the member functions you wri
类CCmdTarget
CCmdTarget Class Microsoft基础类库选件消息映射体系结构的基类。 公共构造函数 名称 说明 CCmdTarget::CCmdTarget 构造 CCmdTarget 对象。 公共方法
CObject/CCmdTarget/CCmdTarget三个类的能力
三个类的能力分别为: CObject:运行时类型识别(RTTI)、动态创建(Dynamic Creation)、文件读写(Serialization) CCmdTarget:消息机制,拥有DECLARE_MESSAGE_MAP宏,从而可以接收WM_COMMAND消息 CWnd:除WM_COMMAND消息之外,还可以接收WM_xxx消息 这三
CWnd可以处理什么消息什么消息,CCmdTarget可以处理什么什么消息
只要是从CWnd派生类,就可以拦下任何Windows消息 与窗口无关的MFC类(例如CDocument和CWinApp)如果也想处理消息,必顺派生自CCmdTarget,并且只能收到WM_COMMAND命令消息
MFC CCmdTarget Class成员变量及成员函数
该类派生于CObject,它封装了MFC的消息映射机制,希望接收系统事件和窗口消息的类都从它派生,如CDocument和CWnd分支。此外,在系统繁忙,无法响应窗口消息时,鼠标光标应该显示为沙漏形等待状态,CCmdTarget类封装了3个成员函数完成该功能。CCmdTarget类以一种类似消息映射的机制提供IDispatch接口,所以使用MFC可以轻松地编写AUTOMATION客户程序和组件。
继:VC中利用CCmdTarget进行的成员函数回调
MFC的消息映射函数中也是用了成员函数回调的方法,经过观察,所有消息处理函数都被映射为CCmdTarget基类的函数指针,比如:#define ON_UPDATE_COMMAND_UI(id, memberFxn) / { WM_COMMAND, CN_UPDATE_COMMAND_UI, (WORD)id, (WORD)id, AfxSig_cmdui, / (AFX_PMSG)(void (
MFC类结构-2、CCmdTarget类
该类派生于CObject,它封装了MFC的消息映射机制,希望接收系统事件和窗口消息的类都从它派生,如CDocument和CWnd分支。此外,在系统繁忙,无法响应窗口消息时,鼠标光标应该显示为沙漏形等待状态,CCmdTarget类封装了3个成员函数完成该功能。封装COM的 IDispatch接口是它的另一项主要功能。IDispatch是COM的标准接口,不含指针操作的语言(如VB)以及描述性语言(如...
MFC # 无法向此非ccmdtarget派生类添加任何命令
使用类向导时报错:无法向此非ccmdtarget派生类添加任何命令 解决方法: ① 关闭对应的解决方案 ② 删除下面的目录debug或者release ③ 删除.vs文件夹和.sdf文件(有的话)
CDocument继承自CCmdTarget类,只能接收WM_COMMAND
// 错误原因:CDocument继承自CCmdTarget类,只能接收WM_COMMAND,它的消息处理函数原形为 //LRESULT CSuperEditDoc::OnFileProcess(WPARAM wParam, LPARAM lParam) //{ // UINT pos = HIWORD(lParam); // UINT max = HIWORD(l...
objectARX 关于MFC类向导 无法向此非CCmdTarget派生类添加任何命令 解决方法
VS2017 C++通过类向导添加消息时提示:无法向此非CCmdTarget派生类添加任何命令 解决方法: ① 关闭对应的解决方案 ② 删除下面的目录debug或者release ③ 删除.vs文件夹和.sdf文件(有的话) 上述三步执行完之后,可以正常添加消息函数了。。 ...



BeginWaitCursor( ); 
1203




被折叠的 条评论
为什么被折叠?



