Code using IUP GUI library does not display the window

New to FreeBASIC? Post your questions here.
Post Reply
Nirmal
Posts: 2
Joined: Feb 27, 2022 13:19

Code using IUP GUI library does not display the window

Post by Nirmal »

I am new to FreeBasic. I have experience in programming C# and Java. I was trying out FreeBasic with IUP GUI library. I wanted to try and created a wrapper for IUP in FreeBasic for my own use. I wrote the following code by I can see the GUI window created. But the commented out portion at the lower bottom works OK and a window opens! What is wrong with my code ? I tried my best to find out, I couldn't ! Can anybody throw some light on where I have gone wrong please?

Code: Select all

#Include "d:/IUP/iup.bi"                 
#Include "Form.bas" 

Type XForm
    dlg as IHandle Ptr 
    label as IHandle Ptr
  
    Declare Constructor
    Declare Sub Show()
End Type

Constructor XForm()
      label = IupLabel("Hello world from IUP.")
      dlg = IupDialog(IupVbox(label,0)) 
      IupSetAttribute(dlg, "SIZE","FULL")
      IupSetAttribute(dlg, "TITLE", "Hello World!")
      Print "Inside Form constructor..."
end constructor

sub XForm.Show()
      IupShowXY(dlg, IUP_CENTER, IUP_CENTER)
      Print "Showing the Form..."
end sub


Dim  Form1 As XForm

IupOpen(0, 0) 
Print "IupOpen..."
Form1.Show() 
Print "Entering IupMainLoop..."
IupMainLoop()
Print "IupClose..."
IupClose()                             


'=============================================================================
'The following code works perfectly

'Dim dlg as IHandle Ptr
'Dim label as IHandle Ptr
'
'IupOpen(0, 0) 
'label = IupLabel("Hello world from IUP.")
'dlg = IupDialog(IupVbox(label,0)) 
'IupSetAttribute(dlg, "SIZE","FULL")
'IupSetAttribute(dlg, "TITLE", "Hello World!")
'IupShowXY(dlg, IUP_CENTER, IUP_CENTER)
'IupMainLoop()
'IupClose()
'
'=============================================================================
VANYA
Posts: 1834
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: Code using IUP GUI library does not display the window

Post by VANYA »

Because IupOpen is called after the constructor has been called. Put it at the beginning:

Code: Select all

...
IupOpen(0, 0)
Dim  Form1 As XForm
...
Nirmal
Posts: 2
Joined: Feb 27, 2022 13:19

Re: Code using IUP GUI library does not display the window

Post by Nirmal »

Oh yes! It worked! Thanks a lot for your help!
Post Reply