C++杂记 05/08/2011 开始一个完整的WTL例子
来源:互联网 发布:ubuntu ibus 设置 编辑:程序博客网 时间:2024/06/07 15:32
1. 生成empty win32 project
2. 加入My1stWTL70Win.cpp
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow)
{...}
int Run(LPTSTR /*lpstrCmdLine*/ = NULL, int nCmdShow = SW_SHOWDEFAULT)
{...}
3. 添加MyMainWnd Class
class MyMainWnd : public CFrameWindowImpl<MyMainWnd>
{
public:
MyMainWnd();
virtual ~MyMainWnd();
};
Error:
MyMainWnd.cpp
d:/study/wtl/hellowtl70/my1stwtl70win/mymainwnd.h(12) : error C2504: 'CFrameWindowImpl' : base class undefined
d:/study/wtl/hellowtl70/my1stwtl70win/mymainwnd.h(12) : error C2143: syntax error : missing ',' before '<'
d:/study/wtl/hellowtl70/my1stwtl70win/mymainwnd.h(12) : error C2059: syntax error : '<'
Error executing cl.exe.
4. 去掉MyMainWnd.cpp文件,OK ?
最后的结果,一个空的windows。相关代码如下:
#include "stdafx.h"
#include <atlframe.h>
#include <atlctrls.h>
#include <atldlgs.h>
#include <atlctrlw.h>
#include "MyMainWnd.h"
CAppModule _Module;
int Run(LPTSTR /*lpstrCmdLine*/ = NULL, int nCmdShow = SW_SHOWDEFAULT)
{
CMessageLoop theLoop;
_Module.AddMessageLoop(&theLoop);
//CMainFrame wndMain;
MyMainWnd wndMain;
if(wndMain.CreateEx() == NULL)
{
ATLTRACE(_T("Main window creation failed!/n"));
return 0;
}
wndMain.ShowWindow(nCmdShow);
int nRet = theLoop.Run();
_Module.RemoveMessageLoop();
return nRet;
}
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;
}
注:此程序在关闭窗口后,进程并没有消失,奇怪!!!
5. 增加一个view: MyView
Error:
Compiling...
My1stWTL70Win.cpp
d:/study/wtl/hellowtl70/my1stwtl70win/mymainwnd.h(19) : error C2146: syntax error : missing ';' before identifier 'myView'
d:/study/wtl/hellowtl70/my1stwtl70win/mymainwnd.h(19) : error C2501: 'MyView' : missing storage-class or type specifiers
d:/study/wtl/hellowtl70/my1stwtl70win/mymainwnd.h(19) : error C2501: 'myView' : missing storage-class or type specifiers
Error executing cl.exe.
A: 在MyMainWnd.h中加入头文件:
#include "MyView.h"
Compile OK ! ( WHY wizard-generated files have no such issue ?! 头文件被引入的顺序有关系?)
**** 目前状态 ****
窗口显示出来了,但view里面没有东东。
这里有一篇文章讲WTL消息处理的:http://blog.csdn.net/fengrx/archive/2009/05/09/4163169.aspx
6. 让View显示东东,终于搞定!
主要修改:在Message map中增加 CHAIN_MSG_MAP(CFrameWindowImpl<MyMainWnd>)
MyMainWnd.h的完整代码如下:
#include "MyView.h"
class MyMainWnd : public CFrameWindowImpl<MyMainWnd>//, public CUpdateUI<MyMainWnd>
{
public:
DECLARE_FRAME_WND_CLASS(NULL, NULL)
MyView myView;
MyMainWnd(){}
virtual ~MyMainWnd(){}
BEGIN_MSG_MAP(MyMainWnd)
MESSAGE_HANDLER(WM_CREATE, OnCreate)
//CHAIN_MSG_MAP(CUpdateUI<MyMainWnd>)
CHAIN_MSG_MAP(CFrameWindowImpl<MyMainWnd>)
END_MSG_MAP()
public:
LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
m_hWndClient = myView.Create(m_hWnd, rcDefault, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, WS_EX_CLIENTEDGE);
CMessageLoop* pLoop = _Module.GetMessageLoop();
ATLASSERT(pLoop != NULL);
return 0;
}
};
- C++杂记 05/08/2011 开始一个完整的WTL例子
- VC杂记 2011/05/22 WTL
- 如何使用epoll?一个完整的C例子
- 一个完整的MapXtreme例子
- 一个完整的AjaxPro例子
- log4j :一个完整的例子
- 一个完整的hibernate例子
- NHibernate一个完整的例子
- 一个完整的Socket例子
- Ehcache的一个完整例子
- 完整的一个表单例子
- 从Spring For Android开始对Android的研究——一个完整的例子
- 杂记 05/07/2011-3 正式学习WTL
- 杂记 05/07/2011-3 正式学习WTL
- 一个完整的extjs的GridPanel例子
- 一个完整的 epoll + socket 的例子
- 一个完整的ldap操作的例子
- 一个完整的负载均衡的例子
- 堆栈的区别
- String深入学习笔记
- 安装flex包
- Visual C++6.0初学者实用技巧(基础)
- iframe中页面如果有验证导致重复出现页面的问题
- C++杂记 05/08/2011 开始一个完整的WTL例子
- 个人日常信息管理
- 线程基本知识点,必须知道的
- C++ 类与对象
- Oracle基础知识--内存参数设置
- Enzymatic extraction extracting the technology of safflower yellow pigment
- 二分法查找[折半查找][Java实现]
- java线程同步,必须知道的
- 权限管理的设计