1. 程式人生 > >[原始碼]Nana GUI示例程式碼

[原始碼]Nana GUI示例程式碼

關於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;
}

如有什麼意見或問題,歡迎交流。