您的位置:首页 > 产品设计 > UI/UE

DuiLib学习(一)

2016-06-24 18:12 351 查看
教程: http://www.cnblogs.com/Alberl/p/3343579.html
这个是邓学彬的博客 Duilib 导航帖:http://blog.csdn.net/cometnet/article/details/12448339

看了这个教程还是有那么一点蛋疼,就是老提示下面这个错误。



不过已经解决了,在包含 UIlib.h 之前包含 ObjBase.h 即可。

我的解决方案名字叫 test2。

stdafx.h:

// stdafx.h : 标准系统包含文件的包含文件,
// 或是经常使用但不常更改的
// 特定于项目的包含文件
//

#pragma once

#include "targetver.h"

#define WIN32_LEAN_AND_MEAN             // 从 Windows 头中排除极少使用的资料
// Windows 头文件:
#include <windows.h>

// C 运行时头文件
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>

// TODO: 在此处引用程序需要的其他头文件
#include <ObjBase.h>
#include <UIlib.h>
using namespace DuiLib;

#ifdef _DEBUG
#   ifdef _UNICODE
#       pragma comment(lib, "DuiLib_ud.lib")
#   else
#       pragma comment(lib, "DuiLib_d.lib")
#   endif
#else
#   ifdef _UNICODE
#       pragma comment(lib, "DuiLib_u.lib")
#   else
#       pragma comment(lib, "DuiLib.lib")
#   endif
#endif

test2.cpp:

// test2.cpp : 定义应用程序的入口点。
//

#include "stdafx.h"
#include "test2.h"

class CDuiFrameWnd : public CWindowWnd, public INotifyUI
{
public:
virtual LPCTSTR GetWindowClassName() const { return _T("DUIMainFrame"); }
virtual void    Notify(TNotifyUI& msg) {}

virtual LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
LRESULT lRes = 0;

if( uMsg == WM_CREATE )
{
CControlUI *pWnd = new CButtonUI;
pWnd->SetText(_T("Hello World"));   // 设置文字
pWnd->SetBkColor(0xFF00FF00);       // 设置背景色

m_PaintManager.Init(m_hWnd);
m_PaintManager.AttachDialog(pWnd);
return lRes;
}

if( m_PaintManager.MessageHandler(uMsg, wParam, lParam, lRes) )
{
return lRes;
}

return __super::HandleMessage(uMsg, wParam, lParam);
}

protected:
CPaintManagerUI m_PaintManager;
};

int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
CPaintManagerUI::SetInstance(hInstance);

CDuiFrameWnd duiFrame;
duiFrame.Create(NULL, _T("DUIWnd"), UI_WNDSTYLE_FRAME, WS_EX_WINDOWEDGE);
duiFrame.ShowModal();
return 0;
}

效果图:



总结:

stdafx.h 中  包含 ObjBase.h   和 UIlib.h 并且 链接 lib 库

test2.cpp 中 新建一个 class 继承 CWindowWnd 和 接口类  INotifyUI 。

知识点:

①GetWindowClassName 后面的const 表明这个函数只是一个只读函数,返回的值为窗口类名。

②Notify为通告消息处理函数。

③HandleMessage为窗口消息处理函数。

④CPaintManagerUI为UI管理类,HelloWord中整个绿色区域为一个CButtonUI
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: