I miss VB...

Windows specific questions.
jonbobbly
Posts: 37
Joined: Jun 20, 2007 17:45
Location: Sioux Falls, South Dakota
Contact:

I miss VB...

Post by jonbobbly »

*Begin rant*

When I think of BASIC, I often think of what the word means as well as the first word of the acronym: Beginner's. Don't get me wrong, I'm not complaining about the language, at least not entirely. My gripe is that programming a gui for windows is neither basic nor for beginners. What happened to the one line print "Hello World!" code? Doing this in a windows gui in FB is incredibly complex when comparing to its console version.

I would like to see someone create a library or an IDE that takes care of all the api stuff in the background so that beginners can actually begin to program for windows. Something like what VB does. It takes care of most of the gui stuff behind the scene and leaves that actual coding to the programmer. I'm not saying that WinAPI should be abandoned, but for beginners, there should be a tool that could actually be defined as basic.

I still like FB and think its the greatest thing that happened to programming since QB and will continue use it, but I am frustrated by both the lack of simple tools for programming gui's and my complete inability to find any tutorial on the subject of any real substance.

*End rant*
Mico
Posts: 167
Joined: Oct 14, 2005 6:09
Location: Italy

Post by Mico »

I agree with you 100%. As for how-to info, you have to rely upon C/C++ tutorials, examples, docs, etc., and then turn them into FB working code. It's usually easier than expected. I also found that using FBedit helps a lot. It helps in visual design of forms and controls, although making the GUI work is up to your coding skills. However, FBedit comes with several examples that really help.

When I wrote my first GUI program in FB I felt like a kid who just learned to ride his bicycle, but I'm afraid that when it comes to more complex GUI projects, VB is still the way to go. The need for run-time libraries was a typical con for VB projects, but now those libraries are almost ubiquitary, so as long as you're not using special controls, you can just distribute the executable file. The bottom line is that I'm writing all my console applications in FB and 99% of the GUI ones in VB, but, yes, I'd really love a FB-only solution.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

For Windows only VB is a realy fast (with optimation enabled)
and a good choice runtimes now a part of the Windows OS.

I renamed the link.exe to link_org.exe and wrote
a short linker stub so i can use optional params.

/DLL or /STACK ...
it makes it easy to create high optimized real (none ActiveX) *.DLL's
usable with any Windows compiler that can use *.DLL's of course fbc too.

I wrote my own OpenGL.tlb (with midl.exe only to learn)
and an ODE C wrapper in the past (VB can't use CDECL callbacks)
the optimized VB versions are ~4 times faster as fbc without an optimation stage.

In a real application with many rigid bodys and collision detection
it is an big deal to have 100 or only 25 fps
(for less error's in physics the timestep must be short 1/100fps is better than 1/25fps)

back to the topic :-)
If you will use the VB GUI classes in FreeBASIC simple create
a real *.dll with VB put all forms and GUI elements in it.

Only one more step is needed if the VB DLL is loaded from FreeBASIC
you can't use "set MyForm=Form1" inside the VB DLL you have to use
DllGetClassObject() inside the real DLL (only ActiveX DLL's will init the com interface for you)
here are an link about this GUI stuff in a dll.

http://www.xtremevbtalk.com/showthread.php?t=282796
(can be you must logged in to download the *.zip and *.pdf file)


Other things are possible too
you can raise event's from the VB DLL to FreeBASIC
and raise events from FreeBASIC to the VB DLL

Joshy
Last edited by D.J.Peters on Jul 12, 2008 18:26, edited 1 time in total.
notthecheatr
Posts: 1759
Joined: May 23, 2007 21:52
Location: Cut Bank, MT
Contact:

Post by notthecheatr »

You can still write the beginner's Hello, World program - just not in Windows. I don't see what the problem is... FB is a hell of a lot easier to use than most languages, there's a big community to help, and lots of tutorials too. I liked VB too, at one point, when I was learning. However, once I learned real programming I liked it a whole lot better. VB doesn't really give you a lot of options, and the knowledge you gain using VB can't be carried over into other languages. And with all the wealth of information online, it's not nearly as hard to learn Windows programming as I had expected it to be. I would recommend just learning proper programming practice in general first (if you haven't already, I'm not trying to insult you if you have), writing console programs or whatever. Or simple game engines or the like. Easy stuff, get a feel for programming in general so you don't get swamped by all the new stuff Windows programming forces you to do. And remember, you have a big community, lots of people willing to help :)

For GUI, btw, I prefer wx-c. Less people use it, but it's kinda nice.
v1ctor
Site Admin
Posts: 3804
Joined: May 27, 2005 8:08
Location: SP / Bra[s]il
Contact:

Post by v1ctor »

Well, there were several attempts to make simple/easy to use GUI libraries for FB, but most received almost no feedback, and you know, nobody here is working for money or such, if users don't offer any response, the lib authors will just give up working on them or develop the libs just for their personal use, it depends 100% on the community..

If someone is waiting for an "official" GUI from the FB compiler devs, that won't ever happen. There are tons of work to do on the compiler itself, and writing *and* maintaining a complete (cross-platform) GUI library is impossible with just a few coders like we have at the moment, unfortunately.
JohnK
Posts: 279
Joined: Sep 01, 2005 5:20
Location: Earth, usually
Contact:

Post by JohnK »

Well, there were several attempts to make simple/easy to use GUI libraries for FB, but most received almost no feedback, and you know, nobody here is working for money or such, if users don't offer any response, the lib authors will just give up working on them or develop the libs just for their personal use, it depends 100% on the community..
I totally agree here. But I really think a strong GUI is important for the future of FB, because I predict in 5 years from now there will be many more GUI users than DOS users. FB would become interesting to only a small number of people.

There was a GUI lib started by N. Eodor that I thought was really nice, but WIN only. There was a lot of work on WX windows but last I looked, it isn't the easiest code to read and requires a very large runtime.

The talent is there in the community, they just need a lot of support. (My approach was to use RapidQ as the GUI and FreeBasic as the computational engine). I on the other hand absolutely hate .NET -- I thought it was the largest waste of money. It is not BASIC, not C, not Java, what the hell is it?
-JK
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Post by MichaelW »

I miss VB...
I don’t. The basic concept is very good, but every implementation I have used is more or less bad. The first versions were easy to use, but you had to be willing to accept limited functionality and a crappy looking GUI, and getting around just some of these problems typically required far too much knowledge and effort. The later versions have progressively improved the built-in functionality and appearance, but in the process ease of use has been more or less lost. If I were coding large applications I might look at it differently, but for what I do I prefer API code combined with a few macros and procedures to automate the most common tasks.
jonbobbly
Posts: 37
Joined: Jun 20, 2007 17:45
Location: Sioux Falls, South Dakota
Contact:

Post by jonbobbly »

JohnK wrote:
Well, there were several attempts to make simple/easy to use GUI libraries for FB, but most received almost no feedback, and you know, nobody here is working for money or such, if users don't offer any response, the lib authors will just give up working on them or develop the libs just for their personal use, it depends 100% on the community..
I totally agree here. But I really think a strong GUI is important for the future of FB, because I predict in 5 years from now there will be many more GUI users than DOS users. FB would become interesting to only a small number of people.

[...]

-JK
I totally agree. If FreeBASIC is going to gain popularity, it must do it through ease of use, and for modern computers, that means GUI's. Wouldn't be nice to have the ability to just write code like this?

Code: Select all

 dim as Window main
 main.add.button(x,y,btn1)
 sub btn1.onclick()
  MsgBox("Hi.")
  main.close
 end sub
ciw1973
Posts: 157
Joined: Jun 12, 2007 15:03
Location: Isle of Man (United Kingdom)

Post by ciw1973 »

You know, wxWidgets isn't a million miles away from the pseudo-code you've just suggested, although you need to do things like actually displaying the window and jumping into an event loop, but that's the same with any GUI toolkit (even VB) and they're only single lines of code anyway. Unlike GTK+ you only need to distribute a single DLL/SO with you application, which is a definite plus.

I've written full commercial applications with it, although they were in Python not FreeBASIC, but the actual GUI code is almost identical. Definitely well worth checking out.

Of course, GTK+ comes with the truly wonderful Glade to enable you to interactively build UIs and will save you quite a bit of work if you're designing anything more than trivial interfaces, and literally hours if you're making frequent changes to the interface. As a result it's usually worth the overhead and hassle of installing GTK+ on Windows, and it'll already be installed if your target system is running Linux.
ciw1973
Posts: 157
Joined: Jun 12, 2007 15:03
Location: Isle of Man (United Kingdom)

Post by ciw1973 »

OK, so now I think about it there are a handful of messy things that you need to do to create GUIs in wxWidgets, so I've quickly put together a set of macros in the form of an include file ("wxHelper.bi") as follows:

Code: Select all

#include once "wx-c/wx.bi"

#macro CreateWindow( _object, _title, _width, _height )
    _object = wxFrame( )
   	wxFrame_Create( _object, 0, -1, _title, wxSize( _width, _height ), wxSize( -1, -1 ), wxDEFAULT_FRAME_STYLE, "frame" )
#endmacro

#macro AddButton( _parent, _object, _caption, _x, _y, _click_event )
    dim as wxButton ptr _object = wxButton()
   	wxbutton_create( _object, _parent, 1001, _caption, wxsize( _x, _y ), wxSize( -1, -1 ), 0, 0, 0 )
   	wxEvtHandler_proxy( _object, @_click_event )
   	wxEvtHandler_connect( _object, wxEvent_EVT_COMMAND_BUTTON_CLICKED(), 1001, -1, 0 )
#endmacro

#macro InitWx()
    dim shared as wxApp ptr app
    
    function app_onexit () as integer
        function = wxApp_OnExit( app )
    end function
#endmacro

#macro StartWx()
    function app_oninit() as integer
#endmacro

#macro RunWx()
        function = wxApp_OnInit( app )
    end function
    
    app = wxApp( )
    wxApp_RegisterVirtual( app, @app_oninit, @app_onexit)
    wxApp_Run( 0, 0 )
    end 0
#endmacro

#macro AddPanel( _parent, _object )
    dim as wxPanel ptr panel = wxPanel()
   	wxPanel_Create( _object, _parent, -1, 0, 0, 0, 0 )
#endmacro

#macro MsgBox( _message )
    wxMsgBox( 0, _message, "", 0, wxSize( -1, -1 ) )
#endmacro

#macro CloseWindow( _object )
    wxWindow_Close( _object, 0 )
#endmacro

#macro ShowWindow( _object )
    wxWindow_Show( _object, 1 )
#endmacro

#macro DimWindow( _object )
    dim shared as wxFrame ptr _object
#endmacro

#macro DeclareCallBack( _name )
    declare sub _name (byval event as wxEvent ptr, byval iListener as integer)
#endmacro

#macro CallBack( _name )
    sub _name (byval event as wxEvent ptr, byval iListener as integer)
#endmacro

#macro EndCallBack()
    end sub
#endmacro
Which allows you to do the following:

Code: Select all

#include once "wxHelper.bi"

InitWx()

DimWindow ( mywin )

CallBack( button_clicked )
    MsgBox ( "Hi" )
    CloseWindow ( mywin )
EndCallBack()

StartWx()
    CreateWindow ( mywin, "My Window", 400, 200 )
    AddPanel ( mywin, panel )
    AddButton ( panel, exitbutton, "Click Me", 160, 90, button_clicked)
    ShowWindow ( mywin )
RunWx()
Which I hope is the sort of thing people have been looking for in this thread.

I've only put together macros for the basics to match jonbobbly's pseudo-code, but I'll expand this over the next week so it's more complete and useful for writing actual GUI apps.
Last edited by ciw1973 on Jul 24, 2007 22:15, edited 1 time in total.
sir_mud
Posts: 1401
Joined: Jul 29, 2006 3:00
Location: US
Contact:

Post by sir_mud »

GTK+ installation on windows has got alot better and can even look good now :p. You don't have to distribute all of GTK if your application doesn't use all of the functions, just a couple. Easiest way is to move a dll, run, if it doesn't run put the dll back and try another :p
notthecheatr
Posts: 1759
Joined: May 23, 2007 21:52
Location: Cut Bank, MT
Contact:

Post by notthecheatr »

ciw1973 wrote:You know, wxWidgets isn't a million miles away from the pseudo-code you've just suggested, although you need to do things like actually displaying the window and jumping into an event loop, but that's the same with any GUI toolkit (even VB) and they're only single lines of code anyway. Unlike GTK+ you only need to distribute a single DLL/SO with you application, which is a definite plus.
Exactly. Nothing with GUI development is simple, and there's no way you can expect other people to do all the work for you. If you want a simple to use GUI library, write one yourself! Otherwise, use one of the ready-made ones, which aren't really as bad as they might look at first. It'll be a good learning experience! Plus, we'll all respect you more!

As for the comment about "I predict GUI will be more used than console" that's true, it already is. That doesn't mean people will be any less interested in FreeBasic though. Look at what is probably the most popular language in existence - C. Or, if you prefer, C++. You have to write code in those to get any GUI. I don't see what the difference is. FreeBasic will live for a long time because it's a great language. And easy to learn. There's no such thing as a one-line Hello, World for GUI. Visual Basic was easy to learn but if you wanted your programs to do anything significant you had to learn about much harder concepts and little quirks and strange things in the language.

note: I'm not trying to be inflammatory here, so I apologize if it comes off that way. I'm just trying to point out the simple facts, as I see them.
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Post by MichaelW »

The main problem with wxWidgets and similar is that you have to learn a large and complex API, to create a GUI that has been more or less compromised in the process of making it cross platform. If you need cross platform then such toolkits make good sense, but if you develop only for Windows then IMO they do not.

Using the tools here, you can have direct access to the Windows API, allowing you to do almost anything that the Windows API can do, and still do the common stuff as easy as this:

Code: Select all

#include "dialogs.bas"

function DialogProc( byval hDlg as  HWND, _
                     byval uMsg as UINT, _
                     byval wParam as WPARAM, _
                     byval lParam as LPARAM ) as integer

  select case uMsg

    case WM_COMMAND

      if loword(wParam) = 100 then

        MessageBox( hDlg, "Hi", "", 0 )

      elseif loword(wParam) = IDCANCEL then

        EndDialog( hDlg, null )

      end if

    case WM_CLOSE

      EndDialog( hDlg, null )

  end select

  return 0

end function

dim as LPDLGTEMPLATE lpdt

Dialog( 1, 0, 0, 80, 60, "My Window", lpdt, _
        WS_OVERLAPPEDWINDOW or DS_CENTER )

DefPushButton( 100, -1, 40, 40, 12, "Click Me" )

CreateModalDialog( 0, @DialogProc, 0, lpdt )
ciw1973
Posts: 157
Joined: Jun 12, 2007 15:03
Location: Isle of Man (United Kingdom)

Post by ciw1973 »

wxWdigets (and to a lesser extent GTK+, but that has Glade to help you out) is *much* less complex API than native Win32 for building GUI apps, and as long as distributing the library as well as you application isn't a problem, then it makes sense to use it and have your application cross-platform by default and with no real additional work.

With one or two minor exceptions, all of the applications I have developed recently have been for clients running Windows, but it's always nice to know that if need to deploy to Linux or maybe one day OS X, then I can do so without needing to change to another GUI toolkit.

The main advantage with wxWidgets is that it uses the controls from the underlying GUI anyway, so it acts as a handy abstraction layer and your end-user sees something which looks and acts in the way they expect.
anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California

Post by anonymous1337 »

I don't see how a GUI would appear crucial to an FB user unless you come from a VB background. Take the VISUAL out of VB and you would probably receive a C-like compiler from MS :P

I do see GUI libraries as very important, but I do hate visual type coding, and event-driven programming isn't my forte. I feel like I'm coding on the web in those cases (even worse, on the web with a visual editor :P). I've never been able to use a GUI Editor for anything beyond trivial programs. I like reading code and seeing all of it as I make things.

Libraries are important for this case I suppose, because so much of Windows API code especially will end up hundreds of lines just for a few elements in your program, what really bothers me about Windows development... I absolutely do not want a visual editor implemented directly in FB, however. I don't see why we'd need that.
Post Reply