PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Demo (and source code) for early WinLib library  (Read 418 times)

Paul Squires

  • Administrator
  • Master FireFly Member
  • *****
  • Posts: 8104
  • Windows 10
    • PlanetSquires Software
Demo (and source code) for early WinLib library
« on: August 13, 2017, 01:01:53 PM »

I am attaching an early look at the WinLib library that I have been writing on and off over the past little while. The goal is to make WinAPI programming easier in the style of .Net while not sacrificing any of the speed or flexibility of the underlying Windows API. The library itself is built on top of Jose's CWindow framework so you must of course already have that code installed.

Code: [Select]
''
''
FUNCTION frmMain_MouseMove( byref sender as object, byref e as MouseEventArgs ) as LRESULT
   Dim byref frmMain as clsForm = wlCast(clsForm, sender)
   frmMain.Text = "Form MouseMove (x,y) = (" & e.x & "," & e.y & ")   Buttons: " & e.Buttons
   function = 0
END FUNCTION

The above shows how all events are handled. A generic OBJECT is received through the function and you then cast it to the type of control/form that you need. In this case, the function is handling all movement as the mouse moves across a form. The second argument is MouseEventArgs but depending on the type of function could be KeyboardEventArgs or simply EventArgs. The elements of that incoming TYPE holds message specific information.

Notice the use of "BYREF". This allows us to use the "." type of syntax instead of the pointer "->" syntax. The "." syntax is very .Net like.

Here is code to create the Form and add a Label:

Code: [Select]
Dim byref frmMain as clsForm = wlNew(clsForm, "frmMain")
with frmMain
   .Size = 600, 400
   .StartPosition = FormStartPosition.CenterScreen
   .Text = "Form1"
   .OnLoad = @frmMain_Load()
   .OnActivated = @frmMain_Activated()
   .OnDeactivate = @frmMain_Deactivate()
   .OnShown = @frmMain_Shown()
   .OnMouseMove = @frmMain_MouseMove()
   .OnFormClosing = @frmMain_FormClosing()
   .OnFormClosed = @frmMain_FormClosed()
   .OnMove = @frmMain_Move()
   .OnResize = @frmMain_Resize()
   .OnAllEvents = @frmMain_AllEvents()
end with

Dim byref Label1 as clsLabel = wlNew(clsLabel, "Label1")
with Label1
   .Text = "This is a Label"
   .SetBounds(5, 5, 150, 30)
   .Foreground = Colors.Yellow
   .Background = Colors.Blue
   .OnClick = @Label1_Click()
end with
frmMain.Controls.Add(Label1)

Application.Run(frmMain)

The attached demo program shows more controls like checkbox, option button, command button, and a popup modal dialog.

Let me know what you think of this and if it is worthwhile to continue. The goal would be to create a library and have WinFBE output generated code via a visual designer. The WinLib code would be easy enough to understand that even if someone wanted to hand write their application then they'd be able to do so easily.

Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

Josť Roca

  • FireFly3 Registered User
  • Master FireFly Member
  • *
  • Posts: 2785
    • Josť Roca Software
Re: Demo (and source code) for early WinLib library
« Reply #1 on: August 13, 2017, 01:59:26 PM »

After clicking the Close button the application remains in memory.
« Last Edit: August 13, 2017, 02:03:05 PM by Josť Roca »
Logged

Paul Squires

  • Administrator
  • Master FireFly Member
  • *****
  • Posts: 8104
  • Windows 10
    • PlanetSquires Software
Re: Demo (and source code) for early WinLib library
« Reply #2 on: August 13, 2017, 02:07:55 PM »

Thanks Jose.... I will check that. See, told you it wasn't perfect  :)
Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

Josť Roca

  • FireFly3 Registered User
  • Master FireFly Member
  • *
  • Posts: 2785
    • Josť Roca Software
Re: Demo (and source code) for early WinLib library
« Reply #3 on: August 13, 2017, 02:12:17 PM »

Forget it. I was compiling it as a GUI application and your demo has an SLEEP.

Paul Squires

  • Administrator
  • Master FireFly Member
  • *****
  • Posts: 8104
  • Windows 10
    • PlanetSquires Software
Re: Demo (and source code) for early WinLib library
« Reply #4 on: August 13, 2017, 02:18:43 PM »

Forget it. I was compiling it as a GUI application and your demo has an SLEEP.

Yes, that's right, I am using Console release so I see the debug PRINT statements in the console window. Obviously in a real world application that wouldn't be necessary.
Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

Josť Roca

  • FireFly3 Registered User
  • Master FireFly Member
  • *
  • Posts: 2785
    • Josť Roca Software
Re: Demo (and source code) for early WinLib library
« Reply #5 on: August 13, 2017, 02:22:23 PM »

I have added a '#CONSOLE ON to it :)

Paul Squires

  • Administrator
  • Master FireFly Member
  • *****
  • Posts: 8104
  • Windows 10
    • PlanetSquires Software
Re: Demo (and source code) for early WinLib library
« Reply #6 on: August 13, 2017, 02:39:41 PM »

Lol, good idea, I'll do the same :)
Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

aloberr

  • FireFly3 User
  • Little Newbie FireFly
  • *
  • Posts: 33
Re: Demo (and source code) for early WinLib library
« Reply #7 on: August 14, 2017, 03:35:55 AM »

I carried out in other times a similar class, functions correctly by inheriting a class
but is the use of dim byref in a class seemed to me not good isn't it? 
example:

type Cform1 extends clsForm
       dim byref btnok as lcsbutton
       ..................
end type
Logged

Paul Squires

  • Administrator
  • Master FireFly Member
  • *****
  • Posts: 8104
  • Windows 10
    • PlanetSquires Software
Re: Demo (and source code) for early WinLib library
« Reply #8 on: August 14, 2017, 11:48:14 AM »

I carried out in other times a similar class, functions correctly by inheriting a class
but is the use of dim byref in a class seemed to me not good isn't it? 
example:

type Cform1 extends clsForm
       dim byref btnok as lcsbutton
       ..................
end type


Hi aloberr, I like that approach as well. Actually it is probably better because it keeps all controls within the Form's class instance. It is very C# like for sure (I haven't checked the VB.Net approach). The more I think of it, the more I like that approach. I think that I will do some redesign to make the library's output similar this approach.
Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

aloberr

  • FireFly3 User
  • Little Newbie FireFly
  • *
  • Posts: 33
Re: Demo (and source code) for early WinLib library
« Reply #9 on: August 15, 2017, 08:28:22 AM »

you do not need to modify any thing. 
I wanted to say avoid using for example dim byref mycontrol as Clsbutton, but rather dim mycontrol as Clsbutton
because FB classes do not support dim byref  I thing
if not one can inherit well ClsForm with for example type TForm1 extends clsForm .
Logged

Paul Squires

  • Administrator
  • Master FireFly Member
  • *****
  • Posts: 8104
  • Windows 10
    • PlanetSquires Software
Re: Demo (and source code) for early WinLib library
« Reply #10 on: August 15, 2017, 12:58:03 PM »

Thanks aloberr, after looking at it all again, I think that I will stick to my original approach. It is easier to understand for many people coming from a BASIC background.
Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor