WTL学习之旅(一) 我的第一个WTL工程

转载请标明是引用于 http://blog.csdn.net/chenyujing1234

 相关代码:

http://www.rayfile.com/zh-cn/files/f19ea46e-77e3-11e1-b980-0015c55db73d/

安装WTL请参考

http://blog.csdn.net/chenyujing1234/article/details/7399014

WTL环境优化:

修改AppWiz文件夹下setup90x.js 。把第152行 fileDest.WriteLine("Param=\"VC_EXPRESS = 1\""); 这句删除。

image

 

WTL向导认为如果是Express版本的VC一定是和psdk2003是的atl配合的,具体和atlthunk相关。如果不删除这句,用向导生成程序是运行不了的

然后在AppWiz\Files\Templates\1033文件夹找到stdafx.h 在32行添加#pragma comment(lib,”atlthunk.lib”)。这样用向导生成的程序就不会有链接错误了。

image

 

工程名为WTLTest。

选择Generate .cpp Files是为了产生cpp文件,这样更符合我们的习惯,不然只有.h文件产生.

调试过程后得知,WTL的调用如下:

1、_tWinMain入口

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_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; }

2、采用ATL初始化模块.

CAppModule _Module;

_Module.Init(

// Overrides of CComModule::Init and Term
	HRESULT Init(ATL::_ATL_OBJMAP_ENTRY* pObjMap, HINSTANCE hInstance, const GUID* pLibID = NULL)
	{
		HRESULT hRet = CComModule::Init(pObjMap, hInstance, pLibID);
		if(FAILED(hRet))
			return hRet;

		m_dwMainThreadID = ::GetCurrentThreadId();
		typedef ATL::CSimpleMap<DWORD, CMessageLoop*>   _mapClass;
		m_pMsgLoopMap = NULL;
		ATLTRY(m_pMsgLoopMap = new _mapClass);
		if(m_pMsgLoopMap == NULL)
			return E_OUTOFMEMORY;
		m_pSettingChangeNotify = NULL;

		return hRet;
	}

 

结束时是_Module.Term(); 

	void Term()
	{
		TermSettingChangeNotify();
		delete m_pMsgLoopMap;
		CComModule::Term();
	}



3、创建ATL窗口

int Run(LPTSTR /*lpstrCmdLine*/ = NULL, int nCmdShow = SW_SHOWDEFAULT)
{
	CMessageLoop theLoop;
	_Module.AddMessageLoop(&theLoop);

	CMainDlg dlgMain;

	if(dlgMain.Create(NULL) == NULL)
	{
		ATLTRACE(_T("Main dialog creation failed!\n"));
		return 0;
	}

	dlgMain.ShowWindow(nCmdShow);

	int nRet = theLoop.Run();

	_Module.RemoveMessageLoop();
	return nRet;
}


 

 

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值