跳转到帖子
登录关注  
墨香年少

4.duilib's first application : hello world

已推荐帖子

Make sure you have already build duilib's dll or static lib

You can use dll or static lib to build your exe application, in this tutorial, I will use static lib

 

1. create a new project. notice: application type is window not console! so let's create a empty new project.

 

2. Right click project. open setting dialog.

        - [Configuration Properties -> C/C++ -> General] set Additional include DirectoriesD:\duilib\include\DuiLib

        - [Configuration Properties -> C/C++ -> Preprocessor] set Preprocessor DefinitionsUILIB_STATIC

        - [Configuration Properties -> C/C++ -> Code Generation] set Runtime LibrayMulti-threaded(/MT)

        - [Configuration Properties -> Linker -> General] set Additional Library DirectoriesD:\duilib\lib\static

        - [Configuration Properties -> Linker -> Input] set Additional Dependenciesduilib.lib

 

3.make sure Configuration Properties -> Linker -> System : SubSystem's value is : Windows (/SUBSYSTEM:WINDOWS)

 

4. Click Apply, click Ok close dialog.

 

5.make sure you have duilib.lib in D:\duilib\lib\static (you can from http://thinkh5.com/topic/123-3-编译-duilib-静态库/ to learn how to build duilib's static lib (duilib.lib) )

 

OK, let's write some code.

 

6. add a new file named: app.h , copy blow code and past to your vs editor:

#pragma once

#include "UIlib.h"
using namespace DuiLib;

7. add a new file named app.cpp, code:

#include "app.h"

class MainWndFrame : public WindowImplBase
{
protected:
	virtual CDuiString GetSkinFolder() override;
	virtual CDuiString GetSkinFile() override;
	virtual LPCTSTR GetWindowClassName(void) const override;

public:
	static const LPCTSTR kClassName;
	static const LPCTSTR kMainWndFrame;
};

DuiLib::CDuiString MainWndFrame::GetSkinFolder()
{
	return m_PaintManager.GetInstancePath();
}

DuiLib::CDuiString MainWndFrame::GetSkinFile()
{
	return kMainWndFrame;
}

LPCTSTR MainWndFrame::GetWindowClassName(void) const
{
	return kClassName;
}

const LPCTSTR MainWndFrame::kClassName = _T("main_wnd");
const LPCTSTR MainWndFrame::kMainWndFrame = _T("main_wnd.xml");

int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
    _In_opt_ HINSTANCE hPrevInstance,
    _In_ LPWSTR    lpCmdLine,
    _In_ int       nCmdShow)
{
    UNREFERENCED_PARAMETER(hPrevInstance);
    UNREFERENCED_PARAMETER(lpCmdLine);

	// 设置窗口关联的实例
	CPaintManagerUI::SetInstance(hInstance);

	// 设置皮肤的默认路径
	CPaintManagerUI::SetCurrentPath(CPaintManagerUI::GetInstancePath());
	CPaintManagerUI::SetResourcePath(_T("theme"));

	// 创建窗口
	MainWndFrame* pMainWndFrame = new MainWndFrame;
	pMainWndFrame->Create(nullptr, MainWndFrame::kClassName, UI_WNDSTYLE_DIALOG, 0);
	pMainWndFrame->CenterWindow();
	pMainWndFrame->ShowWindow();

	CPaintManagerUI::MessageLoop();

	if (nullptr != pMainWndFrame)
	{
		delete pMainWndFrame;
	}

    return 0;
}

8. not harry to build or run the project, you may notice the string "main_wnd.xml" , whereis this xml file? it's in
 

D:\duilib\project\duilib_hello\Release\theme\main_wnd.xml

and it's code is:

<?xml version="1.0" encoding="UTF-8"?>
<Window size="640,480" caption="0,0,0,35">
	<Font id="0" name="Courier New Bold" size="22" bold="false"/>
	<VerticalLayout>
		<HorizontalLayout bkcolor="#FFff1a1a"/>
		<HorizontalLayout>
			<Button font="0" text="Hello DuQingnian!" bkcolor="#FF00b33c"/>
		</HorizontalLayout>
		<HorizontalLayout bkcolor="#FFffd633"/>
	</VerticalLayout>
</Window>

OK, now we can click build and run

you will get this:

preview.png

 

A small question, how to close this application? you may notice there's no close ico or close button.

So, how to close this application?

You can click the red square in vs editor to close it

 

close.png

 

OK , this hello world tutorial is complete! try it yourself!


目之所及,皆是回忆,心之所想,皆是过往

分享这篇帖子


链接帖子
分享到其他站点

创建帐户或登录来提出意见

你需要成为会员才能提出意见

创建帐户

注册成为会员。只要几个简单步骤!

注册帐户

登录

已有帐户? 请登录。

现在登录
登录关注  

×
×
  • 创建新的...

重要信息

注册必须使用2-8个中文汉字作为账号