⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 globalcode.bas

📁 一个用VB开发的细胞元动机
💻 BAS
字号:
Attribute VB_Name = "GlobalCode"
Option Explicit
'**********************  Global constants  **********************
Public Const g_constPreferedCellDim = 8
Public Const g_constAlive As Integer = 1
Public Const g_constDead As Integer = 0

'Actually draws an x since a circle of r = 1 is impossible to draw
Public Const g_constCircRadius As Integer = 1

'********************** Global variables ************************
Public g_iXMin As Integer
Public g_iYMin As Integer
Public g_iXMax As Integer
Public g_iYMax As Integer
Public g_iXColWidth As Integer
Public g_iYRowHeight As Integer
Public g_lGenCount As Long
Public g_iAliveCount As Integer

'Global variables used by Options Dialog
Public g_lMaxGens As Long
Public g_lInterval As Long
Public g_lAliveCellColor As Long
Public g_lFormBGColor As Long
Public g_lGridColor As Long
Public g_lGridVisible As Long

'g_iMaxRow and g_iMaxCol calculated in CalcGrid based on
'g_iXMax, g_iXMin, g_iYMax, g_iYMin, g_iYRowHeight, and g_iXColWidth
Public g_iMaxRow As Integer
Public g_iMaxCol As Integer

Public g_iCurrentScreenWidth As Integer

'g_bStarted is a flag set when the Start button is pressed
'that only allows for a Stop button event.
Public g_bStarted As Boolean
Public g_bGridReset As Boolean

'Global dynamic 2D arrays containing row, col for living, could live,
'and could die cells.
Public g_iWorld() As Integer
Public g_iNbrs() As Integer

'Global Cell collections
Public g_colCouldLive As New Cells
Public g_colCouldDie As New Cells
Public g_colLive As New Cells
Public g_colDie As New Cells

'Declarations for StartDoc function which opens LifeHelp.html
Declare Function ShellExecute Lib "shell32.dll" _
  Alias "ShellExecuteA" (ByVal hwnd As Long, _
  ByVal lpOperation As String, ByVal lpFile As String, _
  ByVal lpParameters As String, ByVal lpDirectory As String, _
  ByVal nShowCmd As Long) As Long

Declare Function GetDesktopWindow Lib "user32" () As Long


'Constants that can be used in ShellExecute
Global Const SW_SHOWNORMAL = 1
'Global Const SW_SHOWMINIMIZED = 2
'Global Const SW_SHOWMAXIMIZED = 3



'This function uses the ShellExecute API to automatically open the referenced file
'using the user's associated program. For Life it is being used to open a help html
'file using the user's associated web browser. If successful the function returns
'the hWnd of the newly launched program's window - zero if unsuccessful
Public Function StartDoc(DocName As String) As Long
    Dim Scr_hDC As Long
    Scr_hDC = GetDesktopWindow() 'Get the handle to the desktop
    StartDoc = ShellExecute(Scr_hDC, "Open", DocName, _
       "", "C:\", SW_SHOWNORMAL)
End Function



Public Sub SaveSettings()
Dim sKeyName As String
Dim sValueName As String
Dim lValue As Variant


sKeyName = "Software\Life\Settings"


sValueName = "Maximum Generations"
lValue = g_lMaxGens
VbRegSetValue HKEY_LOCAL_MACHINE, sKeyName, sValueName, REG_DWORD, lValue

sValueName = "Generation Delay"
lValue = g_lInterval
VbRegSetValue HKEY_LOCAL_MACHINE, sKeyName, sValueName, REG_DWORD, lValue

sValueName = "Alive Color"
lValue = g_lAliveCellColor
VbRegSetValue HKEY_LOCAL_MACHINE, sKeyName, sValueName, REG_DWORD, lValue

sValueName = "Background Color"
lValue = g_lFormBGColor
VbRegSetValue HKEY_LOCAL_MACHINE, sKeyName, sValueName, REG_DWORD, lValue

sValueName = "Grid Color"
lValue = g_lGridColor
VbRegSetValue HKEY_LOCAL_MACHINE, sKeyName, sValueName, REG_DWORD, lValue

sValueName = "Grid Visible"
lValue = g_lGridVisible
VbRegSetValue HKEY_LOCAL_MACHINE, sKeyName, sValueName, REG_DWORD, lValue

End Sub


Public Sub GetSettings()
Dim sKeyName As String
Dim sValueName As String
Dim lValue As Variant
Dim lDisp As Long


sKeyName = "Software\Life\Settings"

VbRegCreateKey HKEY_LOCAL_MACHINE, sKeyName, lDisp

If lDisp = REG_CREATED_NEW_KEY Then
    Call SaveSettings
End If


'Global variables used by Options Dialog and saved in Registry
' g_lMaxGens As Long
' g_lInterval As Long
' g_lAliveCellColor As Long
' g_lFormBGColor As Long
' g_lGridColor As Long
' g_lGridVisible As Long

sValueName = "Maximum Generations"
lValue = VbRegQueryValue(HKEY_LOCAL_MACHINE, sKeyName, sValueName)
g_lMaxGens = lValue

sValueName = "Generation Delay"
lValue = VbRegQueryValue(HKEY_LOCAL_MACHINE, sKeyName, sValueName)
g_lInterval = lValue

sValueName = "Alive Color"
lValue = VbRegQueryValue(HKEY_LOCAL_MACHINE, sKeyName, sValueName)
g_lAliveCellColor = lValue

sValueName = "Background Color"
lValue = VbRegQueryValue(HKEY_LOCAL_MACHINE, sKeyName, sValueName)
g_lFormBGColor = lValue

sValueName = "Grid Color"
lValue = VbRegQueryValue(HKEY_LOCAL_MACHINE, sKeyName, sValueName)
g_lGridColor = lValue

sValueName = "Grid Visible"
lValue = VbRegQueryValue(HKEY_LOCAL_MACHINE, sKeyName, sValueName)
g_lGridVisible = lValue

End Sub



Public Sub DoHelp()
Dim lTempVar As Long
Dim sFileToOpen As String

sFileToOpen = App.Path & "\Help\help.html"
lTempVar = StartDoc(sFileToOpen)
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -