Getting Started
本章的目的是让您了解如何基本使用WVL编程。不过在开始这个指南之前,最好将WVL安装到您的计算机系统中。
一个非常简单的WVL应用程序。
即将将创建一个“Hello world”程序来说明一些WVL的基础。
所有的WVL应用程序都必须包含“wvl.h”这个头文件
#include<wvl/wvl.h>
所有的 Windows 应用程序都有一个叫WinMain()的入口函数
int WINAPI
WinMain(HINSTANCE hinstance, HINSTANCE, char*, int)
{
return 0;
}
然后,定义一个窗口来当作启动窗口。
class my_first_form:
public wvl::form
{
public:
my_first_form()
{
this->text("Hello world");
this->show();
}
};
现在,我得到了这个类 my_first_form,并且我将启动一个WVL实例并把它当作启动窗口
wvl::executer<my_first_form>
runner;
runner.run();
好了,我们来看看整个程序
#include<wvl/wvl.h>
class my_first_form: public
wvl::form
{
public:
my_first_form()
{
this->text("Hello
world");
this->show();
}
};
int WINAPI WinMain(HINSTANCE
hinstance, HINSTANCE, char*, int)
{
wvl::executer<my_first_form> runner;
runner.run();
return 0;
}
现在,我想给 my_first_form 这个窗口添加一个按钮,并且单击它就退出程序。因此我给这个类添加了一个私有成员
wvl::button btn_exit_;
并且在创建这个窗口的时候创建这个按钮
btn_exit_.create(*this, "Exit",
wvl::point(100, 50), wvl::size(100, 20));
但是,直到现在按钮btn_exit_
是不没用的,我必须给它安装一个单击事件。在安装事件之前,我先要写一个函数以响应这个单击事件。
void on_click_btn_exit()
{
this->close();
}
好了,现在我有了一个响应函数,我就可以给这个按钮安装单击事件了。
btn_exit_.make_event<wvl::event::mouse_click>(wvl::bind_mem_fun(this,
&my_first_form::on_click_btn_exit));
这个程序完成了。我们来看看这个程序。
#include<wvl/wvl.h>
class my_first_form: public
wvl::form
{
public:
my_first_form()
{
btn_exit_.create(*this,
"Exit", wvl::point(100,
50), wvl::size(100,
20));
btn_exit_.make_event<wvl::event::mouse_click>(wvl::bind_mem_fun(this,
&my_first_form::on_click_btn_exit));
this->text("Hello
world");
this->show();
}
private:
void on_click_btn_exit()
{
this->close();
}
private:
wvl::button btn_exit_;
};
int WINAPI WinMain(HINSTANCE,
HINSTANCE, char*, int)
{
wvl::executer<my_first_form> runner;
runner.run();
return 0;
}
有个重要的概念需要被理解。它就是启动窗口
所谓的启动窗口实际上就是第一个被wvl::executor创建的窗口。我们来看看下面的代码
wvl::executer<my_first_form>
runner;
runner.run();
这个runner将创建一个类 my_first_form的实例, WVL
会管理这个类对象与窗口的影射。如果启动窗口 被关闭了,WVL
将关闭所有的窗口并停止当前实例的消息循环。