1.《把脉VC++》
Chap 3
* MFC与ATL
ATL中无法使用CWnd
Chap 4
* 赋值与初始化的区别:前者调用operator=(),后者调用constructor
2. 以前关于WTL的笔记
http://blog.csdn.net/printf1998/article/details/6401743
http://blog.csdn.net/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实例

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

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



