free basic how to load new form like vb6,and get form.item (public method or value)

Windows specific questions.
Post Reply
xiaoyao
Posts: 121
Joined: May 05, 2020 2:01

free basic how to load new form like vb6,and get form.item (public method or value)

Post by xiaoyao »

free basic how to load new form like vb6,and get form.item (public method or value)
in this project:
viewtopic.php?t=25215

how to freebasic do like vb6 ?
new form1,new form2?
form1.frm

Code: Select all

Option Explicit
Dim F2a As New Form2, F2b As New Form2
Private Sub Command1_Click()
F2a.Show
F2b.Show

F2a.Form2_abc = 11
F2b.Form2_abc = 22
F2a.Caption = "Form2_a"
F2b.Caption = "Form2_b"

MsgBox F2a.Form2_abc
MsgBox F2b.Form2_abc

End Sub
form2.frm

Code: Select all

Public Form2_abc As Long
Public Sub Form2_Test()
    MsgBox "it's form2 Test"
End Sub
exagonx
Posts: 315
Joined: Mar 20, 2009 17:03
Location: Italy
Contact:

Re: free basic how to load new form like vb6,and get form.item (public method or value)

Post by exagonx »

xiaoyao wrote: Dec 28, 2023 15:57 free basic how to load new form like vb6,and get form.item (public method or value)
in this project:
viewtopic.php?t=25215
The Forms you want to use require the Windows Framework libraries.

If you want to create a program that uses the windows graphical interface and consequently the windows API itself you must include windows.bi

In the example below there is a window with labels buttons and textbox

While if you want to use forms as in Visual BASIC you must necessarily use the Framework and Framework.NET libraries

Even though I have already done it, I don't have an example to show you, I currently work under Linux and I don't have a Windows PC where I can create a working example for you.

Code: Select all

#include "windows.bi"




dim as MSG msg
dim as HWND MainWindow, BClose, BStart, TCommand, TTime, BFirefox, BGeany, BMSYS64, BPromptDOS
dim as HWND LCommand, LTime

dim as integer Time_Value

MainWindow = CreateWindowEx(0,"#32770", "Hello", WS_OVERLAPPEDWINDOW Or WS_VISIBLE, 100, 100, 500, 320, 0,0,0,0 )

'Buttons
BClose = CreateWindowEx(0, "Button", "Close", WS_VISIBLE Or WS_CHILD, 20, 10, 100, 30, MainWindow, 0, 0, 0)
BStart = CreateWindowEx(0, "Button", "Run", WS_VISIBLE Or WS_CHILD, 130, 10, 100, 30, MainWindow, 0, 0, 0)
BGeany = CreateWindowEx(0, "Button", "Load Geany", WS_VISIBLE Or WS_CHILD, 20, 200, 110, 30, MainWindow, 0, 0, 0)
BFirefox = CreateWindowEx(0, "Button", "Load Firefox", WS_VISIBLE Or WS_CHILD, 135, 200, 110, 30, MainWindow, 0, 0, 0)
BMSYS64 = CreateWindowEx(0, "Button", "Load Msys2", WS_VISIBLE Or WS_CHILD, 250, 200, 110, 30, MainWindow, 0, 0, 0)
BPromptDOS = CreateWindowEx(0, "Button", "Open Prompt", WS_VISIBLE Or WS_CHILD, 20, 235, 110, 30, MainWindow, 0, 0, 0)

'Label
LCommand = CreateWindowEx(0, "Static", "Command :" ,  WS_VISIBLE Or WS_CHILD , 10, 50, 99, 20, MainWindow, 0, 0, 0 )
LTime = CreateWindowEx(0, "Static", "Time in Sec. :" ,  WS_VISIBLE Or WS_CHILD , 10, 73, 99, 20, MainWindow, 0, 0, 0 )

'TextBox
TCommand = CreateWindowEx(0, "Edit", "" , WS_BORDER Or WS_VISIBLE Or WS_CHILD Or ES_AUTOHSCROLL, 120, 50, 200, 20, MainWindow, 0, 0, 0 )
TTime = CreateWindowEx(0, "Edit", "" , WS_BORDER Or WS_VISIBLE Or WS_CHILD Or ES_AUTOHSCROLL, 120, 73, 50, 20, MainWindow, 0, 0, 0 )

dim as ZString*1024 Command_text 
dim as ZString*512 Time_text


While GetMessage(@msg, 0, 0, 0)
	TranslateMessage( @msg )
	DispatchMessage( @msg )

	Select Case msg.hwnd
	  case MainWindow
	      Select Case msg.message
		Case 273
		  End
		Case Else
		  
	       End Select
	  Case BClose
	      Select Case msg.message
		Case WM_LBUTTONDOWN
		 end
	       End Select

	  Case BStart
	      Select Case msg.message
		Case WM_LBUTTONDOWN
		  
		  GetWindowText(TCommand, Command_text, sizeof(Command_text))
		  GetWindowText(TTime, Time_text, sizeof(Time_text))
		  Time_Value = val(Time_text)
		 
		  
		  MessageBox( MainWindow, "Start timed." & Comando_text, "Start Timed", MB_OK Or MB_ICONINFORMATION )
	       End Select
	  Case BGeany
	      Select Case msg.message
		Case WM_LBUTTONDOWN
		 shell "geany.cmd"
	       End Select
	  Case BFirefox
	      Select Case msg.message
		Case WM_LBUTTONDOWN
		 shell "firefox.cmd"
	       End Select 
	  Case BMSYS64
	      Select Case msg.message
		Case WM_LBUTTONDOWN
		 shell "msys2.cmd"
	       End Select  
	  Case BPromptDOS  
	      Select Case msg.message
		Case WM_LBUTTONDOWN
		 shell "shell.cmd"
	       End Select  
	End Select
Wend

marcov
Posts: 3462
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: free basic how to load new form like vb6,and get form.item (public method or value)

Post by marcov »

There are native Windows Framework libraries? (or for native app target). Url ?

Or do you mean Microsoft Foundation Libraries?
exagonx
Posts: 315
Joined: Mar 20, 2009 17:03
Location: Italy
Contact:

Re: free basic how to load new form like vb6,and get form.item (public method or value)

Post by exagonx »

marcov wrote: Mar 27, 2024 9:21 There are native Windows Framework libraries? (or for native app target). Url ?

Or do you mean Microsoft Foundation Libraries?
From version 5 of Windows NT (Windows 2000 Professional) The basic framework is included in the system libraries, instead in the old versions of Windows 98 and NT4.

While the .NET Framework can be installed as a Windows add-on from version 5 (Windows 2000 Pro) and all subsequent versions.

The example I mentioned in the previous post uses the native Windows framework (include Windows.bi), to use the Framework.net refer to the documentation provided by Microsoft, currently there is no Header that allows direct use of .NET since they are libraries used by VisualStudio.

ps.
For a matter of practicality I recommend using GTK, given its availability in both Windows and Linux environments, furthermore, using the GLADE tool it is also easy to design an interface since the tool is visual.
marcov
Posts: 3462
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: free basic how to load new form like vb6,and get form.item (public method or value)

Post by marcov »

exagonx wrote: Mar 27, 2024 23:21 From version 5 of Windows NT (Windows 2000 Professional) The basic framework is included in the system libraries, instead in the old versions of Windows 98 and NT4.
(and afaik went out again in Windows 2008, as there are server commandline versions again since then)

But ok, so with the native framework you mean the base windows GDI, not some native variant of the .NET framework visual API (Winforms, WPF)
ps.
For a matter of practicality I recommend using GTK, given its availability in both Windows and Linux environments, furthermore, using the GLADE tool it is also easy to design an interface since the tool is visual.
Ugh.
Post Reply