本文介绍了CAppModule与CAtlExeModuleT,获取应用程序消息循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的项目中从ATL :: CAppModule获取消息循环,似乎没有,因此:




  • 我试过定义CAppModule, extern CAppModule _Module; 在stdafx.h和 CAppModule _Module; 在我的 .cpp文件,它编译,链接和在执行注册步骤我得到一个断言 atlbase.h here
    ATLASSERT(_pAtlModule == NULL);
    这意味着CAppModule已经被声明。



但我似乎找不到另一个CAppModule实例化,而是看到一个CAtlExeModuleT实例化(它不是我的代码..) 。



现在..从我搜索我找到一种方法来获取消息循环从CAtlExeModuleT对象。它们是不同的东西还是我缺少某些东西?

解决方案

CAppModule 是一个WTL类。 _pAtlModule 是指向模块单例类的静态/全局ATL变量。



您不能修复ATL <$ c $ (


$ b),因为这两个是不相关的(在某些方面具有一定的相似性)。

$ <$ p code> $ b

要修复 _pAtlModule 问题,您需要一个ATL模块实例。最简单的是添加 CComModule static:

  CComModule _Module; //<  - 这里你去

int _tmain(int argc,_TCHAR * argv [])
{
// ...

因为 CComModule 本身仅用于向后兼容,使用 CAtlExeModuleT (和朋友),但WTL不会这样工作,因为WTL的 CAppModule 继承自 CComModule 。 CAppModule 的全局实例也将是ATL CComModule 的实例:

  CAppModule _Module; 

int _tmain(int argc,_TCHAR * argv [])
{
// ...
_Module.Init(...
CMessageLoop MessageLoop;
_Module.AddMessageLoop(& MessageLoop);
// ...

然后稍后在一些应用程序对象:

  CMessageLoop * pMessageLoop = _Module.GetMessageLoop(); 

GetMessageLoop 调用将检索您之前添加的消息循环。 / p>

解决此ATL / WTL问题后,您可以转到 WTL消息循环事情,你期望 PreTranslateMessage 在模态对话框消息循环调用,它不会( CMessageLoop 调用消息过滤器链,而模态对话框的循环不会调用)。


I am trying to get the message loop from a ATL::CAppModule in my project, there seems to be none, so:

  • I've tried defining CAppModule, with extern CAppModule _Module; in "stdafx.h" and CAppModule _Module; in my .cpp file, it compiles, linkes and at the perform registration step I get an assertion in atlbase.h hereATLASSERT(_pAtlModule == NULL);which means that the CAppModule has already been declared.

But I can't seem to find another CAppModule instantiation, instead I see a CAtlExeModuleT instantiation (it is not my code..).

now.. from what I've searched I haven t found a way to get the message loop from a CAtlExeModuleT object. Are they different things or am I missing something?

解决方案

There is a mix of issues here. CAppModule is a WTL class. _pAtlModule is static/global ATL variable that points to module singleton class.

You cannot fix ATL _pAtlModule problem with WTL CAppModule because the two are unrelated (atlthough have certain similarity between).

To fix the _pAtlModule problem you need an ATL module instance. The simplest is to add CComModule static:

CComModule _Module; // <-- Here you go

int _tmain(int argc, _TCHAR* argv[])
{
  //...

Because CComModule itself is here for backward compatibility only, it would be the better to use CAtlExeModuleT (and friends) instead, however WTL will not work this way because WTL's CAppModule inherits from CComModule. The global instance of CAppModule will also be the instance for ATL CComModule:

CAppModule _Module;

int _tmain(int argc, _TCHAR* argv[])
{
    // ...
    _Module.Init(...
    CMessageLoop MessageLoop;
    _Module.AddMessageLoop(&MessageLoop);
    // ...

and then later on some application object:

CMessageLoop* pMessageLoop = _Module.GetMessageLoop();

the GetMessageLoop call will retrieve the message loop you added earlier.

Having this ATL/WTL issue resolved, you can move on to the WTL message loop thing, where you expect PreTranslateMessage to be called on modal dialog message loop and it won't be called there because it is not expected to work this way (CMessageLoop calls message filter chain, and modal dialog's loop don't).

这篇关于CAppModule与CAtlExeModuleT,获取应用程序消息循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 01:44