• Welcome to PlanetSquires Forums.
 

WinFormsX

Started by Paul Squires, February 03, 2018, 10:58:18 AM

Previous topic - Next topic

Paul Squires

In order for WinFBE to be the successor to FireFly, it is important that I create a very easy to use and intuitive forms library that will allow the user to interact with Jose's WinFBX library and the Win32 api in the easiest way possible. WinFormsX is my attempt to create a dot notation style forms library. It is still in the early stages but a lot of the underlying engine is now built. Once it matures then it will make the code generation from the visual designer inside WinFBE to be easier for the user to read and understand.

I post the following code to give a simple look at how the code looks. A user could create windows applications by hand if they wish or allow WinFBE to generate the vast bulk of the code below.

WinFBE and WinFormsX are my primary focus this year and I am focused to finish it as soon as I can. I really want a full featured and easy to use editor and visual designer for FreeBASIC.


''
''  FORMTEST
''  Form test application.
''

#include once "WinFormsX\WinFormsX.bi"

'#CONSOLE ON

declare function Form1_MouseMove( byref sender as wfxForm, byref e as EventArgs ) as LRESULT
declare function Form1_Click( byref sender as wfxForm, byref e as EventArgs ) as LRESULT
declare function Form1_Load( byref sender as wfxForm, byref e as EventArgs ) as LRESULT
declare function Form1_Activated( byref sender as wfxForm, byref e as EventArgs ) as LRESULT
declare function Form1_Deactivate( byref sender as wfxForm, byref e as EventArgs ) as LRESULT
declare function Form1_Shown( byref sender as wfxForm, byref e as EventArgs ) as LRESULT
declare function Form1_FormClosing( byref sender as wfxForm, byref e as EventArgs ) as LRESULT
declare function Form1_FormClosed( byref sender as wfxForm, byref e as EventArgs ) as LRESULT
declare function Form1_Move( byref sender as wfxForm, byref e as EventArgs ) as LRESULT
declare function Form1_Resize( byref sender as wfxForm, byref e as EventArgs ) as LRESULT
declare function Form1_GotFocus( byref sender as wfxForm, byref e as EventArgs ) as LRESULT
declare function Form1_LostFocus( byref sender as wfxForm, byref e as EventArgs ) as LRESULT
declare function Form1_KeyDown( byref sender as wfxForm, byref e as EventArgs ) as LRESULT
declare function Form1_KeyPress( byref sender as wfxForm, byref e as EventArgs ) as LRESULT
declare function Form1_KeyUp( byref sender as wfxForm, byref e as EventArgs ) as LRESULT

''         
''  Define the form (no child controls for this test)
''
type TFORMMAIN extends wfxForm
   private:
   
   public:
      ' Controls
      ' Normally we would define our child controls.
      ' For example:
      '
      ' Label1 as wfxLabel
      ' StatusBar as wfxStatusBar
     
      declare constructor   
END TYPE

''
''  Use the Constructor to define the properties and assign methods
''  to the form and child controls.
''
constructor TFORMMAIN
   ' Add the form to the global application collection
   Application.Forms.Add(ControlType.Form, @this)
   
   ' Set the properties of the form
   with this
      .Size          = 600, 400
      .StartPosition = FormStartPosition.CenterScreen
      .Text          = "Form1"
      .Name          = "Form1"
      .OnClick       = @Form1_Click
      .OnResize      = @Form1_Resize
      .OnMouseMove   = @Form1_MouseMove
      .OnLoad        = @Form1_Load
      .OnActivated   = @Form1_Activated
      .OnDeactivate  = @Form1_Deactivate
      .OnShown       = @Form1_Shown
      .OnFormClosing = @Form1_FormClosing
      .OnFormClosed  = @Form1_FormClosed
      .OnMove        = @Form1_Move
      .OnGotFocus    = @Form1_GotFocus
      .OnLostFocus   = @Form1_LostFocus
      .OnKeyDown     = @Form1_KeyDown
      .OnKeyUp       = @Form1_KeyUp
      .OnKeyPress    = @Form1_KeyPress
   end with
END CONSTRUCTOR

''  Define a global variable that will allow access to the form and controls
dim shared Form1 as TFORMMAIN


''
''  Define the various methods that the application will respond to.
''  User code will go into these methods in order to make the application work.
''
function Form1_Load( byref sender as wfxForm, byref e as EventArgs ) as LRESULT
   ? "Form Load"
   function = 0
end function

function Form1_Activated( byref sender as wfxForm, byref e as EventArgs ) as LRESULT
   ? "Form Activated"
   function = 0
end function

function Form1_Deactivate( byref sender as wfxForm, byref e as EventArgs ) as LRESULT
   ? "Form Deactivate"
   function = 0
end function

function Form1_Shown( byref sender as wfxForm, byref e as EventArgs ) as LRESULT
   ? "Form Shown"
   function = 0
end function

function Form1_FormClosing( byref sender as wfxForm, byref e as EventArgs ) as LRESULT
   ? "Form FormClosing"
   function = 0
end function

function Form1_FormClosed( byref sender as wfxForm, byref e as EventArgs ) as LRESULT
   ? "Form FormClosed"
   function = 0
end function

function Form1_GotFocus( byref sender as wfxForm, byref e as EventArgs ) as LRESULT
   ? "Form GotFocus"
   function = 0
end function

function Form1_LostFocus( byref sender as wfxForm, byref e as EventArgs ) as LRESULT
   ? "Form LostFocus"
   function = 0
end function

function Form1_Move( byref sender as wfxForm, byref e as EventArgs ) as LRESULT
   dim pt as wfxPoint = sender.Position
   sender.Text = "Form Move (x,y) = (" & pt.x & ", " & pt.y & ")"
   function = 0
end function

function Form1_MouseMove( byref sender as wfxForm, byref e as EventArgs ) as LRESULT
   sender.Text = "Form MouseMove (x,y) = (" & e.x & "," & e.y & ")   Buttons: " & e.Buttons
   function = 0
end function

function Form1_Resize( byref sender as wfxForm, byref e as EventArgs ) as LRESULT
   dim size as wfxSize = sender.Size
   sender.Text = "Form Resize (x,y) = (" & size.Width & " x " & size.Height & ")"
   function = 0
end function

function Form1_KeyDown( byref sender as wfxForm, byref e as EventArgs ) as LRESULT
   ? "Form KeyDown "; e.KeyChar
   function = 0
end function

function Form1_KeyUp( byref sender as wfxForm, byref e as EventArgs ) as LRESULT
   ? "Form KeyUp "; e.KeyChar
   function = 0
end function

function Form1_KeyPress( byref sender as wfxForm, byref e as EventArgs ) as LRESULT
   ? "Form KeyPress "; e.KeyChar
   function = 0
end function

function Form1_Click( byref sender as wfxForm, byref e as EventArgs ) as LRESULT
   ' Print the properties of the form to the console window
   ' In addition to using the "sender" object we could also have referred to the
   ' form properties through use of the global shared Form1 variable.
   dim pt as wfxPoint = sender.Position
   dim size as wfxSize = sender.Size
   dim clientsize as wfxSize = sender.ClientSize
   
   ? "Name: "; sender.Name
   ? "Text: "; sender.Text
   ? "Parent: "; sender.Parent
   ? "Background: "; sender.Background
   ? "Enabled: "; sender.Enabled
   ? "Visible: "; sender.Visible
   ? "Left: "; sender.Left
   ? "Top: "; sender.Top
   ? "Width: "; sender.Width
   ? "Height: "; sender.Height
   ? "Size: "; size.Width; " x "; size.Height
   ? "ClientSize: "; clientsize.Width; " x "; clientsize.Height
   ? "Position: "; pt.x; ", "; pt.y
   ? "WindowState: "; sender.WindowState
   ? "StartPosition: "; sender.StartPosition
   ? "BorderStyle: "; sender.BorderStyle
   ? "MinimizeBox: "; sender.MinimizeBox
   ? "MaximizeBox: "; sender.MaximizeBox
   ? "ControlBox: "; sender.ControlBox
   ? "IsMainForm: "; sender.IsMainForm
   ? "IsModal: "; sender.IsModal
   ?
   function = 0
end function



''
''  Main code for the application.
''
Application.Run(Form1)

' Pause at the end so we can see the last messages in the console window
sleep



(Edit: Update code example to include more event handling and easier EventArgs handling).


Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

raymw

#1
Hi )Paul,

Downloaded, installed as recommended, and ran test program - works OK. Your install instructions, I don't think you mean to copy the whole folder, just the src folder to the fb inc folder. This is getting a bit messy, program bits and pieces all over the place. Anyway, looking good, somewhat like c#. I expect I'll manage to break it, so stand by for hassle...

Seriously, well done.

Thanks, Ray

edit - spoke too soon, now comes up with compile error, can't open rc file. Funny, it worked once, a number of times on the test form. Then restarted tried others, button, etc., rc error, and also for same original form.

Paul Squires

Thanks Ray, I just uploaded new code a few minutes ago with the ButtonTest example. You are right, just the files in the src folder to \inc\WinFormsX  I will fix that documentation mistake.
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

SeaVipe

#3
FYI,
[1.5.9]
FreeBASIC Compiler - Version 1.06.0 (11-03-2017), built for win64 (64bit)
Copyright (C) 2004-2016 The FreeBASIC development team.
standalone
target:       win64, x86-64, 64bit
compiling:    C:\WinFBE-1.5.9\Examples\WinFormsX\StatusBarTest.bas -o C:\WinFBE-1.5.9\Examples\WinFormsX\StatusBarTest.c (main module)
C:\WinFBE-1.5.9\Examples\WinFormsX\StatusBarTest.bas(55) error 18: Element not defined, Add in '.Panels.Add'

Same result in 1.5.7. Both Form and Label examples compile OK in 1.5.7 and 1.5.9.
Clive Richey

Paul Squires

....yes, I know about the StatusBar example. I probably shouldn't have uploaded that one because it is a work in progress trying to get the .Panels(index) and .Panels.Add differing syntax to work.
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Paul Squires

#5
Quote from: SeaVipe on February 07, 2018, 03:12:10 PM
FYI,
[1.5.9]
FreeBASIC Compiler - Version 1.06.0 (11-03-2017), built for win64 (64bit)
Copyright (C) 2004-2016 The FreeBASIC development team.
standalone
target:       win64, x86-64, 64bit
compiling:    C:\WinFBE-1.5.9\Examples\WinFormsX\StatusBarTest.bas -o C:\WinFBE-1.5.9\Examples\WinFormsX\StatusBarTest.c (main module)
C:\WinFBE-1.5.9\Examples\WinFormsX\StatusBarTest.bas(55) error 18: Element not defined, Add in '.Panels.Add'

Same result in 1.5.7. Both Form and Label examples compile OK in 1.5.7 and 1.5.9.
I fixed this by changing references to the panel collection by using the variable "Panels" and to a specific panel by using the variable "Panel()" as can be seen in the following code snippet. I have updated GitHub.


   with this.StatusBar
      .Parent = @this
      .SizingGrip = false
      ' Add 3 statusbar panels
      for i as long = 0 to 2
         .Panels.Add
      NEXT
      .Panel(0).Text = "Panel1"
      .Panel(0).Width = 120
      .Panel(1).Text = "Panel2"
      .Panel(1).Width = 200
      .Panel(2).Text = "Panel3"
      .Panel(2).AutoSize = StatusBarPanelAutoSize.Spring
   END WITH   
   this.Controls.add(controltype.StatusBar, @this.StatusBar)
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

SeaVipe

Hi Paul, Not sure how helpful this is but "Panel(n)" gives errors. Changed to "Panels(n)" and I only get the .Add error.
Clive Richey

Paul Squires

Looks like you are using the correct new StatusBarTest.bas code but maybe you are not using the latest copies of the library code itself? The latest repository code has newer "wfxStatusBar.bi" and "wfxStatusBar.inc" files. Make sure you download and overwrite the ones that you currently have in your \inc\winformsx folder.

If I were you, I would delete the contents of your \inc\winformsx folder every time you download the code from GitHub.

I compile here with no errors in either 32 bit or 64 bit.
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

raymw

#8
still stuck. downloaded and installed as requested. iirc somewhere there was a reference to add something to the compile options a .rc file I think. I know nothing about such things, can't find the ref - which I thought was in the documents. Anyway compiler log file says {error 80: Invalid command-line option, "C:\Program Files (x86)\FreeBASIC\inc\WinFormsXDOWNLOADED\examples\TMPEDC7.tmp"}
Any suggestions? In Winfbe there are a number of build configuration options - any specific one needed? I think i added whatever.rc to the compiler options there, but it is not there now...

edit to say - Sorted! ( the resource.rc is in the comments at prog beginning!!!! and you can't run it if the .bas program is in the same path as freebasic compiler. Works Ok if on desktop, or in user folder. where admin? rights not needed.

Now, when are we getting the gui to play with?

SeaVipe

Thanks, Paul. Deleted everything and started from scratch. Works without errors.
Clive Richey

Paul Squires

Make sure you have the latest version of WinFBE installed (1.5.9). That version allows for a new code compiler directive called #RESOURCE that makes working with the resource file easier than adding to the compile options. In the test file "ButtonTest.bas" you will see this code that shows that #RESOURCE directive in action:


' When compiling, be sure to include the file "resource.rc". In WinFBE, this can be done
' via the Compiler Setup / Additional Compiler Settings, or using the #RESOURCE code
' directive as shown below.


'#CONSOLE ON
'#RESOURCE "resource.rc"


Also, from your compiler error it looks like you are using WinFBE's "Quick Run". Try doing a normal compile and run instead.

The instructions you are looking for are in (1) The "docs" folder in the *.md files (these are called markdown files and I will use them to generate HTML code or PDF files later.; or, (2) The main GitHub page has the instructions listed as well (towards the bottom of the webpage): https://github.com/PaulSquires/WinFormsX 
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Paul Squires

.... I just read both of your posts :)  Awesome that you guys got it figured out and working. With people actually using and testing the code makes it more motivating for me to develop faster.

Not much sense building the GUI visual designer in WinFBE until most of this library is complete because it is kind of a chicken and egg scenario.
If I don't know what code is being generated...then how can I build the GUI to generate the unknown code :)
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

raymw

Hi Paul, any of the other inc's working - e.g. textbox, linked list, whatever. I'm sort of thinking of programmatically generating the forms, at least the simple ones. It would be quicker than sliding shapes around the screen, I reckon. e.g. a form, or even command line - size of form, number of buttons, number of text boxes, then code generated so that they get spaced around the form in a more or less predefined way. The form could then be titivated up in a gui editor, if needed. I don't want to spend too much time on this, if the list/text binaries are not yet prime time. It was easy enough to alter your button test, for example, cutting and pasting three blocks of code, and altering 1's to 2's. Have you an explanation of how you are making this work, although I've more or less worked out as much as i need. The basic stuff, I'm finding out, e.g. quick compile does not save an .exe - wasted a bit of time wondering where the .exe had disappeared to. I need to get this organized better. Storage always has been, always will be a problem, as are interfaces, digital in an analogue world, etc.

raymw

#13
I've been randomly going through some of the button actions - resizing, moving, etc. A simple form1.button1.hide inside the the button2_click function hides button1 as expected, but a similar form1.button1.show in the button3_click function does not make it reappear. Is that correct behavior?

visible true/false are ok, even hide then visible=true works.
How to change button background colors?

Paul Squires

Quote from: raymw on February 08, 2018, 10:52:40 AM
Hi Paul, any of the other inc's working - e.g. textbox, linked list, whatever.
Nope. So far only the Form, Button, Label and StatusBar has any real working code.

QuoteI'm sort of thinking of programmatically generating the forms, at least the simple ones. It would be quicker than sliding shapes around the screen, I reckon. e.g. a form, or even command line - size of form, number of buttons, number of text boxes, then code generated so that they get spaced around the form in a more or less predefined way.
Seems like a lot of work. :)  I'd wait until the visual designer is finished or simply continue to hand code.
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer