MyFbFramework - My FreeBasic Framework

User projects written in or related to FreeBASIC.
Xusinboy Bekchanov
Posts: 782
Joined: Jul 26, 2018 18:28

Re: MyFbFramework - My FreeBasic Framework

Post by Xusinboy Bekchanov »

oyster wrote: Apr 09, 2022 16:27 is it possible to use `mff32.dll` in other language, for example, python?
Not all functions are exported. You need to create export functions for all object properties. I have created export functions for only the most necessary methods for the VisualFBEditor Designer and Add-ins.
Avata
Posts: 102
Joined: Jan 17, 2021 7:27

Re: MyFbFramework - My FreeBasic Framework

Post by Avata »

Examples: Dynamically load controls

This examples showing that how to dynamically load controls, changing the mouse pointer, dynamically add pictures to controls, and mouse control and moves controls location.

Code: Select all

#ifdef __FB_WIN32__
	'#cmdline "Templates\Files\Resource.rc"
#endif
Type ChoosePoint
	Dim x As Integer
	Dim y As Integer
End Type
Dim Shared As ChoosePoint MousePoint                  ' 记录鼠标按下时的坐标
Dim Shared Number As Integer = 0         ' 移动次数
Dim Shared As Long GameSize, GameSizeRow, GameSizeCol, BlankRow, BlankCol
Dim Shared As Integer  GameSelect, GameSelectOld, ButtonWidth, ButtonHeight
'#Region "Form"
	#include once "mff/Form.bi"
	#include once "mff/Picture.bi"
	#include once "mff/ImageBox.bi"
	#include once "mff/Label.bi"
	#include once "mff/GroupBox.bi"
	#include once "mff/ComboBoxEdit.bi"
	#include once "mff/CommandButton.bi"
	#include once "mff/Panel.bi"
	Using My.Sys.Forms
	
	Type Form1Type Extends Form
		Declare Static Sub Command1_Click_(ByRef Sender As Control)
		Declare Sub Command1_Click(ByRef Sender As Control)
		Declare Static Sub GameButton_Move_(ByRef Sender As Control)
		Declare Sub GameButton_Move(ByRef Sender As Control)
		Declare Sub DrawRect()
		Declare Static Sub Form_Show_(ByRef Sender As Form)
		Declare Sub Form_Show(ByRef Sender As Form)
		Declare Static Sub GameButton_MouseMove_(ByRef Sender As Control, MouseButton As Integer, x As Integer, y As Integer, Shift As Integer)
		Declare Sub GameButton_MouseMove(ByRef Sender As Control, MouseButton As Integer, x As Integer, y As Integer, Shift As Integer)
		
		Declare Static Sub GameButton_MouseUp_(ByRef Sender As Control, MouseButton As Integer, x As Integer, y As Integer, Shift As Integer)
		Declare Sub GameButton_MouseUp(ByRef Sender As Control, MouseButton As Integer, x As Integer, y As Integer, Shift As Integer)
		Declare Static Sub GameButton_KeyDown_(ByRef Sender As Control, Key As Integer, Shift As Integer)
		Declare Sub GameButton_KeyDown(ByRef Sender As Control, Key As Integer, Shift As Integer)
		Declare Static Sub GameButton_MouseDown_(ByRef Sender As Control, MouseButton As Integer, x As Integer, y As Integer, Shift As Integer)
		Declare Sub GameButton_MouseDown(ByRef Sender As Control, MouseButton As Integer, x As Integer, y As Integer, Shift As Integer)
		Declare Constructor
		
		Dim As Picture Picture1
		Dim As Panel Panel1
		'Dim As CommandButton GameButton(14)   ’ImageBox
		Dim As ImageBox GameButton(Any)
		Dim As Label Label1, Label2
		Dim As GroupBox GroupBox1
		Dim As ComboBoxEdit ComboBoxEdit1
		Dim As CommandButton Command1
	End Type
	
	Constructor Form1Type
		' Form1
		With This
			.Name = "Form1"
			.Text = "华容道"
			.Caption = "华容道"
			.Designer = @This
			'.Cursor = crWAIT
			.OnShow = @Form_Show_
			.SetBounds 0, 0, 812, 525
			.Designer = @This
		End With
		' Picture1
		With Picture1
			.Name = "Picture1"
			.Text = "Picture1"
			.TabIndex = 0
			.BackColor = 8421376
			.ForeColor = 255
			.SetBounds 6, 8, 385, 466
			.Designer = @This
			.Parent = @This
		End With
		ReDim GameButton(0) As ImageBox
		' GameButton(0)
		With GameButton(0)
			.Name = "GameButton(0)"
			.Text = "ImageBox1"
			.RealSizeImage = True
			.ForeColor = 8453888
			.BackColor = 0
			.BorderStyle = BorderStyles.bsClient
			.SetBounds 3, 3, 1, 1
			.OnMouseMove = @GameButton_MouseMove_
			.OnMove = @GameButton_Move_
			.Designer = @This
			.OnMouseUp = @GameButton_MouseUp_
			.OnKeyDown = @GameButton_KeyDown_
			.OnMouseDown = @GameButton_MouseDown_
			.Parent = @Picture1
		End With
		
		' Label1
		With Label1
			.Name = "Label1"
			.Text = "Label1"
			.TabIndex = 1
			.SetBounds 431, 9, 354, 52
			.Designer = @This
			.Parent = @This
		End With
		' Label2
		With Label2
			.Name = "Label2"
			.Text = "Label2"
			.TabIndex = 2
			.SetBounds 426, 72, 365, 61
			.Designer = @This
			.Parent = @This
		End With
		' GroupBox1
		With GroupBox1
			.Name = "GroupBox1"
			.Text = "最佳战绩"
			.TabIndex = 3
			.Caption = "最佳战绩"
			.SetBounds 426, 152, 363, 225
			.Designer = @This
			.Parent = @This
		End With
		' ComboBoxEdit1
		With ComboBoxEdit1
			.Name = "ComboBoxEdit1"
			.Text = "ComboBoxEdit1"
			.TabIndex = 4
			.SetBounds 12, 24, 130, 21
			.Designer = @This
			.Parent = @GroupBox1
		End With
		' Command1
		With Command1
			.Name = "Command1"
			.Text = "CommandButton1"
			.TabIndex = 5
			.SetBounds 431, 414, 115, 35
			.Designer = @This
			.OnClick = @Command1_Click_
			.Parent = @This
		End With
		' Panel1
		With Panel1
			.Name = "Panel1"
			.Text = "Panel1"
			.TabIndex = 6
			.SetBounds 669, 18, 116, 129
			.Designer = @This
			.Parent = @This
		End With
	End Constructor
	
	Private Sub Form1Type.GameButton_MouseDown_(ByRef Sender As Control, MouseButton As Integer, x As Integer, y As Integer, Shift As Integer)
		*Cast(Form1Type Ptr, Sender.Designer).GameButton_MouseDown(Sender, MouseButton, x, y, Shift)
	End Sub
	
	Private Sub Form1Type.GameButton_KeyDown_(ByRef Sender As Control, Key As Integer, Shift As Integer)
		*Cast(Form1Type Ptr, Sender.Designer).GameButton_KeyDown(Sender, Key, Shift)
	End Sub
	
	Private Sub Form1Type.GameButton_MouseUp_(ByRef Sender As Control, MouseButton As Integer, x As Integer, y As Integer, Shift As Integer)
		*Cast(Form1Type Ptr, Sender.Designer).GameButton_MouseUp(Sender, MouseButton, x, y, Shift)
	End Sub
	
	Private Sub Form1Type.Form_Show_(ByRef Sender As Form)
		*Cast(Form1Type Ptr, Sender.Designer).Form_Show(Sender)
	End Sub
	
	Private Sub Form1Type.GameButton_Move_(ByRef Sender As Control)
		*Cast(Form1Type Ptr, Sender.Designer).GameButton_Move(Sender)
	End Sub
	
	Private Sub Form1Type.GameButton_MouseMove_(ByRef Sender As Control, MouseButton As Integer, x As Integer, y As Integer, Shift As Integer)
		*Cast(Form1Type Ptr, Sender.Designer).GameButton_MouseMove(Sender, MouseButton, x, y, Shift)
	End Sub
	
	Private Sub Form1Type.Command1_Click_(ByRef Sender As Control)
		*Cast(Form1Type Ptr, Sender.Designer).Command1_Click(Sender)
	End Sub
	
	Dim Shared Form1 As Form1Type
	
	#ifndef _NOT_AUTORUN_FORMS_
		#define _NOT_AUTORUN_FORMS_
		
		Form1.Show
		
		App.Run
	#endif
'#End Region

Private Sub Form1Type.Command1_Click(ByRef Sender As Control)
	
End Sub


Private Sub Form1Type.DrawRect()
	Picture1.Canvas.Pen.Color = Picture1.BackColor
	Picture1.Canvas.Rectangle(GameButton(GameSelectOld).Left - 2, GameButton(GameSelectOld).Top - 2, GameButton(GameSelectOld).Left + GameButton(GameSelectOld).Width + 2, GameButton(GameSelectOld).Top + GameButton(GameSelectOld).Height + 2)
	Picture1.Canvas.Pen.Color = clRed 'Picture1.ForeColor
	Picture1.Canvas.Rectangle(GameButton(GameSelect).Left - 2, GameButton(GameSelect).Top - 2, GameButton(GameSelect).Left + GameButton(GameSelect).Width + 2, GameButton(GameSelect).Top + GameButton(GameSelect).Height + 2)
	
End Sub

Private Sub Form1Type.Form_Show(ByRef Sender As Form)
	' GameButton(0)
	ReDim GameButton(14) As ImageBox  'CommandButton '  ImageBox
	ButtonWidth = 120 'GameButton(0).Width
	ButtonHeight = 80 'GameButton(0).Height
	For i As Integer = 0 To 14
		With GameButton(i)
			.Name = "GameButton(" & Str(i) & ")"
			.Designer = @This
			.Text = "GameButton列" & Str((i Mod 3) + 1) & "行" & Str((i Mod 5) + 1)
			.Cursor =crHAND '14 - 手型
			.RealSizeImage = True
			.ForeColor = 8453888
			.BackColor = 33023
			.BorderStyle = BorderStyles.bsNone
			.SetBounds  3 + ButtonWidth * (i Mod 3 ), 3 + ButtonHeight * (i Mod 5), ButtonWidth - 3, ButtonHeight - 3
			.OnMouseMove = @GameButton_MouseMove_
			.OnMove = @GameButton_Move_
			.OnMouseUp = @GameButton_MouseUp_
			.OnMouseDown = @GameButton_MouseDown_
			.Parent = @Picture1
		End With
	Next
	For i As Integer = 0 To 14
		With GameButton(i)
		.Graphic.Bitmap.LoadFromFile(ExePath & "/Resources/" & Right("00" & 0, 2) & ".png", ButtonWidth, ButtonHeight)
		End With
	Next
End Sub

Private Sub Form1Type.GameButton_KeyDown(ByRef Sender As Control, Key As Integer, Shift As Integer)
	
End Sub

Private Sub Form1Type.GameButton_MouseUp(ByRef Sender As Control, MouseButton As Integer, x As Integer, y As Integer, Shift As Integer)
	Dim As Integer Index = Val(Mid(Sender.Name, InStrRev(Sender.Name, "(") + 1))
	GameButton(Index).Graphic.Bitmap.LoadFromFile(ExePath & "/Resources/" & Right("00" & 0, 2) & ".png", ButtonWidth, ButtonHeight)
End Sub

Private Sub Form1Type.GameButton_MouseDown(ByRef Sender As Control, MouseButton As Integer, x As Integer, y As Integer, Shift As Integer)
	Dim As Integer Index = Val(Mid(Sender.Name, InStrRev(Sender.Name, "(") + 1))
	'GameButton(Index).Graphic.Bitmap.LoadFromFile(ExePath & "/Resources/" & Right("00" & Index, 2) & "D.png")
	GameButton(Index).Graphic.Bitmap.LoadFromFile(ExePath & "/Resources/" & Right("00" & 0, 2) & "D.png", ButtonWidth, ButtonHeight)
	Picture1.Canvas.Pen.Color = Picture1.BackColor
	Picture1.Canvas.Rectangle(GameButton(GameSelectOld).Left - 1, GameButton(GameSelectOld).Top - 1, GameButton(GameSelectOld).Left + GameButton(GameSelectOld).Width + 1, GameButton(GameSelectOld).Top + GameButton(GameSelectOld).Height + 1)
	Picture1.Canvas.cls
	'	' 检测右面是否存在空位
	'	If checkMove(Pic_Chessman_Zu_2, "Right", 3) Then
	'		showChoosePic(Pic_Chessman_Zu_2, "Right", 3)
	'	End If
	'	' 检测左面是否存在空位
	'	If checkMove(Pic_Chessman_Zu_2, "Left", 3) Then
	'		showChoosePic(Pic_Chessman_Zu_2, "Left", 3)
	'	End If
	'	' 检测上面是否存在空位
	'	If checkMove(Pic_Chessman_Zu_2, "Top", 3) Then
	'		showChoosePic(Pic_Chessman_Zu_2, "Top", 3)
	'	End If
	'	' 检测上面是否存在空位
	'	If checkMove(Pic_Chessman_Zu_2, "Bottom", 3) Then
	'		showChoosePic(Pic_Chessman_Zu_2, "Bottom", 3)
	'	End If
	MousePoint.x = X
	MousePoint.y = Y
End Sub

Private Sub Form1Type.GameButton_MouseMove(ByRef Sender As Control, MouseButton As Integer, x As Integer, y As Integer, Shift As Integer)
	Dim As Integer Index = Val(Mid(Sender.Name, InStrRev(Sender.Name, "(") + 1))
	If GameSelect <> Index AndAlso Index >= 0 Then
		GameSelectOld = GameSelect
		GameSelect = Index
		DrawRect
		Print "GameSelectOld, GameSelect", GameSelectOld, GameSelect
	End If
	If MouseButton = 0 Then Sender.Location = Type<My.Sys.Drawing.Point>(Sender.Left + x - MousePoint.x, Sender.Top + y - MousePoint.y)
	'Print "MouseMove " & Sender.Name
End Sub

Private Sub Form1Type.GameButton_Move(ByRef Sender As Control)
	Dim As Integer Index = Val(Mid(Sender.Name, InStrRev(Sender.Name, "(") + 1))
	
End Sub

Avata
Posts: 102
Joined: Jan 17, 2021 7:27

Re: MyFbFramework - My FreeBasic Framework

Post by Avata »

Examples: Game Five in a row
"Wuziqi(also known as 'Five in a Row', Gomoku, GoLang) is a two-player abstract strategy game generally played with Go pieces on a 19x19 Go board.
Ruler
"The objective of the game is to be the first player to create a sequence of five same-colored pieces vertically, horizontally, or diagonally. Pieces are never taken off the board, and once the whole board is filled, the game draws.

Code: Select all

'五子棋的人工智能试验小程序
' vbnet实现五子棋的人工智能  http://www.west999.com/www/info/24067-1.htm
' 实现五子棋的人工智能五子棋的AI构想 https://blog.csdn.net/elizabethxxy/article/details/103150370?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_title~default-8.pc_relevant_default&spm=1001.2101.3001.4242.5&utm_relevant_index=11
' 由阿凡达翻译到freeBasic. 本程序需要MyFbFramework框架支持,并由VisualFBEditor进行可视化窗体设计
' 你可以拷贝,分发,修改,本程序中的任意代码, 期待你加入局域网对战功能
'
'修改历史:
'2022年4月12日 阿凡达增加棋盘大小可以动态修改,修复棋盘从10X0放大到19X19后算法不准,电脑乱走。
'2022年4月13日 阿凡达增加可换棋盘颜色, 调整搜索范围,改变游戏难易程度
#ifdef __FB_WIN32__
	#cmdline "VisualFBEditor.rc"
#endif

Dim Shared As Single MouseX, MouseY
Dim Shared As Integer mSteps, ChessR = 30, ChessSize, WinStepSum '棋子大小,棋盘大小 WinStepSum, 19->354, 10-> 192
'  定义虚拟桌面:
Dim Shared As Integer Table(Any, Any) ' =0, 无子, 1 黑子, 2 白子
'   定义当前玩家桌面空格的分数:
Dim Shared pScore(Any, Any) As Integer
'  定义当前电脑桌面空格的分数:
Dim Shared cScore(Any, Any) As Integer
'  定义玩家的获胜组合:
Dim Shared  PersonWin(Any, Any, Any) As Boolean
'  定义电脑的获胜组合:
Dim Shared  ComputerWin(Any, Any, Any) As Boolean
'  定义玩家的获胜组合标志:
Dim Shared  PersonFlag(Any) As Boolean
'  定义电脑的获胜组合标志:
Dim Shared ComputerFlag(Any) As Boolean
'  定义游戏有效标志
Dim Shared PlayingFlag As Boolean
Dim Shared As Integer zhX, zhY, zhXOld, zhYOld
Dim Shared As Integer colorPerson, ColorComputer, ColorLastStep, ColorChessBK, ColorChessGrid

'#Region "Form"
	#include once "mff/Form.bi"
	#include once "mff/Picture.bi"
	#include once "mff/ImageBox.bi"
	#include once "mff/Label.bi"
	#include once "mff/GroupBox.bi"
	#include once "mff/ComboBoxEdit.bi"
	#include once "mff/CommandButton.bi"
	#include once "mff/Panel.bi"
	#include once "mff/RadioButton.bi"
	#include once "mff/UpDown.bi"
	#include once "mff/TextBox.bi"
	#include once "mff/CheckBox.bi"
	#include once "mff/Dialogs.bi"
	#include once "mff/LinkLabel.bi"
	Using My.Sys.Forms
	
	
	Type frmWuziqiType Extends Form
		Declare Static Sub cmdStart_Click_(ByRef Sender As Control)
		Declare Sub cmdStart_Click(ByRef Sender As Control)
		Declare Static Sub GameButton_Move_(ByRef Sender As Control)
		Declare Sub GameButton_Move(ByRef Sender As Control)
		Declare Sub InitPlayEnvironment()
		Declare Sub CheckWhoWin(ByVal BlackOrWhite As Integer)
		Declare Sub ComputerAI
		Declare Function WinStepsTotal(ByVal n As Long) As Long
		Declare Sub DrawCompter(ByVal x As Integer, ByVal y As Integer)
		
		Declare Function WhoWin() As Integer
		Declare Static Sub Form_Show_(ByRef Sender As Form)
		Declare Sub Form_Show(ByRef Sender As Form)
		
		Declare Static Sub Picture1_MouseDown_(ByRef Sender As Control, MouseButton As Integer,x As Integer,y As Integer, Shift As Integer)
		Declare Sub Picture1_MouseDown(ByRef Sender As Control, MouseButton As Integer,x As Integer,y As Integer, Shift As Integer)
		Declare Static Sub Picture1_MouseMove_(ByRef Sender As Control, MouseButton As Integer,x As Integer,y As Integer, Shift As Integer)
		Declare Sub Picture1_MouseMove(ByRef Sender As Control, MouseButton As Integer,x As Integer,y As Integer, Shift As Integer)
		Declare Static Sub Picture1_Click_(ByRef Sender As Picture)
		Declare Sub Picture1_Click(ByRef Sender As Picture)
		Declare Static Sub UpDown1_Changing_(ByRef Sender As UpDown,Value As Integer,Direction As Integer)
		Declare Sub UpDown1_Changing(ByRef Sender As UpDown, Value As Integer, Direction As Integer)
		Declare Static Sub cmdChangBK_Click_(ByRef Sender As Control)
		Declare Sub cmdChangBK_Click(ByRef Sender As Control)
		Declare Constructor
		
		Dim As Picture Picture1
		Dim As GroupBox GroupBox1
		Dim As CommandButton cmdStart, cmdChangBK(1)
		Dim As RadioButton optComputer(1)
		Dim As Label lblInfomation, Label2, lblChessText(1), lblColorBK(1)
		Dim As UpDown UpDown1
		Dim As TextBox txtChessSize
		Dim As CheckBox chkComputerFirst
		Dim As LinkLabel LinkLblAbout
		'Dim As TextBox LinkLblAbout
		Dim As ColorDialog ColorDialog1
	End Type
	
	Constructor frmWuziqiType
		
		' frmWuziqi
		With This
			.Name = "frmWuziqi"
			.Text = "Wuziqi"  '"五子棋"
			.Designer = @This
			.BorderStyle = FormBorderStyle.FixedDialog
			.MaximizeBox = False
			.MinimizeBox = False
			.StartPosition = FormStartPosition.CenterScreen
			'.Cursor = crWait
			.OnShow = @Form_Show_
			.Graphic.Icon.LoadFromResourceID(1, , 48, 48)
			.BorderStyle = FormBorderStyle.FixedSingle
			.SetBounds 0, 0, 811, 667
			.Designer = @This
		End With
		' Picture1
		With Picture1
			.Name = "Picture1"
			.Text = "Picture1"
			.TabIndex = 0
			.Cursor = crHand
			.BackColor = 8421376
			.ForeColor = 255
			.SetBounds 6, 8, 625, 625
			.Designer = @This
			.OnMouseDown = @Picture1_MouseDown_
			.OnMouseMove = @Picture1_MouseMove_
			.OnClick = @Picture1_Click_
			.Parent = @This
		End With
		
		' GroupBox1
		With GroupBox1
			.Name = "GroupBox1"
			.Text = "Setting" '"设置"
			.TabIndex = 3
			.SetBounds 638, 13, 159, 242
			.Designer = @This
			.Parent = @This
		End With
		' cmdStart
		With cmdStart
			.Name = "cmdStart"
			.Text = "Restart"  '"重新开始"
			.TabIndex = 5
			.SetBounds 13, 198, 135, 35
			.Designer = @This
			.OnClick = @cmdStart_Click_
			.Parent = @GroupBox1
		End With
		' optComputer3
		With optComputer(0)
			.Name = "optComputer(0)"
			.Text = "Man-Computer Playing"
			.TabIndex = 5
			.Checked = True
			.SetBounds 16, 46, 129, 22
			.Designer = @This
			.Parent = @GroupBox1
		End With
		' optComputer4
		With optComputer(1)
			.Name = "optComputer(1)"
			.Text = "Man-Man Playing"
			.TabIndex = 6
			.SetBounds 15, 23, 127, 24
			.Designer = @This
			.Parent = @GroupBox1
		End With
		' lblInfomation
		With lblInfomation
			.Name = "lblInfomation"
			.Text = "lblInfomation"
			.TabIndex = 8
			.BackColor = 255
			.SetBounds 17, 166, 135, 26
			.Designer = @This
			.Parent = @GroupBox1
		End With
		' Label2
		With Label2
			.Name = "Label2"
			.Text = "Chess Board Size" '"棋盘大小:"
			.TabIndex = 8
			.SetBounds 19, 97, 67, 16
			.Designer = @This
			.Parent = @GroupBox1
		End With
		' UpDown1
		With UpDown1
			.Name = "UpDown1"
			.Text = "UpDown1"
			.TabIndex = 9
			.SetBounds 120, 93, 17, 25
			.Designer = @This
			.OnChanging = @UpDown1_Changing_
			.Parent = @GroupBox1
		End With
		' txtChessSize
		With txtChessSize
			.Name = "txtChessSize"
			.Text = "19"
			.TabIndex = 10
			.SetBounds 84, 98, 31, 17
			.Designer = @This
			.Parent = @GroupBox1
		End With
		' chkComputerFirst
		With chkComputerFirst
			.Name = "chkComputerFirst"
			.Text = "Computer first" '"电脑先下"
			.TabIndex = 9
			.Checked = True
			.SetBounds 18, 74, 117, 16
			.Designer = @This
			.Parent = @GroupBox1
		End With
		' LinkLblAbout
		With LinkLblAbout
			.Name = "LinkLblAbout"
			.Text = !"Wuziqi(also known as 'Five in a Row', Gomoku, GoLang) is a two-player abstract strategy game generally played with Go pieces on a 19x19 Go board.\r\rRuler:\r" & _
			!"The objective of the game is to be the first player to create a sequence of five same-colored pieces vertically, horizontally, or diagonally." & _
			!"Pieces are never taken off the board, and once the whole board is filled, the game draws.\r" & _
			!"This APP made by Avata with <a href=""https://www.freebasic.net/"">freeBasic</a>\r" & _
			!"Compile the source code need the <a href=""https://github.com/XusinboyBekchanov/MyFbFramework"">MyFbFramework</a> frame," & _
			!"Edited by freeBasic IDE <a href=""https://github.com/XusinboyBekchanov/VisualFBEditor"">VisualFBEditor</a> Visual design\r\r" & _
			!"Download address:<a href=""https://gitee.com/avata/MyFbFramework"">https://gitee.com/avata/MyFbFramework</a>\r " & _
			!"VisualFBEditor: <a href=""https://gitee.com/avata/VisualFBEditor""> https://gitee.com/avata/VisualFBEditor</a>"
			
			'			.Text = "五子棋是一款双人抽象策略游戏。" & Chr(13, 10) &  Chr(13, 10) & "规则:" & Chr(13, 10)  & _
			'					"每个玩家轮流放置自己的棋子,游戏的目标是成为第一个垂直,水平或对角线创建五个相同颜色棋子序列的玩家。" & _
			'					"棋子永远不会从棋盘上取下,一旦整个棋盘被填满,游戏平局。" & Chr(13, 10) & Chr(13, 10) & _
			'					"本程序是阿凡达用freeBasic语言编写并开源, " & _
			'					"源程序编译需要MyFbFramework框架支持," & _
			'					"并由VisualFBEditor进行可视化窗体设计。" & Chr(13, 10) & Chr(13, 10) & _
			'					"GitHub, 码云下载地址:" & Chr(13, 10) & "MyFbFramework框架: https://gitee.com/avata/MyFbFramework" & _
			'					Chr(13, 10) & "   VisualFBEditor: https://gitee.com/avata/VisualFBEditor"
			.TabIndex = 10
			'.Multiline = True
			'.WordWraps = True
			.SetBounds 639, 264, 159, 367
			.Designer = @This
			.Parent = @This
		End With
		' lblChessText
		With lblChessText(0)
			.Name = "lblChessText(0)"
			.Text = "Chess Background:"  '"Change Background" '"棋盘背景:"
			.TabIndex = 11
			.SetBounds 20, 120, 70, 16
			.Designer = @This
			.Parent = @GroupBox1
		End With
		
		With lblChessText(1)
			.Name = "lblChessText(1)"
			.Text = "Grid Color:"  '"Grid Color" '"网格颜色:"
			.TabIndex = 11
			.SetBounds 20, 141, 70, 16
			.Designer = @This
			.Parent = @GroupBox1
		End With
		
		' lblColorBK
		With lblColorBK(0)
			.Name = "lblColorBK(0)"
			.Text = ""
			.TabIndex = 12
			.Caption = ""
			.SetBounds 82, 121, 35, 14
			.Designer = @This
			.Parent = @GroupBox1
		End With
		' lblColorBK
		With lblColorBK(1)
			.Name = "lblColorBK(1)"
			.Text = ""
			.TabIndex = 12
			.Caption = ""
			.SetBounds 83, 141, 35, 14
			.Designer = @This
			.Parent = @GroupBox1
		End With
		
		' cmdChangBK
		With cmdChangBK(0)
			.Name = "cmdChangBK(0)"
			.Text = "..."
			.TabIndex = 13
			.Caption = "..."
			.SetBounds 120, 123, 27, 17
			.Designer = @This
			.OnClick = @cmdChangBK_Click_
			.Parent = @GroupBox1
		End With
		
		With cmdChangBK(1)
			.Name = "cmdChangBK(1)"
			.Text = "..."
			.TabIndex = 13
			.Caption = "..."
			.SetBounds 120, 141, 27, 17
			.Designer = @This
			.OnClick = @cmdChangBK_Click_
			.Parent = @GroupBox1
		End With
		
		' ColorDialog1
		With ColorDialog1
			.Name = "ColorDialog1"
			.SetBounds 692, 1, 16, 16
			.Designer = @This
			.Parent = @This
		End With
	End Constructor
	
	Private Sub frmWuziqiType.cmdChangBK_Click_(ByRef Sender As Control)
		*Cast(frmWuziqiType Ptr, Sender.Designer).cmdChangBK_Click(Sender)
	End Sub
	
	Private Sub frmWuziqiType.UpDown1_Changing_(ByRef Sender As UpDown,Value As Integer,Direction As Integer)
		*Cast(frmWuziqiType Ptr, Sender.Designer).UpDown1_Changing(Sender, Value, Direction)
	End Sub
	
	Private Sub frmWuziqiType.Picture1_Click_(ByRef Sender As Picture)
		*Cast(frmWuziqiType Ptr, Sender.Designer).Picture1_Click(Sender)
	End Sub
	
	Private Sub frmWuziqiType.Picture1_MouseMove_(ByRef Sender As Control, MouseButton As Integer, x As Integer, y As Integer, Shift As Integer)
		*Cast(frmWuziqiType Ptr, Sender.Designer).Picture1_MouseMove(Sender, MouseButton, x, y, Shift)
	End Sub
	
	Private Sub frmWuziqiType.Picture1_MouseDown_(ByRef Sender As Control, MouseButton As Integer,x As Integer,y As Integer, Shift As Integer)
		*Cast(frmWuziqiType Ptr, Sender.Designer).Picture1_MouseDown(Sender, MouseButton, x, y, Shift)
	End Sub
	
	Private Sub frmWuziqiType.Form_Show_(ByRef Sender As Form)
		*Cast(frmWuziqiType Ptr, Sender.Designer).Form_Show(Sender)
	End Sub
	
	Private Sub frmWuziqiType.cmdStart_Click_(ByRef Sender As Control)
		*Cast(frmWuziqiType Ptr, Sender.Designer).cmdStart_Click(Sender)
	End Sub
	
	Dim Shared frmWuziqi As frmWuziqiType
	
	#ifndef _NOT_AUTORUN_FORMS_
		#define _NOT_AUTORUN_FORMS_
		
		frmWuziqi.Show
		
		App.Run
	#endif
'#End Region

Private Sub frmWuziqiType.cmdStart_Click(ByRef Sender As Control)
	InitPlayEnvironment
End Sub

Private Sub frmWuziqiType.InitPlayEnvironment()
	'player.filename = ".\music\zhyu01.mid"
	'player.play()
	If ChessSize<> Val(txtChessSize.Text) Then
		ChessSize= Max(10, Min(19, Val(txtChessSize.Text)))
		txtChessSize.Text = Str(ChessSize)
		
		WinStepSum = max(WinStepsTotal(Val(txtChessSize.Text)), 192)
		ReDim As Integer Table(ChessSize+ 1, ChessSize+ 1) ' =0, 无子, 1 黑子, 2 白子
		'  定义虚拟桌面:
		ReDim Table(ChessSize, ChessSize) As Integer
		'   定义当前玩家桌面空格的分数:
		ReDim pScore(ChessSize, ChessSize) As Integer
		'  定义当前电脑桌面空格的分数:
		ReDim cScore(ChessSize, ChessSize) As Integer
		'  定义玩家的获胜组合:
		ReDim  PersonWin(ChessSize, ChessSize, WinStepSum) As Boolean
		'  定义电脑的获胜组合:
		ReDim  ComputerWin(ChessSize, ChessSize, WinStepSum) As Boolean
		'  定义玩家的获胜组合标志:
		ReDim  PersonFlag(WinStepSum) As Boolean
		'  定义电脑的获胜组合标志:
		ReDim ComputerFlag(WinStepSum) As Boolean
	End If
	With Picture1.Canvas
		.Pen.Color = ColorChessBK
		.CreateDoubleBuffer
		.Cls
		For i As Integer = 1 To ChessSize     ''''''画游戏棋盘ChessSize 19*19
			.Line i * ChessR + ChessR / 2, ChessR + ChessR / 2, i * ChessR + ChessR / 2, ChessSize * ChessR + ChessR / 2
			.TextOut i * ChessR + ChessR / 3, ChessR / 3, Str(i), clBlack
			.Line ChessR + ChessR / 2 , ChessR *i + ChessR / 2, ChessSize * ChessR + ChessR / 2, ChessR *i + ChessR / 2
			.TextOut  ChessR / 3 , ChessR *i + ChessR / 3 , Chr(i + 64), clBlack
		Next
		.DeleteDoubleBuffer
	End With
	
	PlayingFlag = True           '游戏有效
	lblInfomation.visible = True       '游戏状态标签显示
	lblInfomation.BackColor = frmWuziqi.BackColor
	lblInfomation.text = "Player Turn......"   '"等待玩家落子......"
	Dim  As Integer i, j, m, n
	
	'桌面初始化
	For i = 0 To ChessSize - 1
		For j = 0 To ChessSize - 1
			Table(i, j) = 0
		Next
	Next
	
	'获胜标志初始化
	For i = 0 To WinStepSum
		PersonFlag(i) = True
		ComputerFlag(i) = True
	Next
	
	'******** 初始化获胜组合 ********
	n = 0
	For i = 0 To ChessSize - 1
		For j = 0 To ChessSize - 5
			For m = 0 To 4
				PersonWin(j + m, i, n) = True
				ComputerWin(j + m, i, n) = True
			Next
			n = n + 1
		Next
	Next
	
	For i = 0 To ChessSize - 1
		For j = 0 To ChessSize - 5
			For m = 0 To 4
				PersonWin(i, j + m, n) = True
				ComputerWin(i, j + m, n) = True
			Next
			n = n + 1
		Next
	Next
	
	For i = 0 To ChessSize - 5
		For j = 0 To ChessSize - 5
			For m = 0 To 4
				PersonWin(j + m, i + m, n) = True
				ComputerWin(j + m, i + m, n) = True
			Next
			n = n + 1
		Next
	Next
	
	For i = 0 To ChessSize - 5
		For j = ChessSize - 1 To 4 Step -1
			For m = 0 To 4
				PersonWin(j - m, i + m, n) = True
				ComputerWin(j - m, i + m, n) = True
			Next
			n = n + 1
		Next
	Next
	
	''由于我们设定电脑先手,并下在了坐标ChessSize*ChessR / 2, 调用绘图函数绘制当前电脑先走的位置
	If chkComputerFirst.Checked = True Then
		zhX = ChessSize / 2 : zhY = ChessSize/ 2
		ZhXOld = -2: ZhYOld = -2
		DrawCompter((zhX + 1)*ChessR + ChessR / 2 , (zhY + 1)*ChessR + ChessR / 2 )
		Table(zhX , zhY) = 1              '由于我们设定电脑先手,并下了ChessSize / 2,ChessSize / 2位所以将其值设为1
		'由于电脑已下了ChessSize/ 2,ChessSize/ 2位所以我们需要重新设定玩家的获胜标志
		For i = 0 To WinStepSum
			If PersonWin(zhX,  zhY, i) = True Then
				PersonFlag(i) = False
			End If
		Next
	Else
		ZhXOld = -2: ZhYOld = -2
	End If
	
	'******** 初始化获胜组合结束 ********
	
End Sub

Private Sub frmWuziqiType.Form_Show(ByRef Sender As Form)
	Picture1.Style = 16
	colorPerson = clWhite: ColorComputer = clBlack: ColorLastStep = clPurple: ColorChessBK = 8421376: ColorChessGrid = &HF00f0000
	lblColorBK(0).BackColor = ColorChessBK
	lblColorBK(1).BackColor = ColorChessGrid  
	InitPlayEnvironment
End Sub

Private Sub frmWuziqiType.Picture1_MouseDown(ByRef Sender As Control, MouseButton As Integer, x As Integer, y As Integer, Shift As Integer)
	If PlayingFlag = False Then Exit Sub '检查游戏状态是否有效
	If x > ChessR  And y > ChessR  And x < ChessSize * ChessR + ChessR  And y < ChessSize * ChessR + ChessR Then
		Dim As Integer i, j, k
		k = mSteps Mod 2
		zhX =  Int(X / ChessR) - 1
		zhY =  Int(Y / ChessR) - 1
		Print Int(x / ChessR), Int(y / ChessR)
		'检查当前鼠标点击的格子是否有效
		For i = 0 To ChessSize - 1
			For j = 0 To ChessSize - 1
				If Table(zhX, zhY) > 0 Then
					Exit Sub
				End If
			Next
		Next
		
		Dim myColor As Integer
		'绘制玩家的棋子
		If ZhXOld > -1 Then
			Picture1.Canvas.Pen.Color = ColorComputer
			Picture1.Canvas.Brush.Color = ColorComputer
			Picture1.Canvas.Circle((zhXOld + 1) * ChessR + ChessR / 2, (zhYOld + 1) * ChessR + ChessR / 2, ChessR - 2, ColorComputer)
		End If
		Picture1.Canvas.Pen.Color = ColorLastStep
		Picture1.Canvas.Circle((zhX + 1) * ChessR + ChessR / 2, (zhY + 1) * ChessR + ChessR / 2, ChessR - 2, colorPerson)
		zhXOld = zhX:  zhYOld = zhY
		Table(zhX, zhY) = 2
		For i = 0 To WinStepSum
			If ComputerWin(zhX, zhY, i) = True Then
				ComputerFlag(i) = False
			End If
		Next
		
		'重设电脑的获胜标志
		CheckWhoWin(1)               '检查当前玩家是否获胜
		ComputerAI()                '调用电脑算法
	EndIf
	
End Sub

'*****************************************************************************
'** 模块名称: 获胜检查算法。 CheckWhoWin
'* *
'* * 描述: 此模块执行以下功能:
'* * 1. 检查是否和棋。
'* * 2. 检查电脑是否获胜。
'* * 3. 检查玩家是否获胜。
'**
'*****************************************************************************

Sub frmWuziqiType.CheckWhoWin(ByVal BlackOrWhite As Integer)
	Dim  As Integer i, j, k, m, n
	Dim ca As Integer
	Dim pa As Integer
	Dim ComputerNormal As Integer = 0
	Picture1.Cursor = crHand '14 - 手型
	For i = 0 To WinStepSum
		If ComputerFlag(i) = False Then ComputerNormal = ComputerNormal + 1
	Next
	
	'设定和棋规则
	If ComputerNormal = WinStepSum  - 1 Then
		lblInfomation.visible = True
		lblInfomation.BackColor = clBLue
		lblInfomation.text = "Noone Win." '"和棋,请重新开始!"
		PlayingFlag = False
		Exit Sub
	End If
	
	Dim As Integer Xmin, XMax, YMin, YMax
	Xmin = 0: XMax = ChessSize-1
	YMin = 0: YMax = ChessSize-1
	'检查电脑是否获胜
	For i = 0 To WinStepSum
		If ComputerFlag(i) = True Then
			ca = 0
			For j = Xmin To XMax
				For k = Ymin To YMax
					If Table(j, k) = 1 Then
						If ComputerWin(j, k, i) = True Then
							ca = ca + 1
						End If
					End If
				Next
			Next
			
			If ca = 5 Then
				lblInfomation.visible = True
				lblInfomation.BackColor = clGreen
				lblInfomation.text = "Computer win."  '"电脑获胜,请重新开始"
				PlayingFlag = False
				Exit Sub
			End If
		End If
	Next
	
	'检查玩家是否获胜
	For i = 0 To WinStepSum
		If PersonFlag(i) = True Then
			pa = 0
			For j = Xmin To XMax
				For k = Ymin To YMax
					If Table(j, k) = 2 Then
						If PersonWin(j, k, i) = True Then
							pa = pa + 1
						End If
					End If
				Next
			Next
			
			If pa = 5 Then
				lblInfomation.visible = True
				lblInfomation.BackColor = clRed
				lblInfomation.text = "Player Win."  '"玩家获胜,请重新开始"
				PlayingFlag = False
				Exit Sub
			End If
		End If
	Next
	
End Sub


'*****************************************************************************
'* * 模块名称: 电脑算法 ComputerAI

'** 描述: 此程序主要执行以下功能:
'** 1. 初始化赋值系统。
'** 2. 赋值加强算法。
'** 3. 计算电脑和玩家的最佳攻击位。
'** 4. 比较电脑和玩家的最佳攻击位并决定电脑的最佳策略。
'** 5. 执行检查获胜函数。
'*****************************************************************************

Sub frmWuziqiType.ComputerAI()
	Dim  As Integer i, j, k, m, n
	Dim dc As Integer
	Dim cab As Integer
	Dim pab As Integer
	If PlayingFlag = False Then Exit Sub
	lblInfomation.visible = True
	lblInfomation.BackColor = frmWuziqi.BackColor
	lblInfomation.text = "Computer Searching......"    ' "电脑思考中......"
	For i = 0 To ChessSize - 1
		For j = 0 To ChessSize - 1
			pScore(i, j) = 0
			cScore(i, j) = 0
		Next
	Next
	
	'调整搜索范围,改变游戏难易程度
	Dim As Integer Xmin, XMax, YMin, YMax
	'Xmin = Max(0, zhX - 8): XMax = Min(ChessSize-1, zhX + 8)
	'YMin = Max(0, zhY - 8): YMax = Min(ChessSize-1, zhY + 8)
	
	Xmin = 0: XMax = ChessSize-1
	YMin = 0: YMax = ChessSize-1
	'Print Xmin, XMax, Ymin, YMax
	Picture1.Cursor = crWait
	'初始化赋值数组
	'* * * * * * * * 电脑加强算法 * * * * * * * *
	For i = 0 To WinStepSum
		If ComputerFlag(i) = True Then
			cab = 0
			For j = Xmin To XMax
				For k = Ymin To YMax
					If Table(j, k) = 1 Then
						If ComputerWin(j, k, i) = True Then
							cab = cab + 1
						End If
					End If
				Next
			Next
			
			Select Case cab
			Case 3
				For m = Xmin To XMax
					For n = Ymin To YMax
						If Table(m, n) = 0 Then
							If ComputerWin(m, n, i) = True Then
								cScore(m, n) = cScore(m, n) + 5
							End If
						End If
					Next
				Next
			Case 4
				For m = Xmin To XMax
					For n = Ymin To YMax
						If Table(m, n) = 0 Then
							If ComputerWin(m, n, i) = True Then
								DrawCompter((m + 1) * ChessR + ChessR / 2, (n + 1) * ChessR + ChessR / 2)
								Table(m, n) = 1
								For dc = 0 To WinStepSum
									If PersonWin(m, n, dc) = True Then
										PersonFlag(dc) = False
										CheckWhoWin(1)
										Exit Sub
									End If
								Next
							End If
						End If
					Next
				Next
			End Select
		End If
	Next
	
	For i = 0 To WinStepSum
		If PersonFlag(i) = True Then
			pab = 0
			For j = Xmin To XMax
				For k = Ymin To YMax
					If Table(j, k) = 2 Then
						If PersonWin(j, k, i) = True Then
							pab = pab + 1
						End If
					End If
				Next
			Next
			
			Select Case pab
			Case 3
				For m = Xmin To XMax
					For n = Ymin To YMax
						If Table(m, n) = 0 Then
							If PersonWin(m, n, i) = True Then
								pScore(m, n) = pScore(m, n) + ChessR
							End If
						End If
					Next
				Next
			Case 4
				For m = Xmin To XMax
					For n = Ymin To YMax
						If Table(m, n) = 0 Then
							If PersonWin(m, n, i) = True Then
								DrawCompter((m + 1) * ChessR + ChessR / 2, (n + 1) * ChessR + ChessR / 2)
								Table(m, n) = 1
								For dc = 0 To WinStepSum
									If PersonWin(m, n, dc) = True Then
										PersonFlag(dc) = False
										CheckWhoWin(0)
										Exit Sub
									End If
								Next
							End If
						End If
					Next
				Next
			End Select
		End If
	Next
	
	'******** 电脑加强算法结束 ********
	
	'******** 赋值系统 ********
	For i = 0 To WinStepSum
		If ComputerFlag(i) = True Then
			For j = Xmin To XMax
				For k = Ymin To YMax
					If Table(j, k) = 0 Then
						If ComputerWin(j, k, i) = True Then
							For m = Xmin To XMax
								For n = Ymin To YMax
									If Table(m, n) = 1 Then
										If ComputerWin(m, n, i) = True Then
											cScore(j, k) = cScore(j, k) + 1
										End If
									End If
								Next
							Next
						End If
					End If
				Next
			Next
		End If
	Next
	
	For i = 0 To WinStepSum
		If PersonFlag(i) = True Then
			For j = Xmin To XMax
				For k = Ymin To YMax
					If Table(j, k) = 0 Then
						If PersonWin(j, k, i) = True Then
							For m = Xmin To XMax
								For n = Ymin To YMax
									If Table(m, n) = 2 Then
										If PersonWin(m, n, i) = True Then
											pScore(j, k) = pScore(j, k) + 1
										End If
									End If
								Next
							Next
						End If
					End If
				Next
			Next
		End If
	Next
	
	'******** 赋值系统结束 ********
	
	'* * * * * * * * 分值比较算法 * * * * * * * *
	Dim As Integer a, b, c, d
	Dim cs As Integer = 0
	Dim ps As Integer = 0
	For i = Xmin To XMax
		For j = Ymin To YMax
			If cScore(i, j) > cs Then
				cs = cScore(i, j)
				a = i
				b = j
			End If
		Next
		
	Next
	
	For i = Xmin To XMax
		For j = Ymin To YMax
			If pScore(i, j) > ps Then
				ps = pScore(i, j)
				c = i
				d = j
			End If
		Next
	Next
	
	If cs > ps Then
		DrawCompter((a + 1) * ChessR + ChessR / 2, (b + 1) * ChessR + ChessR / 2)
		Table(a, b) = 1
		For i = 0 To WinStepSum
			If PersonWin(a, b, i) = True Then
				PersonFlag(i) = False
			End If
		Next
	Else
		DrawCompter((c + 1) * ChessR + ChessR / 2, (d + 1) * ChessR + ChessR / 2)
		Table(c, d) = 1
		For i = 0 To WinStepSum
			If PersonWin(c, d, i) = True Then
				PersonFlag(i) = False
			End If
		Next
	End If
	lblInfomation.visible = True
	lblInfomation.BackColor = frmWuziqi.BackColor
	lblInfomation.text = "Player Turn......"  '"等待玩家落子......"
	'******** 分值比较算法结束 ********
	CheckWhoWin(0)
End Sub
''*****************************************************************************
'* * 模块名称: 绘制棋子  DrawCompter
'** 描述: 此函数主要进行电脑棋子的绘制。
'*****************************************************************************

Sub frmWuziqiType.DrawCompter(ByVal x As Integer, ByVal y As Integer)
	Dim As Integer tX, tY
	tX =  Int(x / ChessR)
	tY =  Int(Y / ChessR)
	lblInfomation.visible = True
	lblInfomation.BackColor = frmWuziqi.BackColor
	lblInfomation.text = "Player Turn......"  '"等待玩家落子......"
	If ZhXOld > -1 Then
		Picture1.Canvas.Pen.Color = colorPerson
		Picture1.Canvas.Brush.Color = colorPerson
		Picture1.Canvas.Circle((ZhXOld + 1) * ChessR + ChessR / 2, (ZhYOld + 1) * ChessR + ChessR / 2, ChessR - 2, colorPerson)
	End If
	Picture1.Canvas.Pen.Color = ColorLastStep
	Picture1.Canvas.Brush.Color = ColorComputer
	Picture1.Canvas.Circle(tX * ChessR + ChessR / 2, tY * ChessR + ChessR / 2, ChessR - 2, ColorComputer)
	ZhXOld = tX - 1: ZhYOld = tY - 1
End Sub

Public Function frmWuziqiType.WinStepsTotal(ByVal tChessSize As Long) As Long
	'根据输入的棋盘布局n*n计算总共有多少种获胜组合
	'假定棋盘为10X10相应的棋盘数组就是Table(9, 9)
	'水平方向每一列获胜组合是6共10列6*10=60
	' 垂直方向每一-行获胜组合是6共10行8*10=60
	'正对角线方向6+(5+4+3+2+1)*2=36
	'反对角线方向 6+(5+4+3+2+1)*2=36
	' 总的获胜组合数为60 + 60 + 36 +36= 192
	Dim As Long i, j, m, n
	'For i = n - 5 To 1 Step -1: n += i: Next
	'Return 2 * (2 * t + n - 4) + 2 * n * (n - 4)
	
	'******** 初始化获胜组合 ********
	n = 0
	n = 0
	For i = 0 To ChessSize - 1
		For j = 0 To ChessSize - 5
			n = n + 1
		Next
	Next
	
	For i = 0 To ChessSize - 1
		For j = 0 To ChessSize - 5
			n = n + 1
		Next
	Next
	
	For i = 0 To ChessSize - 5
		For j = 0 To ChessSize - 5
			n = n + 1
		Next
	Next
	
	For i = 0 To ChessSize - 5
		For j = ChessSize - 1 To 4 Step -1
			n = n + 1
		Next
	Next
	Return n
	
End Function

Private Sub frmWuziqiType.Picture1_MouseMove(ByRef Sender As Control, MouseButton As Integer,x As Integer,y As Integer, Shift As Integer)
	If x > ChessR And y > ChessR And x < ChessR * ChessSize And y < ChessR * ChessSize Then
		frmWuziqi.Cursor = crWait
	Else
		frmWuziqi.Cursor = crHand
	End If
End Sub


Private Sub frmWuziqiType.Picture1_Click(ByRef Sender As Picture)
	
End Sub

Private Sub frmWuziqiType.UpDown1_Changing(ByRef Sender As UpDown,Value As Integer,Direction As Integer)
	'Print "Value As Integer, Direction" & Value & " " & Direction
	If Val(txtChessSize.Text) >= 19 AndAlso Direction = 1 OrElse (Val(txtChessSize.Text) <= 10 AndAlso Direction = -1) Then Exit Sub
	txtChessSize.Text  = Str(Val(txtChessSize.Text) + Direction)
End Sub

Private Sub frmWuziqiType.cmdChangBK_Click(ByRef Sender As Control)
	Dim As Integer Index = Val(Mid(Sender.Name, InStrRev(Sender.Name, "(") + 1))
	ColorDialog1.Color = lblColorBK(Index).BackColor
	If ColorDialog1.Execute Then
		lblColorBK(Index).BackColor = ColorChessBK
		If Index = 0 Then
		ColorChessBK = ColorDialog1.Color
		Else
		ColorChessGrid = ColorDialog1.Color
		End If
	End If
End Sub

Xusinboy Bekchanov
Posts: 782
Joined: Jul 26, 2018 18:28

Re: MyFbFramework - My FreeBasic Framework

Post by Xusinboy Bekchanov »

Version 1.3.2 (April 16, 2022)
- Fixed: Unable to register class message
- Fixed: CheckBox Font in Dark Mode
- Added: Game FiveInARow example
- Added: Import Get function in Canvas like freeBasic Graphics function to grab an image
- Added: DPI Change handling
- Improved: AddRange control methods are available in gcc backend and 64-bit.
- Fixed: Reorder TabPage on Windows
- Fixed: GridData compiling
- Added: Location and Size properties to Control
- Fixed: Hanging in DoEvents Function
- Fixed: FromUTF8 function
Xusinboy Bekchanov
Posts: 782
Joined: Jul 26, 2018 18:28

Re: MyFbFramework - My FreeBasic Framework

Post by Xusinboy Bekchanov »

Version 1.3.3 (September 25, 2022)
- Fixed: WebBrowser Navigate method
- Fixed: Compiling with gtk2
- Added: HorizontalBox and VerticalBox container controls
- Fixed: Opening multiple files with OpenFileDialog on Linux
- Fixed: ActiveForm property of Application on Linux
- Fixed: Application Run method
- Fixed: Recreating OpenFileControl
- Added: Undo, PasteFromClipboard, CopyToClipboard, CutToClipboard, SelectAll methods to ComboBoxEdit and ComboBoxEx
- Fixed: the Index of Items for all Control
- Fixed: Crashing IDE on Linux
- Added: Ability to change properties of FolderBrowserDialog, FontDialog and ColorDialog through the Properties window
- Added: Ability to change properties of OpenFileDialog and SaveFileDialog through the Properties window
- Improved: Showing MDI Child Icon and Minimize, Restore and Close buttons in High DPI
- Fixed: Image and ImageKey property of MenuItem
- Added: ActiveMDIChild property to Application
- Fixed: Showing MDI Child Icon and Minimize, Restore, Close buttons on Dark Mode
- Added: __HIDE_NO_MAIN_FORM_ON_CLOSE__ define
- Fixed: RichTextBox TextRTF property and adding to Designer
- Fixed: BitmapWidth, BitmapHeight, ButtonWidth and ButtonHeight properties of ToolBar on High DPI
- Fixed: Set Colors in MDI forms
- Fixed: Show, Hide And CreateWnd methods of ToolTips
- Fixed: Drawing of the top menu when enabling and disabling elements of the top menu.
- Fixed: WebBrowser designing
- Changed: License to modifiedLGPL
- Added: ControlRepaint Export sub for Control, ChangeIndex method for List, PanelIndex property to StatusPanel, ChangePanelIndex method for StatusBar, ButtonIndex property to ToolButton, ChangeIndex method to ToolButtons
- Fixed: UpDown control
- Added: AutoSize property to ContainerControl
- Added: Vertical centering text of Label with CenterImage property
- Fixed: Dark mode of MDI Client window
- Added: OnColumnClick event to Grid
- Added: NumbersOnly property to TextBox
- Fixed: AllowDrop property of Control on Design mode
- Fixed: Form Closing errors
- Fixed: Dictionary IndexOfKey function
- Improved: Setting the default property of a CommandButton sets or unsets the DefaultButton property of the parent Form.
- Fixed: CommandButton Default property
- Fixed: ToolPalette Remove tool buttons
- Improved: Drawing checkboxes in CheckedListBox
- Added: OnActivate and OnDeActivate events to MDI Child
- Fixed: Tab on MDI Child
- Added: Selected property to ListView Item
- Fixed: MDI Form on High DPI
- Updated: Canvas functions in Linux for Scale
- Fixed: Crashing Chart control
- Improved: MDI Form
- Fixed: Set empty caption to MenuItem on Linux
- Added: ChangeIndex procedure to Control
- Added: ControlIndex property to Control
- Added: ParentMenuItem property to MeniItem
- Fixed: Form WindowState property on startup
- Fixed: Closing and Showing MDI Child
- Fixed: Showing MDI Child Form on Design Mode
- Added: MouseWheel to ScrollControl
- Added: ScrollControl on Linux
- Added: ScrollControl
- Added: OnLinkClicked event to ToolTips
- Fixed: KeyPress event of Controls to get Unicode symbols
- Fixed: ComboBoxEx Text Limit
- Fixed: Display of ComboBoxEx items with long text
- Improved: ComboBoxEx events
- Fixed: OnDblClick event of ComboBoxEx
- Improved: OnDblClick event triggers also in TextBox for ComboBoxEdit & ComboBoxEx.
- Added: ItemCount function and Clear method to ComboBoxEx (to extend the properties and methods of the base class)
- Added: AddItem, RemoveItem and InsertItem methods, Item and ItemData properties, IndexOf, Contains and IndexOfData functions to ComboBoxEx
- Fixed: Showing ToolPalette icons on High DPI
- Fixed: Compiling on Android
- Added: ByRef Idx parameter to WStringList Contains function
- Fixed: Get and set inner and outer text and html in function GetBody/SetBody of WebBrowser
- Added: ItemText parameter to IndexOf function of WStringList
- Improved: Control RequestAlign method
- Fixed: Showing ComboBoxEdit
- Fixed: Drawing GroupBox on Dark Mode
- Fixed: File number leak
- Fixed: Control Margins property
- Added: __USE_GTK4__ define
- Fixed: Refresh ComboBoxEdit items after change item by Index
- Fixed: LoadFromFile and SaveToFile functions of CheckedListBox, ComboBoxEdit and ListControl
- Added: LoadFromFile and SaveToFile functions
- Fixed: Showing EditControl Tooltip
- Fixed: Showing ToolTip for Form
- Improved: WLetEx function
- Added: MatchFullWords optional parameter to IndexOf function of Dictionary
- Improved: WStringList Sorted Add
- Added: MatchCase and MatchFullWords properties to WStringList
- Added: SortInsert parameter to WStringList Add function
- Improved: The speed IndexOf functions of WStringList and Dictionary
- Fixed: TextBox Left and Right Margins on High DPI
- Improved: Set Images to Menu from ImageList
- Fixed: Hang when changing IDE width at High DPI
- Fixed: ToolBar on High DPI
- Fixed: High DPI of ComboBoxEx, TabControl and ToolPalette controls
- Fixed: ComboBoxEdit Item Height on High DPI
- Fixed: ImageList on High DPI
- Added: My.Sys.Registry namespace
- Fixed: ToolButton State property
- Added: Debug.Clear function
- Changed: DebugPrint to Debug.Print
- Added: Printing with Debug.Print to Debug Window
- Added: Setting SelStart and SelEnd methods of TextBox in Constructor
- Improved: Dictionary IndexOfKey method
- Fixed: FromUTF8 function
- Fixed: TabPage on Designer
- Fixed: PopupMenu ParentWindow property (get)
- Added: Index Parameter to Control Add Method
- Added: Get and Set Menu and MenuItem Items by Key
- Added: TabControl DeleteTab by TabPage Pointer
- Fixed: Splitter update on moving
oyster
Posts: 274
Joined: Oct 11, 2005 10:46

Re: MyFbFramework - My FreeBasic Framework

Post by oyster »

it seems that mff develops rapidly. however the document or demo runs after mff.
document is a tedious work, may I suggest to add more demos to reflect the new functions if you have the time?
for example, "- Added: HorizontalBox and VerticalBox container controls"

Thanks
Xusinboy Bekchanov
Posts: 782
Joined: Jul 26, 2018 18:28

Re: MyFbFramework - My FreeBasic Framework

Post by Xusinboy Bekchanov »

oyster wrote: Sep 28, 2022 12:04 it seems that mff develops rapidly. however the document or demo runs after mff.
document is a tedious work, may I suggest to add more demos to reflect the new functions if you have the time?
for example, "- Added: HorizontalBox and VerticalBox container controls"

Thanks
Yes, help is always welcome.
oyster
Posts: 274
Joined: Oct 11, 2005 10:46

Re: MyFbFramework - My FreeBasic Framework

Post by oyster »

any way to reduce EXE file size?
For my project, the EXE is 633.5k on April 22nd which use mff cloned on April 22nd.
Now the date is Sep 28th, the EXE is bloated into 897.5k with latest mff. Can compiler choose only used lib to be linked?

For both cases, the same FreeBASIC-1.09.0-win64\fbc.exe is used and "create symbolic debug info" is not chosen in "project properties".
`strip` is used upon both EXE already.

I must claim that I know `upx` application. But `upx` is not the answer obviously.

thanks
Xusinboy Bekchanov
Posts: 782
Joined: Jul 26, 2018 18:28

Re: MyFbFramework - My FreeBasic Framework

Post by Xusinboy Bekchanov »

oyster wrote: Sep 28, 2022 13:45 any way to reduce EXE file size?
For my project, the EXE is 633.5k on April 22nd which use mff cloned on April 22nd.
Now the date is Sep 28th, the EXE is bloated into 897.5k with latest mff. Can compiler choose only used lib to be linked?

For both cases, the same FreeBASIC-1.09.0-win64\fbc.exe is used and "create symbolic debug info" is not chosen in "project properties".
`strip` is used upon both EXE already.

I must claim that I know `upx` application. But `upx` is not the answer obviously.

thanks
Added: ReadProperty_Off and WriteProperty_Off checks for ReadProperty and WriteProperty functions:
https://github.com/XusinboyBekchanov/My ... 7551aae743

These actions need to be performed on other controls too. I have now done only for the form and the classes belonging to them, to see the difference in size. The size of the empty form has decreased from 293 to 255. First it was 313 due to public functions (LoadFromFile and SaveToFile) in the Application.bas file. I changed them to Private. These unused functions were removed when compiled by the compiler and the size was 293.

To remove these functions at the beginning of the includes, you need to add ReadProperty_Off and WriteProperty_Off defines like this:

Code: Select all

'#Region "Form"
	#define ReadProperty_Off
	#define WriteProperty_Off
	#if defined(__FB_MAIN__) AndAlso Not defined(__MAIN_FILE__)
		#define __MAIN_FILE__
		Const _MAIN_FILE_ = __FILE__
		#ifdef __FB_WIN32__
			#cmdline "Form1.rc"
		#endif
	#endif
	#include once "mff/Form.bi"
	
	Using My.Sys.Forms
	
	Type Form1Type Extends Form
		
	End Type
	
	Dim Shared Form1 As Form1Type
	
	#if _MAIN_FILE_ = __FILE__
		Form1.MainForm = True
		Form1.Show
		App.Run
	#endif
'#End Region
oyster
Posts: 274
Joined: Oct 11, 2005 10:46

Re: MyFbFramework - My FreeBasic Framework

Post by oyster »

does that mean freebasic always link non-needed code into final binary file no matter which library is used?

will freebasic strip these code automatically?
oyster
Posts: 274
Joined: Oct 11, 2005 10:46

Re: MyFbFramework - My FreeBasic Framework

Post by oyster »

for my code
Error: Element not defined, ReadProperty 15 D:\VisualFBEditor\Controls\MyFbFramework\mff\TimerComponent.bas
Error: Element not defined, WriteProperty 25 D:\VisualFBEditor\Controls\MyFbFramework\mff\TimerComponent.bas
well you have said that "I have now done only for the form and the classes belonging to them". But I do not use timer at all
Xusinboy Bekchanov
Posts: 782
Joined: Jul 26, 2018 18:28

Re: MyFbFramework - My FreeBasic Framework

Post by Xusinboy Bekchanov »

oyster wrote: Sep 29, 2022 15:42 for my code
Error: Element not defined, ReadProperty 15 D:\VisualFBEditor\Controls\MyFbFramework\mff\TimerComponent.bas
Error: Element not defined, WriteProperty 25 D:\VisualFBEditor\Controls\MyFbFramework\mff\TimerComponent.bas
well you have said that "I have now done only for the form and the classes belonging to them". But I do not use timer at all
TimerComponent used inside Chart control.

Added: ReadProperty_Off and WriteProperty_Off checks for all ReadProperty and WriteProperty functions.
https://github.com/XusinboyBekchanov/My ... eb3d8a93ef

Now when compiling with these defines there should be no problems.
Xusinboy Bekchanov
Posts: 782
Joined: Jul 26, 2018 18:28

Re: MyFbFramework - My FreeBasic Framework

Post by Xusinboy Bekchanov »

oyster wrote: Sep 29, 2022 10:50 does that mean freebasic always link non-needed code into final binary file no matter which library is used?

will freebasic strip these code automatically?
The compiler removes only unused Private procedures (Functions, Subs, Properties, Constructors).

If these procedures are used in an unused Private procedure, then they are left in the final binary file.
oyster
Posts: 274
Joined: Oct 11, 2005 10:46

Re: MyFbFramework - My FreeBasic Framework

Post by oyster »

is there improvement space?

mff cloned on date, EXE size
April 22nd, 633.5k
Sep 28th, 897.5k
Sep 30th, 767.5k
Xusinboy Bekchanov
Posts: 782
Joined: Jul 26, 2018 18:28

Re: MyFbFramework - My FreeBasic Framework

Post by Xusinboy Bekchanov »

oyster wrote: Sep 30, 2022 1:02 is there improvement space?

mff cloned on date, EXE size
April 22nd, 633.5k
Sep 28th, 897.5k
Sep 30th, 767.5k
What components and controls are you using? I can see that the Chart control and TimerComponent have not changed since then.
Post Reply