Help for the Hello World start

Apr 20, 2014 at 1:11 PM
Hi,
I downloaded nana-0.63 C03 version, for Windows.
I used VS2005 (VC8), opened the included VC8 solution file, and compiled and got the static lib file.
For a start, I was trying the provided Hello World smaple, from: http://sourceforge.net/p/nanapro/blog/2012/11/preliminary-study-of-nana-c-library/.
To do this, I created, using VS2005, a new console project, using Windows library, unicode, DEBUG build mode, using the compiled nana static lib, and copied the code(amended) from above address, as
#include <nana/gui/wvl.hpp>
#include <nana/gui/widgets/button.hpp>
int _tmain(int argc, _TCHAR* argv[]) {
    using namespace nana::gui;
    form fm;
    fm.caption(L"Hello, World!");
    button btn(fm, nana::rectangle(20, 20, 150, 30));
    btn.caption(L"Quit");
    btn.make_event<events::click>(API::exit);
    fm.show();
    exec();
    return 0;
}
Everything seemed fine, except the running result got two windows, one is Nana GUI form (expected), and the other is the Windows DOS console black window.

I did previously have the experience that creating a Window GUI based on a console project. But I am not sure how Nana is designed for.
So my simple question is: what happened to me? and how can I use Nana to create a GUI application without the console window?

THX

dunson
Coordinator
Apr 20, 2014 at 5:07 PM
You should create a Win32 Project which uses WinMain() for the entry defaultly.
Apr 20, 2014 at 11:21 PM
Hi jinhao,

Sorry my previous link was wrong for the sample code(they are similar though). The real link is http://nanapro.org/help/hello_world.htm.

So that tutorial is indeed not for Windows. I'll try on the Win32 Windows mode.


Thanks
Apr 21, 2014 at 2:57 AM
Hi Jinhao,

WOW! Totally different.
I created a Win32 Windows project. At the beginning, I was wondering for adapting your code into this project. It just can not be using "main()" or "_tmain()". I used the IDE created _tWinMain(), took off every original code inside it and used your sample code, as below:
// // File "main.cpp"
#include "stdafx.h"
#include <nana/gui/wvl.hpp>
#include <nana/gui/widgets/button.hpp>
#include "main.h"
int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
    UNREFERENCED_PARAMETER(hPrevInstance);
    UNREFERENCED_PARAMETER(lpCmdLine);
    using namespace nana::gui;
    form fm;
    fm.caption(L"Hello, World!");
    button btn(fm, nana::rectangle(20, 20, 150, 30));
    btn.caption(L"Quit");
    btn.make_event<events::click>(API::exit);
    fm.show();
    exec();
    return 0;
}
It worked. I got the GUI form (or dialog) pop up.

I think it's a good start for trying the way which seems to provide a solution for more easily logical thinking, less coding. The coding style makes me feeling that I could put more time on business logic instead of focusing on language tricks and Windows system themselves, and this is still in C++.

Many Thanks

dunson