wxWidgets for FreeBASIC?

New to FreeBASIC? Post your questions here.
TheDcoder
Posts: 44
Joined: Jul 09, 2016 11:43
Location: India
Contact:

Re: wxWidgets for FreeBASIC?

Post by TheDcoder »

St_W wrote: You need to download IUP, without the libraries it simply can't work.
...
And please read some documentation about libraries as you don't seem to have much of a clue yet how they work:
https://freebasic.net/wiki/ProPgPrebuiltLibraries
https://freebasic.net/wiki/ProPgSharedLibraries
https://freebasic.net/wiki/ProPgStaticLibraries
Sorry, I thought that the libraries were already shipped with FreeBASIC, my bad.

About understanding how libraries work, I only have a limited idea... I started my programming journey with AutoIt, which has BASIC syntax, I am only familiar with using simple If...Else statements and simple functions like MsgBox or Sleep. FreeBASIC is too "complex" for me, pointers and whatnot, most of it is very alien for me, but I can't fully blame it on the language.

I will have a good read at the mentioned links. Thanks to everyone who has posted, I have gained a wealth of information.

I am thinking of renaming this thread's title to something more relevant, something like "GUI programming - wxWidgets and other GUI foundations for FreeBASIC"
St_W
Posts: 1626
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: wxWidgets for FreeBASIC?

Post by St_W »

For using libraries in C-like languages one needs the library (during linking) and the header files (during compilation). FB ships only with the header files (because those are FB-specific, while the library is not).

The header files describe the interface of the library, so that you can e.g. call functions in the library from your code. They e.g. specify the number and types of parameters so that the compiler can check those.

The library file contains the actual code (the implementation) of the library's functions, etc. There are two types: static and dynamic. Static libraries are fully integrated into your final executable (and thus the library isn't needed anymore at runtime). Dynamic libraries are loaded (and thus needed) at runtime and only a very small part of it (import library) is integrated into your executable.

That was a simplified (and probably not 100% accurate) description of some of the most important things you should know about libraries. For details have a look into the articles in the wiki I've already referred to previously.
TheDcoder
Posts: 44
Joined: Jul 09, 2016 11:43
Location: India
Contact:

Re: wxWidgets for FreeBASIC?

Post by TheDcoder »

Thanks for the quick explanation. In AutoIt it is only possible to interact with dynamic libraries by calling the "DllCall" function
Kuan Hsu
Posts: 586
Joined: Sep 16, 2007 15:12
Location: Taiwan

Re: wxWidgets for FreeBASIC?

Post by Kuan Hsu »

Munair wrote:The two errors regarding different pointer types apply to these two lines in the example file buttons.bas:

Code: Select all

IupSetFunction( "ok_act", @ok_onclick ) 
IupSetFunction( "close_act", @close_onclick )
These errors are related to binding definitions.
Use "cast"

Code: Select all

IupSetFunction( "ok_act", cast( Icallback, @ok_onclick ) )
IupSetFunction( "close_act", cast( Icallback, @close_onclick ) )
St_W
Posts: 1626
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: wxWidgets for FreeBASIC?

Post by St_W »

Kuan Hsu wrote:Use "cast"
Better change the return type of the functions to "long", then a cast isn't needed and it will work fine for 64-bit builds too. (or did I miss something?)
Munair
Posts: 1286
Joined: Oct 19, 2017 15:00
Location: Netherlands
Contact:

Re: wxWidgets for FreeBASIC?

Post by Munair »

Kuan Hsu wrote:
Munair wrote:The two errors regarding different pointer types apply to these two lines in the example file buttons.bas:

Code: Select all

IupSetFunction( "ok_act", @ok_onclick ) 
IupSetFunction( "close_act", @close_onclick )
These errors are related to binding definitions.
Use "cast"

Code: Select all

IupSetFunction( "ok_act", cast( Icallback, @ok_onclick ) )
IupSetFunction( "close_act", cast( Icallback, @close_onclick ) )
I changed type 'integer' to 'long' in the example file, which seemed to do the trick.
lizard
Posts: 440
Joined: Oct 17, 2017 11:35
Location: Germany

Re: wxWidgets for FreeBASIC?

Post by lizard »

For my project i use wx-c with above mentioned designer, and it is almost finished, so i dont want to switch to fltk-c or iup. After creating the main skeleton program with designer one can use the examples of designer in combination with the .bi files. There are a huge number of additional functions. Most of them work out of the box.

If "clientdc01.bas" is used for example:

Code: Select all

#Include "wx-c/wx.bi"

Dim Shared As wxPanel Ptr panel
Dim Shared As wxTextCtrl Ptr textCtrl
Dim Shared As wxApp Ptr app

Sub EventHandler WXCALL ( event As wxEvent Ptr, iListener As wxInt )
  ' allocate a client DC
  Dim As wxDC Ptr dc = wxClientDC_ctor2(Panel)
  ' use it
  wxDC_Clear(dc)
  For i As Integer = 1 To 3
    wxDC_DrawCircle(dc, Rnd*640, Rnd*480, 1+Rnd*240)
  Next
  For i As Integer = 1 To 30
    wxDC_DrawLine(dc, Rnd*640, Rnd*480, Rnd*640, Rnd*480)
  Next
  For i As Integer = 1 To 10
    wxDC_DrawRotatedText(dc, wxString_ctorUTF8("Hello World!"), Rnd*640, Rnd*480, Rnd*360)
  Next
  ' release it
  wxDC_dtor(dc)
End Sub

Function OnInit WXCALL As wxBool
  Dim As wxFrame Ptr frame = wxFrame_ctor()
  wxFrame_Create(frame, WX_NULL, -1, wxString_ctorUTF8("wxClientDC"), -1, -1, 640, 480, _
               wxFRAME_DEFAULT_STYLE Or wxCLOSE_BOX _
               Xor wxMAXIMIZE_BOX Xor wxRESIZE_BORDER)
               
  panel = wxPanel_ctor2(frame, -1, -1, -1 , -1, -1 , 0, WX_NULL)
  
  Dim As _wxButton Ptr button = wxButton_ctor()
  wxButton_Create(button, panel, -1, wxString_ctorUTF8("click me"), 70, 270, 250, 60)
  wxEvtHandler_proxy(button, @EventHandler)
  wxEvtHandler_Connect(button, wxEvent_EVT_COMMAND_BUTTON_CLICKED(), -1, -1, 0)

  wxWindow_Show(frame,WX_TRUE)
  
  Return wxApp_OnInit(app)
End Function

Function OnExit WXCALL As wxInt
  Return wxApp_OnExit(app)
End Function

app = wxApp_ctor()
wxApp_RegisterVirtual(app, @OnInit, @OnExit)
wxApp_Run()
One could go to "freebasic/inc/wx-c folder and use all the functions from "dc.bi" (which is already included from "wx.bi"):

Code: Select all

#Ifndef __dc_bi__
#Define __dc_bi__

#Include Once "common.bi"

' class wxDC
Declare Sub wxDC_dtor WXCALL Alias "wxDC_dtor" (self As wxDC Ptr)
Declare Function wxDC_Ok WXCALL Alias "wxDC_Ok" (self As wxDC Ptr) As wxBool
Declare Sub wxDC_DrawBitmap WXCALL Alias "wxDC_DrawBitmap" (self As wxDC Ptr, bitmap As wxBitmap Ptr, x As wxCoord, y As wxCoord, transp As wxBool)
Declare Sub wxDC_DrawPolygon WXCALL Alias "wxDC_DrawPolygon" (self As wxDC Ptr, n As wxInt, pPonts As wxPoint Ptr, xoffset As wxCoord, yoffset As wxCoord, fill_style As wxPolygonFillStyle)
Declare Sub wxDC_DrawLine WXCALL Alias "wxDC_DrawLine" (self As wxDC Ptr, x1 As wxCoord, y1 As wxCoord, x2 As wxCoord, y2 As wxCoord)
Declare Sub wxDC_DrawRectangle WXCALL Alias "wxDC_DrawRectangle" (self As wxDC Ptr, x1 As wxCoord, y1 As wxCoord, x2 As wxCoord, y2 As wxCoord)
Declare Sub wxDC_DrawText WXCALL Alias "wxDC_DrawText" (self As wxDC Ptr, txt As wxString Ptr, x As wxInt, y As wxInt)
Declare Sub wxDC_DrawEllipse WXCALL Alias "wxDC_DrawEllipse" (self As wxDC Ptr, x As wxInt, y As wxInt, w As wxInt, h As wxInt)
Declare Sub wxDC_DrawPoint WXCALL Alias "wxDC_DrawPoint" (self As wxDC Ptr, x As wxInt, y As wxInt)
Declare Sub wxDC_DrawRoundedRectangle WXCALL Alias "wxDC_DrawRoundedRectangle" (self As wxDC Ptr, x As wxInt, y As wxInt, w As wxInt, h As wxInt, radius As wxDouble)

' shortened to reduce display size
In my experience this works easily in most cases. Some times there may appear problems, then a workaround may be needed.

Similarly with the other examples. There are mostly additional functions in the .bi files.
Last edited by lizard on Nov 09, 2017 21:55, edited 1 time in total.
lizard
Posts: 440
Joined: Oct 17, 2017 11:35
Location: Germany

Re: wxWidgets for FreeBASIC?

Post by lizard »

Another way would be to compile "clientdc01.bas" with -pp:

Code: Select all

fbc -pp clientdc01.bas
This produces a huge file "clientdc01.pp.bas" listing all wx-c functions avaiable. This maybe pretty obvious for some, for others it could be helpful. :-)
Post Reply