How to setup Afx in FBE and start to using it?

New to FreeBASIC? Post your questions here.
Post Reply
PeterHu
Posts: 148
Joined: Jul 24, 2022 4:57

How to setup Afx in FBE and start to using it?

Post by PeterHu »

Greetings!

I searched Afx key word there are a lot result but it failed to find the very basic ones.I am fresh new to freebasic but I've learnt Afx is a great art of work so I would like to use it .But I can't set up the basic working environment,ie.does it have to be compiled to lib before using,and how to import or include necessary headers to be everthing is ready to go?

If there is already a thread regarding this basic topic,forgive me careless not find.Any tutorial on Using Afx in FB would be much appreciated.



By the way,not to open another new thread,so just asking help herer,how to add even code in FBE Form Designer for a control,like,a Button Click to popup a MessageBox?Just Curious in a very simple windows(a form ,a button in it) project,just a *inc file,a *.bas file ,no other files,and the *.bas file only contains blew few codes:

Code: Select all

' For your convenience, below are some of the most commonly used WinFBX library
' include files. Uncomment the files that you wish to use in the project or add
' additional ones. Refer to the WinFBX Framework Help documentation for information
' on how to use the various functions.

' #Include Once "Afx\AfxFile.inc"
' #Include Once "Afx\AfxStr.inc"
' #Include Once "Afx\AfxTime.inc"
' #Include Once "Afx\CIniFile.inc"
' #Include Once "Afx\CMoney.inc"
' #Include Once "Afx\CPrint.inc"


Application.Run(frmMain)

How to adding control(...)code on it?

Thanks everybody in advance for the help.
Peter
Josep Roca
Posts: 564
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: How to setup Afx in FBE and start to using it?

Post by Josep Roca »

There is a dedicated forum for WinFBE/WInFBX:
https://www.planetsquires.com/protect/forum/index.php
PeterHu
Posts: 148
Joined: Jul 24, 2022 4:57

Re: How to setup Afx in FBE and start to using it?

Post by PeterHu »

Thank you so much for the help!
deltarho[1859]
Posts: 4292
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: How to setup Afx in FBE and start to using it?

Post by deltarho[1859] »

@PeterHu

You may also find WinFBX_Help.zip helpful.
PeterHu
Posts: 148
Joined: Jul 24, 2022 4:57

Re: How to setup Afx in FBE and start to using it?

Post by PeterHu »

Thanks a lot...

I've downloaded FBX from github,got the WINFBX.chm,at the meanwhile,I found there is another FBX help file(s)(folder) in the all-in-one WinFBE package which I've installed & using to learn FB.I am a bit confused so which one should I learn,or both should be learned?

Besides SDK references(I knew it is core and so important to learn),at this moment I also need some basic guides on how to add code to controls I've added in the form,not saying just a simple & easy Button Click.So I am wondering whether there is such a help document.Or,the SDK includes everything I need to know.

==================================================
Questions & asking help from the exercise:
A form,a Button, a Textbox,when the Button been clicked,the Textbox's text changed,that's all about the app/Form.
The ex03.bas source file contains one line

Code: Select all

Application.Run(frmMain)
besides the #includes... and using,
then I found there are other files generated by the IDE,among those frmMain.inc & WinFBE_VD_MAIN.bas attracted me the most.I think I am a bit closer to the whole picture on how a GUI program sources is organized.

But soon I am confused with this line in WINFBE_VD_MAIN.bas,at the bottom of the file,ie.,the last line:

Code: Select all

#include once "E:\Learning\FreeBasic\ex\03\frmMain.inc"
Q1:I am confused because the codes in frmMain.inc are almost exactly the same already exist in WINFBE_VD_MAIN.bas,so why #include frmMain.inc again,doesn't this cause a compiler error?

Q2:Why frmMain_btn1Click has to be a normal procedure rather than type(class) frmMainType's member procedure?

Code: Select all

Declare Function frmMain_btn1_Click( ByRef sender As wfxButton, ByRef e As EventArgs ) As LRESULT
Q3:Why type(class)member function FormInitializeComponent has to have a pointer parameter points to itself?

Code: Select all

declare static function FormInitializeComponent( byval pForm as frmMainType ptr ) as LRESULT

Code: Select all

constructor frmMainType
   InitializeComponent = cast( any ptr, @FormInitializeComponent )
   this.FormInitializeComponent( @this )
end constructor
Your help would be alway much appreciated.

==========================
Code list below:
1). ex03.bas:

Code: Select all

 #Include Once "Afx\AfxFile.inc"
 #Include Once "Afx\AfxStr.inc"
 #Include Once "Afx\AfxTime.inc"
 #Include Once "Afx\CIniFile.inc"
 #Include Once "Afx\CMoney.inc"
 #Include Once "Afx\CPrint.inc"
' #include once "afx"
 #include once "afx\cwstr.inc"
 #include once "windows.bi"
 using afx
 
Application.Run(frmMain)

2).frmMain.inc:

Code: Select all

' WINFBE FORM
' WINFBE VERSION 3.0.1
' LOCKCONTROLS=False
' SNAPLINES=True
' WINFBE FORM_START
' WINFBE CONTROL_START Form
'   PROPERTIES_START
'     PROP_NAME=Name
'     PROP_VALUE=frmMain
'     PROP_NAME=Left
'     PROP_VALUE=10
'     PROP_NAME=Top
'     PROP_VALUE=10
'     PROP_NAME=Width
'     PROP_VALUE=500
'     PROP_NAME=Height
'     PROP_VALUE=300
'     PROP_NAME=ChildForm
'     PROP_VALUE=False
'     PROP_NAME=Text
'     PROP_VALUE=Form1
'     PROP_NAME=WindowState
'     PROP_VALUE=FormWindowState.Normal
'     PROP_NAME=StartPosition
'     PROP_VALUE=FormStartPosition.Manual
'     PROP_NAME=BorderStyle
'     PROP_VALUE=FormBorderStyle.Sizable
'     PROP_NAME=MinimizeBox
'     PROP_VALUE=True
'     PROP_NAME=MaximizeBox
'     PROP_VALUE=True
'     PROP_NAME=ControlBox
'     PROP_VALUE=True
'     PROP_NAME=Enabled
'     PROP_VALUE=True
'     PROP_NAME=Visible
'     PROP_VALUE=True
'     PROP_NAME=BackColor
'     PROP_VALUE=SYSTEM|Control
'     PROP_NAME=AcceptButton
'     PROP_VALUE=
'     PROP_NAME=AllowDrop
'     PROP_VALUE=False
'     PROP_NAME=KeyPreview
'     PROP_VALUE=False
'     PROP_NAME=CancelButton
'     PROP_VALUE=
'     PROP_NAME=Icon
'     PROP_VALUE=
'     PROP_NAME=Locked
'     PROP_VALUE=False
'     PROP_NAME=MaximumHeight
'     PROP_VALUE=0
'     PROP_NAME=MaximumWidth
'     PROP_VALUE=0
'     PROP_NAME=MinimumHeight
'     PROP_VALUE=0
'     PROP_NAME=MinimumWidth
'     PROP_VALUE=0
'     PROP_NAME=Tag
'     PROP_VALUE=
'   PROPERTIES_END
'   EVENTS_START
'   EVENTS_END
' WINFBE CONTROL_END
' WINFBE CONTROL_START Button
'   PROPERTIES_START
'     PROP_NAME=Name
'     PROP_VALUE=btn1
'     PROP_NAME=Left
'     PROP_VALUE=230
'     PROP_NAME=Top
'     PROP_VALUE=163
'     PROP_NAME=Width
'     PROP_VALUE=116
'     PROP_NAME=Height
'     PROP_VALUE=33
'     PROP_NAME=AllowDrop
'     PROP_VALUE=False
'     PROP_NAME=BackColor
'     PROP_VALUE=SYSTEM|Control
'     PROP_NAME=BackColorDown
'     PROP_VALUE=SYSTEM|Control
'     PROP_NAME=BackColorHot
'     PROP_VALUE=SYSTEM|Control
'     PROP_NAME=Font
'     PROP_VALUE=Segoe UI,9,400,0,0,0,1
'     PROP_NAME=TextForeColor
'     PROP_VALUE=SYSTEM|ControlText
'     PROP_NAME=TextBackColor
'     PROP_VALUE=SYSTEM|Control
'     PROP_NAME=TextForeColorDown
'     PROP_VALUE=SYSTEM|ControlText
'     PROP_NAME=TextBackColorDown
'     PROP_VALUE=SYSTEM|Control
'     PROP_NAME=Image
'     PROP_VALUE=
'     PROP_NAME=ImageWidth
'     PROP_VALUE=16
'     PROP_NAME=ImageHeight
'     PROP_VALUE=16
'     PROP_NAME=ImageMargin
'     PROP_VALUE=4
'     PROP_NAME=ImageHighDPI
'     PROP_VALUE=True
'     PROP_NAME=Text
'     PROP_VALUE=(&S)显示
'     PROP_NAME=TextAlign
'     PROP_VALUE=ButtonAlignment.MiddleCenter
'     PROP_NAME=TextMargin
'     PROP_VALUE=4
'     PROP_NAME=UseMnemonic
'     PROP_VALUE=True
'     PROP_NAME=ThemeSupport
'     PROP_VALUE=True
'     PROP_NAME=ToggleMode
'     PROP_VALUE=False
'     PROP_NAME=Enabled
'     PROP_VALUE=True
'     PROP_NAME=TabIndex
'     PROP_VALUE=1
'     PROP_NAME=TabStop
'     PROP_VALUE=True
'     PROP_NAME=Locked
'     PROP_VALUE=False
'     PROP_NAME=Tag
'     PROP_VALUE=
'     PROP_NAME=ToolTip
'     PROP_VALUE=
'     PROP_NAME=ToolTipBalloon
'     PROP_VALUE=False
'     PROP_NAME=Visible
'     PROP_VALUE=True
'   PROPERTIES_END
'   EVENTS_START
'     EVENT_NAME=Click
'   EVENTS_END
' WINFBE CONTROL_END
' WINFBE CONTROL_START TextBox
'   PROPERTIES_START
'     PROP_NAME=Name
'     PROP_VALUE=Text1
'     PROP_NAME=Left
'     PROP_VALUE=124
'     PROP_NAME=Top
'     PROP_VALUE=98
'     PROP_NAME=Width
'     PROP_VALUE=289
'     PROP_NAME=Height
'     PROP_VALUE=40
'     PROP_NAME=AcceptsReturn
'     PROP_VALUE=False
'     PROP_NAME=AcceptsTab
'     PROP_VALUE=False
'     PROP_NAME=AllowDrop
'     PROP_VALUE=False
'     PROP_NAME=BackColor
'     PROP_VALUE=SYSTEM|Window
'     PROP_NAME=BorderStyle
'     PROP_VALUE=ControlBorderStyle.Fixed3D
'     PROP_NAME=CharacterCasing
'     PROP_VALUE=CharacterCase.Normal
'     PROP_NAME=CueBannerText
'     PROP_VALUE=
'     PROP_NAME=Enabled
'     PROP_VALUE=True
'     PROP_NAME=Font
'     PROP_VALUE=Segoe UI,9,400,0,0,0,1
'     PROP_NAME=ForeColor
'     PROP_VALUE=SYSTEM|WindowText
'     PROP_NAME=HideSelection
'     PROP_VALUE=True
'     PROP_NAME=Locked
'     PROP_VALUE=False
'     PROP_NAME=Multiline
'     PROP_VALUE=False
'     PROP_NAME=PasswordChar
'     PROP_VALUE=
'     PROP_NAME=ReadOnly
'     PROP_VALUE=False
'     PROP_NAME=TextScrollBars
'     PROP_VALUE=ScrollBars.None
'     PROP_NAME=TabIndex
'     PROP_VALUE=2
'     PROP_NAME=TabStop
'     PROP_VALUE=True
'     PROP_NAME=Tag
'     PROP_VALUE=
'     PROP_NAME=ToolTip
'     PROP_VALUE=
'     PROP_NAME=ToolTipBalloon
'     PROP_VALUE=False
'     PROP_NAME=Text
'     PROP_VALUE=Text1
'     PROP_NAME=TextAlign
'     PROP_VALUE=TextAlignment.Left
'     PROP_NAME=Visible
'     PROP_VALUE=True
'     PROP_NAME=WordWrap
'     PROP_VALUE=False
'   PROPERTIES_END
'   EVENTS_START
'   EVENTS_END
' WINFBE CONTROL_END
' WINFBE FORM_END
' WINFBE_CODEGEN_START
#if 0
Declare Function frmMain_btn1_Click( ByRef sender As wfxButton, ByRef e As EventArgs ) As LRESULT

type frmMainType extends wfxForm
   private:
      temp as byte
   public:
      declare static function FormInitializeComponent( byval pForm as frmMainType ptr ) as LRESULT
      declare constructor
      ' Controls
      btn1 As wfxButton
      Text1 As wfxTextBox
end type


function frmMainType.FormInitializeComponent( byval pForm as frmMainType ptr ) as LRESULT
   dim as long nClientOffset

   pForm->Name = "frmMain"
   pForm->Text = "Form1"
   pForm->SetBounds(10,10,500,300)
   pForm->btn1.Parent = pForm
   pForm->btn1.Name = "btn1"
   pForm->btn1.Text = "(&S)显示"
   pForm->btn1.SetBounds(230,163-nClientOffset,116,33)
   pForm->btn1.OnClick = @frmMain_btn1_Click
   pForm->Text1.Parent = pForm
   pForm->Text1.Name = "Text1"
   pForm->Text1.Text = "Text1"
   pForm->Text1.SetBounds(124,98-nClientOffset,289,40)
   pForm->Controls.Add(ControlType.Button, @(pForm->btn1))
   pForm->Controls.Add(ControlType.TextBox, @(pForm->Text1))
   Application.Forms.Add(ControlType.Form, pForm)
   function = 0
end function

constructor frmMainType
   InitializeComponent = cast( any ptr, @FormInitializeComponent )
   this.FormInitializeComponent( @this )
end constructor

dim shared frmMain as frmMainType
#endif
' WINFBE_CODEGEN_END
' frmMain form code file
''
''
Function frmMain_btn1_Click( ByRef sender As wfxButton, ByRef e As EventArgs ) As LRESULT
   MessageBox(null,"FreeBasic 很好很强大!","你好!",MB_OK or MB_ICONINFORMATION)
   'MessageBox(null, "Hello World", "FreeBASIC", MB_OK)
   frmmain.text1.text="文本框字体改变啦~~~"
   
   Function = 0
End Function


3). WINFBE_VD_MAIN.bas:

Code: Select all

#Define UNICODE
#Define _WIN32_WINNT &h0602
#Include Once "windows.bi"
#Include Once "Afx\CWindow.inc"
#define CODEGEN_FORM
#define CODEGEN_BUTTON
#define CODEGEN_TEXTBOX
#Include once "WinFormsX\WinFormsX.bi"
Using Afx

' WINFBE_CODEGEN_START

Declare Function frmMain_Button1_Click( ByRef sender As wfxButton, ByRef e As EventArgs ) As LRESULT

type frmMainType extends wfxForm
   private:
      temp as byte
   public:
      declare static function FormInitializeComponent( byval pForm as frmMainType ptr ) as LRESULT
      declare constructor
      ' Controls
      Button1 As wfxButton
      Text1 As wfxTextBox
end type


function frmMainType.FormInitializeComponent( byval pForm as frmMainType ptr ) as LRESULT
   dim as long nClientOffset

   pForm->Name = "frmMain"
   pForm->Text = "Form1"
   pForm->SetBounds(10,10,500,300)
   pForm->Button1.Parent = pForm
   pForm->Button1.Name = "Button1"
   pForm->Button1.Text = "(&S)显示"
   pForm->Button1.SetBounds(315,185-nClientOffset,105,30)
   pForm->Button1.OnClick = @frmMain_Button1_Click
   pForm->Text1.Parent = pForm
   pForm->Text1.Name = "Text1"
   pForm->Text1.Text = "Text1"
   pForm->Text1.SetBounds(114,101-nClientOffset,264,26)
   pForm->Controls.Add(ControlType.Button, @(pForm->Button1))
   pForm->Controls.Add(ControlType.TextBox, @(pForm->Text1))
   Application.Forms.Add(ControlType.Form, pForm)
   function = 0
end function

constructor frmMainType
   InitializeComponent = cast( any ptr, @FormInitializeComponent )
   this.FormInitializeComponent( @this )
end constructor

dim shared frmMain as frmMainType

' WINFBE_CODEGEN_END

' ========================================================================================
' WinFBE - FreeBASIC Editor (Windows 32/64 bit)
' Visual Designer auto generated project
' ========================================================================================

' Main application entry point.
' Place any additional global variables or #include files here.

' For your convenience, below are some of the most commonly used WinFBX library
' include files. Uncomment the files that you wish to use in the project or add
' additional ones. Refer to the WinFBX Framework Help documentation for information
' on how to use the various functions.

' #Include Once "Afx\AfxFile.inc"
' #Include Once "Afx\AfxStr.inc"
' #Include Once "Afx\AfxTime.inc"
' #Include Once "Afx\CIniFile.inc"
' #Include Once "Afx\CMoney.inc"
' #Include Once "Afx\CPrint.inc"


Application.Run(frmMain)

#include once "E:\Learning\FreeBasic\ex\03\frmMain.inc"


Best Regards,
Peter
deltarho[1859]
Posts: 4292
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: How to setup Afx in FBE and start to using it?

Post by deltarho[1859] »

@PeterHu
got the WINFBX.chm … there is another FBX help file(s)(folder) in the all-in-one WinFBE package
The source information is the same for both. The format of the latter, according to Paul Squires, is the new way for Help files. I don't like that format one bit and much prefer a well-written chm file any day of the week. WINFBX.chm is a well-written chm file and is what I use.

I don't use visual designers – all my forms are designed manually on A4 paper and I use a high precision ruler for placing the controls. If I need to move a group of controls, I add a horizontal/vertical offset to them. Change the offsets, and a recompile sees the group move as one. Admittedly, a designer is faster, but my result is lean code and readable. Readable in the sense that I wrote it and not a designer.

My SetCompilerSwitchesII.bas was written using WinFBX and started life on A4 paper. Do I look like a dinosaur? No. Am I a dinosaur? Probably. :)

If you go to WinFBE File>Open Templates… there are quite a few examples. I used that quite a lot when I wrote Encrypternet. In fact, Encrypternet was my first use of WinFBX.

I have been using WinFBX for a few years now, but am not an expert by any means and not one to ask a question of. If you need help on WinFBE or WinFBX your best bet is to ask Paul Squires or José Roca respectively. Fortunately, they are two of the most helpful members of this forum.

You will not find WinFBX a 'walk in the park' but since it is 'wall to wall' SDK wrappers it is easier than pure SDK code. Of course, you can add your own SDK code without worrying about incompatibility issues.
deltarho[1859]
Posts: 4292
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: How to setup Afx in FBE and start to using it?

Post by deltarho[1859] »

Just a quick word.
PeterHu wrote:I think I am a bit closer to the whole picture on how a GUI program sources is organized.
That is not true. What you are looking at is how the designer works. None of the examples in File>Open Templates… rely on a designer.
Josep Roca
Posts: 564
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: How to setup Afx in FBE and start to using it?

Post by Josep Roca »

WinFBX is a framework to ease the use of the Windows API with FreeBasic. Among other things, it provides hundreds of wrapper procedures, a dynamic unicode string data type (CWSTR), string management procedures and unicode aware file management classes.

For GUI programming, it provides the CWindow class, that is 100% SDK compatible and must be used coding by hand, not a visual designer. It is documenmted here: https://github.com/JoseRoca/WinFBX/blob ... 20Class.md

Many templates are available directly from the WinFBE editor.

Most users don't want to code by hand, but to use a visual designer. The WinFBE editor provides a visual designer and a set of classes called generically WinFormsX that provide a syntax similar in nature to other languages, such vb.net, that also use visual designers. Instead of condig the GUI by hand, you drag and drop the GUI elements (buttons, labels, etc.) to the form and fill properties. Then the designer generates code to create the GUI and event handlers to deal with the notifications.

So you have two choices: to code by hand using the good old SDK style or to use a visual designer.

The non-GUI parts of the WinFBX framework can be used in any case.

The documentation for the WinFBX framework is available in the WinFBE editor and is also available in github:
https://github.com/JoseRoca/WinFBX/tree/master/docs

Other than the GUI templates, there are other examples that use WinFBX.
https://github.com/JoseRoca/WinFBX/tree/master/Examples

If you have already downloaded WinFBE, you don't need to download WinFBX, since the WinFBE download incorporates WinFBX, but WinFBX can also be used with other editors.
PaulSquires
Posts: 999
Joined: Jul 14, 2005 23:41

Re: How to setup Afx in FBE and start to using it?

Post by PaulSquires »

Hi Peter,
PeterHu wrote: Aug 18, 2022 0:21 Q1:I am confused because the codes in frmMain.inc are almost exactly the same already exist in WINFBE_VD_MAIN.bas,so why #include frmMain.inc again,doesn't this cause a compiler error?
DO NOT manually edit the WINFBE_VD_MAIN.bas file. That file is automatically generated by the visual designer and is the main file that is compiled by the FB compiler. You need to put your code within the editor and then when you start to compile, the editor will bundle all of the necessary files into code generation in files like WINFBE_VD_MAIN.bas and shell to the compiler to compile your application. So, yes, the code in WINFBE_VD_MAIN does indeed contain code from other files because it has to. I probably should just delete the WINFBE_VD_MAIN file after compiling in order to prevent this kind of confusion.
Q2:Why frmMain_btn1Click has to be a normal procedure rather than type(class) frmMainType's member procedure?

Code: Select all

Declare Function frmMain_btn1_Click( ByRef sender As wfxButton, ByRef e As EventArgs ) As LRESULT
Because that is the way that I designed it. :-)
Q3:Why type(class)member function FormInitializeComponent has to have a pointer parameter points to itself?

Code: Select all

declare static function FormInitializeComponent( byval pForm as frmMainType ptr ) as LRESULT

Code: Select all

constructor frmMainType
   InitializeComponent = cast( any ptr, @FormInitializeComponent )
   this.FormInitializeComponent( @this )
end constructor
You should NOT ever have to manually deal with this code. This code is part of the internal GUI framework that interacts with your code behind the scenes.

You should also join the planetsquires.com support forum for these types of questions. I monitor my forum much more closely than this forum and it is easier for myself and other WinFBE users to provide you with help.

Also, in September I will doing major additions and fixes to the visual designer portion of WinFBE. I recently finished the EDITOR portion of WinFBE as you can see with the recent version 3 release. Next step is to work on the visual designer. Lots of work to do there.

Overall, when the visual designer portion is finished I will do a better job with documentation.
PeterHu
Posts: 148
Joined: Jul 24, 2022 4:57

Re: How to setup Afx in FBE and start to using it?

Post by PeterHu »

Thank you all for the nice and patient guide!
Post Reply