读书时间 2011/11/16 读书时间

本文深入探讨了C++与ATL/WTL框架的整合应用,详细解析了ATL中无法使用CWnd的问题及赋值与初始化的区别。通过分析WTL例子My2ndWTL70Win,展示了如何在不同环境下进行窗口生成与消息循环操作,包括环境初始化、窗口创建、显示以及消息循环流程。重点介绍了CAppModule实例的作用和必要性,以及整个过程的步骤和关键代码解释。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

1.《把脉VC++》

 

Chap 3

* MFC与ATL

ATL中无法使用CWnd

 

Chap 4

* 赋值与初始化的区别:前者调用operator=(),后者调用constructor

 

2. 以前关于WTL的笔记

http://blog.youkuaiyun.com/printf1998/article/details/6401743

http://blog.youkuaiyun.com/printf1998/article/details/6403104

 

3. WTL例子分析:My2ndWTL70Win

* My2ndWTL70Win.cpp

 


// HelloWTL70Win2.cpp : main source file for HelloWTL70Win2.exe
//

#include "stdafx.h"

//#include <atlapp.h>

#include <atlframe.h>
#include <atlctrls.h>
#include <atldlgs.h>
#include <atlctrlw.h>

#include "resource.h"

#include "MyMainWnd.h"

//#include "aboutdlg.h"
//#include "maindlg.h"

CAppModule _Module;

int Run(LPTSTR /*lpstrCmdLine*/ = NULL, int nCmdShow = SW_SHOWDEFAULT)
{
 CMessageLoop theLoop;
 _Module.AddMessageLoop(&theLoop);
 
 CMyMainWnd MyMainWnd;
 
 if(MyMainWnd.CreateEx() == NULL)
 {
  ATLTRACE(_T("Main dialog creation failed!\n"));
  return 0;
 }
 
 MyMainWnd.ShowWindow(nCmdShow);
 
 int nRet = theLoop.Run();
 
 _Module.RemoveMessageLoop();
 return nRet;
 // return 0;
}

int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow)
{
 HRESULT hRes = ::CoInitialize(NULL);
 // If you are running on NT 4.0 or higher you can use the following call instead to
 // make the EXE free threaded. This means that calls come in on a random RPC thread.
 // HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
 ATLASSERT(SUCCEEDED(hRes));
 
 // this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used
 ::DefWindowProc(NULL, 0, 0, 0L);
 
 AtlInitCommonControls(ICC_COOL_CLASSES | ICC_BAR_CLASSES); // add flags to support other controls
 
 hRes = _Module.Init(NULL, hInstance);
 ATLASSERT(SUCCEEDED(hRes));
 
 int nRet = Run(lpstrCmdLine, nCmdShow);
 
 _Module.Term();
 ::CoUninitialize();
 
 return nRet;
}

 

总结:

#1. 必须有一个CAppModule的实例,并且名字只能是_Module(因为ATL/WTL类库中直接使用此名字)

CAppModule _Module;

#2.基本steps

各种环境初始化:CoInit, _Module.init

窗口生成与消息循环

环境复位:Com.uninit. _Module.term

 

#3 窗口生成与消息循环

MessageLoop实便化并加入_Module

主窗口实例化

主窗口生成

主窗口显示

messageLoop.run(消息循环)

_Module删除messaegLoop实例

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值