您的位置:首页 > 其它

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

2011-11-16 14:19 232 查看
1.《把脉VC++》

Chap 3

* MFC与ATL

ATL中无法使用CWnd

Chap 4

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

2. 以前关于WTL的笔记

/article/11004121.html

/article/11004122.html

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实例
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: