[源代码]Nana GUI示例代码

作者: NickYang 分类: 技术文章,程序开发 发布时间: 2012-09-25 09:22

关于nana的介绍,可以查看《[GUI]nana GUI初尝试》,本文主要是分享其中UI的实现代码。

#include <tchar.h>
#include <Windows.h>
#include <iostream>
#include <nana/gui/wvl.hpp>
#include <nana/gui/basis.hpp>
#include <nana/gui/widgets/label.hpp>
#include <nana/gui/widgets/textbox.hpp>
#include <nana/gui/widgets/combox.hpp>
#include <nana/gui/widgets/button.hpp>
#include <nana/paint/image.hpp>
#include <nana/paint/graphics.hpp>
#include <nana/gui/layout.hpp>
#include <nana/gui/widgets/picture.hpp>

int APIENTRY _tWinMain(HINSTANCE hInstance,
	HINSTANCE hPrevInstance,
	LPTSTR    lpCmdLine,
	int       nCmdShow)
{
	// 设置窗体属性
	nana::gui::form my_form(nana::gui::API::make_center(450, 220), 
		nana::gui::appearance(true, true, false, false, true, false, false));
	my_form.caption(STR("Webpage2Image By eliteYang"));

	nana::gui::API::window_icon(my_form, nana::paint::image(STR("small.ico")));

	// 窗体背景图
	nana::paint::image image_bg;
	bool bOpen = image_bg.open(STR("bg.png"));
	nana::gui::drawing drawing_bg(my_form);  
	drawing_bg.clear();  
	drawing_bg.bitblt(0, 0, 450, 220, image_bg, 0, 0);  
	drawing_bg.update(); 

	// 设置label显示
	nana::gui::label my_label(my_form, 10, 10, my_form.size().width - 10, my_form.size().width - 10);
	my_label.format(true);
	my_label.transparent(true);
	my_label.caption(STR("<bold=true, color=0xff0000, font=\"Consolas\">\
<color=0x000000>Notes :</>This is a tiny program to show how save a html webpage\
        to an image.\n\n\
<color=0x000000>Author:</>eliteYang\n\n\
<color=0x000000>Blog  :</><color=0x0000ff, url=\"http://www.cppfans.org\">http://www.cppfans.org\
<bold=false, italic=true, color=0xff0000>(Click url to access my blog)</></></>"));

	// 设置输入框
	nana::gui::label my_label_input(my_form, 10, 122, 80, 80);
	my_label_input.format(true);
	my_label_input.transparent(true);
	my_label_input.caption(STR("Website url:"));

	// url输入框
	nana::gui::textbox my_text_box_url(my_form, 80, 120, 200, 20);
	my_text_box_url.border(true);
	my_text_box_url.multi_lines(false);

	// 保存格式组合框
	nana::gui::combox my_combox_format(my_form, 290, 120, 60, 20);
	my_combox_format.push_back(STR("PNG"));
	my_combox_format.push_back(STR("JPG"));
	my_combox_format.push_back(STR("BMP"));
	my_combox_format.push_back(STR("GIF"));
	my_combox_format.push_back(STR("TIFF"));
	my_combox_format.option(0);

	// button
	// TODO:GetUrlImage
	nana::gui::button btn(my_form, my_form.size().width / 2 - 75, 160, 150, 30);
	btn.caption(STR("Get Image"));
	btn.make_event<nana::gui::events::click>(nana::gui::API::exit);

	my_form.show();
	nana::gui::exec();

	return 0;
}

如有什么意见或问题,欢迎交流。

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!

发表评论

电子邮件地址不会被公开。 必填项已用*标注