VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Object = "{06E821D3-127B-411E-A820-6202994741D9}#12.0#0"; "DXVUMeter3.ocx"
Begin VB.Form frmMain 
   AutoRedraw      =   -1  'True
   Caption         =   "DXVU Spectrum Analyzer"
   ClientHeight    =   5370
   ClientLeft      =   2805
   ClientTop       =   6390
   ClientWidth     =   10095
   BeginProperty Font 
      Name            =   "Tahoma"
      Size            =   8.25
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   Icon            =   "frmMain.frx":0000
   LinkTopic       =   "Form1"
   LockControls    =   -1  'True
   ScaleHeight     =   5370
   ScaleWidth      =   10095
   Begin DXVUMeter3.dxVU3 dxvuCtrl 
      Height          =   2370
      Left            =   8220
      TabIndex        =   48
      Top             =   1995
      Visible         =   0   'False
      Width           =   915
      _ExtentX        =   1614
      _ExtentY        =   4180
      EnableRendering =   0   'False
      DrawGrid        =   0   'False
   End
   Begin VB.Timer tmrDoUpdate 
      Enabled         =   0   'False
      Interval        =   5
      Left            =   9450
      Top             =   1035
   End
   Begin VB.CheckBox chkUseRightChannel 
      Caption         =   "R"
      BeginProperty Font 
         Name            =   "Small Fonts"
         Size            =   6
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   210
      Left            =   2625
      Style           =   1  'Graphical
      TabIndex        =   40
      Top             =   4965
      Width           =   195
   End
   Begin VB.ComboBox cmbQuality 
      BeginProperty Font 
         Name            =   "Small Fonts"
         Size            =   6
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   270
      ItemData        =   "frmMain.frx":030A
      Left            =   720
      List            =   "frmMain.frx":0341
      Style           =   2  'Dropdown List
      TabIndex        =   39
      Top             =   4965
      Width           =   1680
   End
   Begin VB.PictureBox picRealScale 
      Appearance      =   0  'Flat
      AutoRedraw      =   -1  'True
      BorderStyle     =   0  'None
      DrawMode        =   10  'Mask Pen
      FillStyle       =   2  'Horizontal Line
      BeginProperty Font 
         Name            =   "Small Fonts"
         Size            =   6
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H80000008&
      Height          =   195
      Left            =   795
      ScaleHeight     =   195
      ScaleWidth      =   3450
      TabIndex        =   38
      Top             =   225
      Width           =   3450
   End
   Begin VB.CheckBox chkZoom 
      Height          =   195
      Left            =   90
      Picture         =   "frmMain.frx":043B
      Style           =   1  'Graphical
      TabIndex        =   36
      Top             =   2295
      Width           =   195
   End
   Begin VB.PictureBox picAmp 
      AutoRedraw      =   -1  'True
      BorderStyle     =   0  'None
      BeginProperty Font 
         Name            =   "Small Fonts"
         Size            =   6
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   1860
      Left            =   240
      ScaleHeight     =   1860
      ScaleWidth      =   210
      TabIndex        =   35
      Top             =   285
      Width           =   210
   End
   Begin VB.Frame frameOptions 
      BorderStyle     =   0  'None
      Height          =   1650
      Left            =   3195
      TabIndex        =   20
      Top             =   3390
      Width           =   2970
      Begin VB.CheckBox chkShowGrid 
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   195
         Left            =   0
         Style           =   1  'Graphical
         TabIndex        =   46
         TabStop         =   0   'False
         Top             =   1125
         Width           =   165
      End
      Begin VB.TextBox txtDTMF 
         Appearance      =   0  'Flat
         BeginProperty Font 
            Name            =   "Terminal"
            Size            =   9
            Charset         =   255
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   180
         Left            =   1440
         Locked          =   -1  'True
         MousePointer    =   1  'Arrow
         TabIndex        =   26
         ToolTipText     =   "Detected Digitis (Double Click to Clear)"
         Top             =   930
         Visible         =   0   'False
         Width           =   1530
      End
      Begin VB.CheckBox chkDTMF 
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   195
         Left            =   0
         Style           =   1  'Graphical
         TabIndex        =   25
         TabStop         =   0   'False
         Top             =   900
         Width           =   165
      End
      Begin VB.CheckBox chkShowEnergy 
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   195
         Left            =   0
         Style           =   1  'Graphical
         TabIndex        =   24
         TabStop         =   0   'False
         Top             =   0
         Width           =   165
      End
      Begin VB.CheckBox chkHoldPeaks 
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   195
         Left            =   0
         Style           =   1  'Graphical
         TabIndex        =   23
         TabStop         =   0   'False
         Top             =   225
         Width           =   165
      End
      Begin VB.CheckBox chkLog 
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   195
         Left            =   0
         Style           =   1  'Graphical
         TabIndex        =   22
         TabStop         =   0   'False
         Top             =   450
         Width           =   165
      End
      Begin VB.CheckBox chkColorScale 
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   195
         Left            =   0
         Style           =   1  'Graphical
         TabIndex        =   21
         TabStop         =   0   'False
         Top             =   675
         Width           =   165
      End
      Begin VB.Label Label6 
         AutoSize        =   -1  'True
         BackStyle       =   0  'Transparent
         Caption         =   "Show Grid"
         Height          =   195
         Left            =   255
         TabIndex        =   47
         Top             =   1140
         Width           =   720
      End
      Begin VB.Label lblDTMF 
         AutoSize        =   -1  'True
         BackStyle       =   0  'Transparent
         Caption         =   "DTMF Detection"
         Height          =   195
         Left            =   255
         TabIndex        =   31
         Top             =   915
         Width           =   1140
      End
      Begin VB.Label lblShowE 
         AutoSize        =   -1  'True
         BackStyle       =   0  'Transparent
         Caption         =   "Show Energy"
         Height          =   195
         Left            =   255
         TabIndex        =   30
         Top             =   0
         Width           =   945
      End
      Begin VB.Label lblHoldPeaks 
         AutoSize        =   -1  'True
         BackStyle       =   0  'Transparent
         Caption         =   "Hold Peaks"
         Height          =   195
         Left            =   255
         TabIndex        =   29
         Top             =   225
         Width           =   780
      End
      Begin VB.Label label 
         AutoSize        =   -1  'True
         BackStyle       =   0  'Transparent
         Caption         =   "Logarithmic Scale"
         Height          =   195
         Left            =   255
         TabIndex        =   28
         Top             =   450
         Width           =   1230
      End
      Begin VB.Label Label3 
         AutoSize        =   -1  'True
         BackStyle       =   0  'Transparent
         Caption         =   "Use Colorized Scale"
         Height          =   195
         Left            =   255
         TabIndex        =   27
         Top             =   675
         Width           =   1395
      End
   End
   Begin VB.Frame frameStyle 
      BorderStyle     =   0  'None
      Height          =   1140
      Left            =   105
      TabIndex        =   13
      Top             =   3390
      Width           =   2700
      Begin VB.ComboBox cmbWindow 
         BeginProperty Font 
            Name            =   "Small Fonts"
            Size            =   6
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   270
         ItemData        =   "frmMain.frx":08E5
         Left            =   1035
         List            =   "frmMain.frx":0901
         Style           =   2  'Dropdown List
         TabIndex        =   44
         Top             =   825
         Width           =   900
      End
      Begin VB.ComboBox cmbFFTSize 
         BeginProperty Font 
            Name            =   "Small Fonts"
            Size            =   6
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   270
         ItemData        =   "frmMain.frx":094A
         Left            =   1035
         List            =   "frmMain.frx":0960
         Style           =   2  'Dropdown List
         TabIndex        =   41
         Top             =   525
         Width           =   900
      End
      Begin VB.HScrollBar hsPA 
         Height          =   195
         LargeChange     =   10
         Left            =   1035
         Max             =   20
         Min             =   1
         TabIndex        =   18
         Top             =   300
         Value           =   10
         Width           =   1470
      End
      Begin VB.CommandButton cmdResetPreAmp 
         Height          =   195
         Left            =   2535
         TabIndex        =   17
         Top             =   300
         Width           =   165
      End
      Begin VB.OptionButton opMode 
         Appearance      =   0  'Flat
         BackColor       =   &H80000005&
         ForeColor       =   &H80000008&
         Height          =   240
         Index           =   0
         Left            =   0
         Picture         =   "frmMain.frx":0985
         Style           =   1  'Graphical
         TabIndex        =   16
         Top             =   0
         Value           =   -1  'True
         Width           =   240
      End
      Begin VB.OptionButton opMode 
         Appearance      =   0  'Flat
         BackColor       =   &H80000005&
         ForeColor       =   &H80000008&
         Height          =   240
         Index           =   1
         Left            =   300
         Picture         =   "frmMain.frx":0F0F
         Style           =   1  'Graphical
         TabIndex        =   15
         Top             =   0
         Width           =   240
      End
      Begin VB.OptionButton opMode 
         Appearance      =   0  'Flat
         BackColor       =   &H80000005&
         ForeColor       =   &H80000008&
         Height          =   240
         Index           =   2
         Left            =   615
         Picture         =   "frmMain.frx":1499
         Style           =   1  'Graphical
         TabIndex        =   14
         Top             =   0
         Width           =   240
      End
      Begin VB.Label Label5 
         AutoSize        =   -1  'True
         BackStyle       =   0  'Transparent
         Caption         =   "FFT Window"
         Height          =   195
         Left            =   15
         TabIndex        =   43
         Top             =   870
         Width           =   885
      End
      Begin VB.Label Label4 
         AutoSize        =   -1  'True
         BackStyle       =   0  'Transparent
         Caption         =   "FFT Size"
         Height          =   195
         Left            =   15
         TabIndex        =   42
         Top             =   570
         Width           =   600
      End
      Begin VB.Label Label2 
         AutoSize        =   -1  'True
         BackStyle       =   0  'Transparent
         Caption         =   "Input Gain"
         Height          =   195
         Left            =   15
         TabIndex        =   19
         Top             =   300
         Width           =   750
      End
   End
   Begin VB.Frame frameColors 
      BorderStyle     =   0  'None
      Height          =   1335
      Left            =   6480
      TabIndex        =   2
      Top             =   3390
      Width           =   1500
      Begin VB.PictureBox picColor 
         BackColor       =   &H0000FF00&
         Height          =   120
         Index           =   5
         Left            =   0
         MouseIcon       =   "frmMain.frx":1A23
         MousePointer    =   99  'Custom
         ScaleHeight     =   60
         ScaleWidth      =   180
         TabIndex        =   8
         Top             =   1215
         Width           =   240
      End
      Begin VB.PictureBox picColor 
         BackColor       =   &H0000FFFF&
         Height          =   120
         Index           =   4
         Left            =   0
         MouseIcon       =   "frmMain.frx":1B75
         MousePointer    =   99  'Custom
         ScaleHeight     =   60
         ScaleWidth      =   180
         TabIndex        =   7
         Top             =   1095
         Width           =   240
      End
      Begin VB.PictureBox picColor 
         BackColor       =   &H000000FF&
         Height          =   120
         Index           =   3
         Left            =   0
         MouseIcon       =   "frmMain.frx":1CC7
         MousePointer    =   99  'Custom
         ScaleHeight     =   60
         ScaleWidth      =   180
         TabIndex        =   6
         Top             =   975
         Width           =   240
      End
      Begin VB.PictureBox picColor 
         BackColor       =   &H000000C0&
         Height          =   240
         Index           =   2
         Left            =   0
         MouseIcon       =   "frmMain.frx":1E19
         MousePointer    =   99  'Custom
         ScaleHeight     =   180
         ScaleWidth      =   180
         TabIndex        =   5
         Top             =   585
         Width           =   240
      End
      Begin VB.PictureBox picColor 
         BackColor       =   &H0000FF00&
         Height          =   240
         Index           =   0
         Left            =   0
         MouseIcon       =   "frmMain.frx":1F6B
         MousePointer    =   99  'Custom
         ScaleHeight     =   180
         ScaleWidth      =   180
         TabIndex        =   4
         Top             =   0
         Width           =   240
      End
      Begin VB.PictureBox picColor 
         BackColor       =   &H00000000&
         Height          =   240
         Index           =   1
         Left            =   0
         MouseIcon       =   "frmMain.frx":20BD
         MousePointer    =   99  'Custom
         ScaleHeight     =   180
         ScaleWidth      =   180
         TabIndex        =   3
         Top             =   300
         Width           =   240
      End
      Begin VB.Label Label1 
         AutoSize        =   -1  'True
         BackStyle       =   0  'Transparent
         Caption         =   "Scale Color"
         Height          =   195
         Left            =   315
         TabIndex        =   12
         Top             =   1050
         Width           =   795
      End
      Begin VB.Label lblPeaksColor 
         AutoSize        =   -1  'True
         BackStyle       =   0  'Transparent
         Caption         =   "Peaks / Energy"
         Height          =   195
         Left            =   315
         TabIndex        =   11
         Top             =   615
         Width           =   1080
      End
      Begin VB.Label lblColorGraph 
         AutoSize        =   -1  'True
         BackStyle       =   0  'Transparent
         Caption         =   "Graphic"
         Height          =   195
         Left            =   315
         TabIndex        =   10
         Top             =   23
         Width           =   540
      End
      Begin VB.Label lblColorBack 
         AutoSize        =   -1  'True
         BackStyle       =   0  'Transparent
         Caption         =   "Background"
         Height          =   195
         Left            =   315
         TabIndex        =   9
         Top             =   330
         Width           =   840
      End
   End
   Begin MSComDlg.CommonDialog cDlgColor 
      Left            =   8340
      Top             =   180
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
   End
   Begin VB.PictureBox picScale 
      Appearance      =   0  'Flat
      AutoRedraw      =   -1  'True
      BackColor       =   &H00E0E0E0&
      DrawMode        =   10  'Mask Pen
      FillStyle       =   2  'Horizontal Line
      BeginProperty Font 
         Name            =   "Small Fonts"
         Size            =   6
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H80000008&
      Height          =   195
      Left            =   405
      ScaleHeight     =   165
      ScaleWidth      =   5715
      TabIndex        =   1
      Top             =   2310
      Width           =   5745
   End
   Begin VB.PictureBox picFFT 
      Appearance      =   0  'Flat
      AutoRedraw      =   -1  'True
      BackColor       =   &H00000000&
      CausesValidation=   0   'False
      FillColor       =   &H0000FF00&
      FillStyle       =   0  'Solid
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H80000008&
      Height          =   1905
      Left            =   390
      ScaleHeight     =   125
      ScaleMode       =   0  'User
      ScaleWidth      =   540
      TabIndex        =   0
      Top             =   300
      Width           =   8130
      Begin VB.Label lblInfo 
         Appearance      =   0  'Flat
         AutoSize        =   -1  'True
         BackColor       =   &H80000018&
         BorderStyle     =   1  'Fixed Single
         Caption         =   "Info"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H80000008&
         Height          =   225
         Left            =   0
         TabIndex        =   37
         Top             =   0
         Visible         =   0   'False
         Width           =   375
      End
      Begin VB.Shape shpMed 
         BackColor       =   &H000000FF&
         BackStyle       =   1  'Opaque
         BorderStyle     =   0  'Transparent
         DrawMode        =   3  'Not Merge Pen
         Height          =   990
         Left            =   720
         Top             =   420
         Visible         =   0   'False
         Width           =   615
      End
      Begin VB.Shape shpHi 
         BackColor       =   &H0000FF00&
         BackStyle       =   1  'Opaque
         BorderStyle     =   0  'Transparent
         DrawMode        =   3  'Not Merge Pen
         Height          =   585
         Left            =   45
         Top             =   0
         Visible         =   0   'False
         Width           =   555
      End
      Begin VB.Shape shpLow 
         BackColor       =   &H000000FF&
         BackStyle       =   1  'Opaque
         BorderStyle     =   0  'Transparent
         DrawMode        =   3  'Not Merge Pen
         Height          =   990
         Left            =   0
         Top             =   840
         Visible         =   0   'False
         Width           =   615
      End
      Begin VB.Line lnVDiv 
         BorderColor     =   &H00404040&
         DrawMode        =   7  'Invert
         Index           =   0
         X1              =   187
         X2              =   187
         Y1              =   14
         Y2              =   107
      End
   End
   Begin VB.Label lblDummy 
      AutoSize        =   -1  'True
      BackStyle       =   0  'Transparent
      Caption         =   "dummy"
      BeginProperty Font 
         Name            =   "Small Fonts"
         Size            =   6
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   150
      Left            =   6930
      TabIndex        =   45
      Top             =   4980
      Visible         =   0   'False
      Width           =   375
   End
   Begin VB.Image imgSpan 
      Height          =   120
      Left            =   3450
      MousePointer    =   9  'Size W E
      Picture         =   "frmMain.frx":220F
      Top             =   2550
      Width           =   120
   End
   Begin VB.Image cmdSwitch 
      Appearance      =   0  'Flat
      Height          =   480
      Left            =   90
      MouseIcon       =   "frmMain.frx":26B9
      MousePointer    =   99  'Custom
      Picture         =   "frmMain.frx":280B
      Top             =   4815
      Width           =   480
   End
   Begin VB.Label lblSpectrumStyle 
      AutoSize        =   -1  'True
      BackStyle       =   0  'Transparent
      Caption         =   "Spectrum Style"
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   195
      Left            =   165
      TabIndex        =   34
      Top             =   2955
      Width           =   1305
   End
   Begin VB.Label lblOptions 
      AutoSize        =   -1  'True
      BackStyle       =   0  'Transparent
      Caption         =   "Options"
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   195
      Left            =   3255
      TabIndex        =   33
      Top             =   2955
      Width           =   645
   End
   Begin VB.Label lblColors 
      AutoSize        =   -1  'True
      BackStyle       =   0  'Transparent
      Caption         =   "Colors"
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   195
      Left            =   6540
      TabIndex        =   32
      Top             =   2955
      Width           =   525
   End
   Begin VB.Image imgHiF 
      Height          =   120
      Left            =   2070
      MousePointer    =   9  'Size W E
      Picture         =   "frmMain.frx":30D5
      Stretch         =   -1  'True
      Top             =   2595
      Width           =   120
   End
   Begin VB.Image imgLowF 
      Height          =   120
      Left            =   1695
      MousePointer    =   9  'Size W E
      Picture         =   "frmMain.frx":321F
      Stretch         =   -1  'True
      Top             =   2610
      Width           =   120
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Dim IsStereo As Boolean
Dim Is16bits As Boolean
Dim IsRunning As Boolean

Dim FFTMode As Integer

Dim IsDragging As Boolean

Dim WithEvents eFFTLib As DXVUFFT.FFT
Attribute eFFTLib.VB_VarHelpID = -1
Dim FFTLib As New DXVUFFT.FFT
Dim MyPref As PrefDef

Private Const WM_PAINT = &HF

Dim LastDTMF As Integer
Dim WithEvents msgSC As SmartSubClass
Attribute msgSC.VB_VarHelpID = -1

Private Sub FixFocus()

    On Error Resume Next
    picFFT.SetFocus
    
    SetPreferences

End Sub

Private Sub chkColorScale_Click()

    FixFocus

End Sub

Private Sub chkDTMF_Click()

    Dim CorrectSettings As String
    
    If chkDTMF.Value = vbChecked Then
        If MyPref.FFTSize <> 512 Then CorrectSettings = CorrectSettings + "The Recommneded FFT Size is: 512" + vbCrLf
        If MyPref.FFTWindow <> wcNone Then CorrectSettings = CorrectSettings + "The Recommneded FFT Window is: (none)" + vbCrLf
        If dxvuCtrl.Quality <> qc44M16 Then CorrectSettings = CorrectSettings + "The Recommneded Sampling Rate is: 44KHz @ 16bit Mono" + vbCrLf
        
        If CorrectSettings <> "" Then
            MsgBox "In order to enhance the performance and accuracy of the DTMF detection algorithm," + vbCrLf + "please make sure you configure Frequency Analyzer with the following settings:" + vbCrLf + vbCrLf + CorrectSettings, vbInformation + vbOKOnly, "DTMF Detection Algorithm Recommended Settings"
        End If
    End If
    
    LastDTMF = -1

    txtDTMF.Visible = (chkDTMF.Value = vbChecked)
    If Not txtDTMF.Visible Then txtDTMF.Text = ""
    FixFocus

End Sub

Private Sub chkHoldPeaks_Click()

    FixFocus

End Sub

Private Sub chkLog_Click()

    FixFocus
    UpdateScale

End Sub

Private Sub chkShowEnergy_Click()

    FixFocus

End Sub

Private Sub SetPreferences()

    With MyPref
        .FFTWindow = cmbWindow.ListIndex
        .DetectDTMF = (chkDTMF.Value = vbChecked)
        .GraphColor = IIf(chkColorScale.Value = vbChecked, vbWhite, picFFT.FillColor)
        .GraphMode = FFTMode
        .HoldPeaks = (chkHoldPeaks.Value = vbChecked)
        .Is16bits = Is16bits
        .IsStereo = IsStereo
        .LogScale = (chkLog.Value = vbChecked)
        .MaxFreq = GetFreq()
        .PeaksColor = picColor(2).BackColor
        Set .picFFT = picFFT
        .PreAmp = hsPA.Value / 10
        .ShowEnergy = (chkShowEnergy.Value = vbChecked)
        .ZoomToScale = (chkZoom.Value = vbChecked)
        .UseRightChannel = (chkUseRightChannel.Value = vbChecked)
        .FFTSize = cmbFFTSize.Text
        
        ' The support for Equalization is still under development
        ' To create equalization lines, simply redim the EQ array to the number
        ' of lines you want to have (minus one).
        'ReDim .EQ(0)
        
        ' Then set the Freq to the frequency you want the line to affect
        '.EQ(0).Freq = 5000
        
        ' Set the Gain or amount of equalization
        '.EQ(0).Gain = 5
        
        ' And finally set the bandwith (or octave)
        '.EQ(0).Width = 10
    End With
    
    shpLow.Visible = (chkColorScale.Value = vbChecked)
    shpMed.Visible = (chkColorScale.Value = vbChecked)
    shpHi.Visible = (chkColorScale.Value = vbChecked)
    
    picFFT.BackColor = IIf(chkColorScale.Value = vbChecked, vbBlack, picColor(1).BackColor)
    
    FFTLib.Preferences = MyPref

End Sub

Private Function GetFreq() As Long

    Select Case dxvuCtrl.Quality
        Case qc11M08, qc11M16, qc11S08, qc11S16
            GetFreq = 11025
        Case qc22M08, qc22M16, qc22S08, qc22S16
            GetFreq = 22050
        Case qc44M08, qc44M16, qc44S08, qc44S16
            GetFreq = 44100
    End Select

End Function

Private Sub chkShowGrid_Click()

    MyPref.ShowGrid = (chkShowGrid.Value = vbChecked)
    UpdateScale
    FixFocus
    
End Sub

Private Sub chkUseRightChannel_Click()

    FixFocus

End Sub

Private Sub chkZoom_Click()

    FixFocus
    UpdateScale

End Sub

Private Sub cmbFFTSize_Click()

    FixFocus

End Sub

Private Sub cmbQuality_Click()

    dxvuCtrl.Quality = cmbQuality.ItemData(cmbQuality.ListIndex)
    
    If MyPref.Min > GetFreq Then MyPref.Min = 0
    If MyPref.Max > GetFreq Then MyPref.Max = GetFreq
    MyPref.MaxFreq = GetFreq
    
    If InStr(cmbQuality.Text, "Stereo") Then
        chkUseRightChannel.Enabled = True
    Else
        chkUseRightChannel.Enabled = False
        chkUseRightChannel.Value = vbUnchecked
    End If

End Sub

Private Sub cmbWindow_Click()

    FixFocus

End Sub

Private Sub cmdSwitch_Click()

    SetPreferences

    If IsRunning Then
        IsRunning = False
        cmdSwitch.Picture = LoadResPicture(101, vbResIcon)
        cmbQuality.Enabled = True
        dxvuCtrl.StopVU
        DoEvents
        picFFT.Cls
    Else
        cmbQuality.Enabled = False
        IsRunning = True
    
        Select Case dxvuCtrl.Quality
            Case qc11M08, qc22M08, qc44M08
                IsStereo = False
                Is16bits = False
            Case qc11S08, qc22S08, qc44S08
                IsStereo = True
                Is16bits = False
            Case qc11M16, qc22M16, qc44M16
                IsStereo = False
                Is16bits = True
            Case qc11S16, qc22S16, qc44S16
                IsStereo = True
                Is16bits = True
        End Select
        cmdSwitch.Picture = LoadResPicture(102, vbResIcon)
        dxvuCtrl.StartVU
    End If
    
    FixFocus

End Sub

Private Sub cmdResetPreAmp_Click()

    hsPA.Value = 10

End Sub

Private Sub dxvuCtrl_PeakValues(Values() As Byte, FromPos As Long, ToPos As Long)

    FFTLib.DoFFT FromPos, ToPos, Values
    
End Sub

Private Sub eFFTLib_DTMF(Number As Integer)

    Static Pause As Integer
    Static Hold As Integer
    
    If Number = -1 Then
        If Pause < 100 Then Pause = Pause + 1
        If Pause > 4 Then
            Hold = 0
            LastDTMF = -1
        End If
        Exit Sub
    Else
        Pause = 0
        If LastDTMF = Number And Hold < 100 Then Hold = Hold + 1
        If Hold < 2 And LastDTMF <> Number Then
            LastDTMF = Number
            txtDTMF.Text = txtDTMF.Text + Chr(Number + 48)
            txtDTMF.SelStart = Len(txtDTMF.Text)
        End If
    End If

End Sub

Private Sub Form_Load()

    Set eFFTLib = FFTLib
    Set msgSC = New SmartSubClass
    msgSC.SubClassHwnd Me.hwnd, True
    
    With Screen
        Move (.Width - Width) / 2, (.Height - Height) / 2
    End With
    
    SetCaption
    
    picColor(0).BackColor = GetSetting(App.EXEName, "Settings", "GraphicColor", 65535)
    picColor(1).BackColor = GetSetting(App.EXEName, "Settings", "BackgroundColor", vbBlack)
    picColor(2).BackColor = GetSetting(App.EXEName, "Settings", "Peaks", 4245759)
    
    picColor(5).BackColor = GetSetting(App.EXEName, "Settings", "ScaleLowColor", vbGreen)
    picColor(4).BackColor = GetSetting(App.EXEName, "Settings", "ScaleMedColor", vbYellow)
    picColor(3).BackColor = GetSetting(App.EXEName, "Settings", "ScaleHiColor", vbRed)
    
    opMode(GetSetting(App.EXEName, "Settings", "Mode", 0)).Value = True
    
    cmbWindow.ListIndex = GetSetting(App.EXEName, "Settings", "Window", 0)
    chkShowEnergy.Value = GetSetting(App.EXEName, "Settings", "ShowEnergy", vbUnchecked)
    chkHoldPeaks.Value = GetSetting(App.EXEName, "Settings", "HoldPeaks", vbUnchecked)
    chkColorScale.Value = GetSetting(App.EXEName, "Settings", "ColorizedScale", vbUnchecked)
    chkZoom.Value = GetSetting(App.EXEName, "Settings", "Zoom2Scale", vbUnchecked)
    chkShowGrid.Value = GetSetting(App.EXEName, "Settings", "ShowGrid", vbChecked)
    chkDTMF.Value = GetSetting(App.EXEName, "Settings", "DTMF", vbUnchecked)
    
    cmbFFTSize.ListIndex = GetSetting(App.EXEName, "Settings", "FFTSize", 2)
    
    hsPA.Value = GetSetting(App.EXEName, "Settings", "Gain", 10)
    
    MyPref.Min = GetSetting(App.EXEName, "Settings", "MinFreq", 0)
    MyPref.Max = GetSetting(App.EXEName, "Settings", "MaxFreq", GetFreq)
    
    cmbQuality.ListIndex = GetSetting(App.EXEName, "Settings", "Quality", 5)
    
    UpdateColors
    
    ' BETA NOTIFICATION
     MsgBox "FFT 2.0 is still under development. Some features such as the Logarithmic scale and the DTMF detection are not working properly", vbInformation + vbOKOnly, "FFT 2.0"
    
End Sub

Private Sub SetCaption()

    Caption = "DXVU Spectrum Analyzer " & App.Major & "." & App.Minor & "." & App.Revision

End Sub

Private Sub UpdateColors()

    Dim c() As Integer

    picFFT.FillColor = picColor(0).BackColor
    picFFT.BackColor = picColor(1).BackColor
    
    c = GetRGB(picColor(3).BackColor)
    shpHi.BackColor = RGB(c(0) Xor &HFF, c(1) Xor &HFF, c(2) Xor &HFF)
    shpHi.ZOrder 0
    
    c = GetRGB(picColor(4).BackColor)
    shpMed.BackColor = RGB(c(0) Xor &HFF, c(1) Xor &HFF, c(2) Xor &HFF)
    shpMed.ZOrder 0
    
    c = GetRGB(picColor(5).BackColor)
    shpLow.BackColor = RGB(c(0) Xor &HFF, c(1) Xor &HFF, c(2) Xor &HFF)
    shpLow.ZOrder 0
    
    lblInfo.ZOrder 0
    
    SetPreferences

End Sub

Private Function GetRGB(c As Long) As Integer()
    
    Dim r(0 To 2) As Integer
    r(2) = (c And &HFF0000) / &H10000
    r(1) = ((c And &HFF00) / &H100) And &HFF
    r(0) = (c And &HFF)
    
    GetRGB = r

End Function

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)

    Dim i As Integer
    
    msgSC.SubClassHwnd Me.hwnd, False

    SaveSetting App.EXEName, "Settings", "GraphicColor", picColor(0).BackColor
    SaveSetting App.EXEName, "Settings", "BackgroundColor", picColor(1).BackColor
    SaveSetting App.EXEName, "Settings", "Peaks", picColor(2).BackColor
    
    SaveSetting App.EXEName, "Settings", "ScaleLowColor", picColor(5).BackColor
    SaveSetting App.EXEName, "Settings", "ScaleMedColor", picColor(4).BackColor
    SaveSetting App.EXEName, "Settings", "ScaleHiColor", picColor(3).BackColor
    
    For i = opMode.LBound To opMode.UBound
        If opMode(i).Value Then Exit For
    Next i
    SaveSetting App.EXEName, "Settings", "Mode", i
    
    SaveSetting App.EXEName, "Settings", "Window", cmbWindow.ListIndex
    SaveSetting App.EXEName, "Settings", "ShowEnergy", chkShowEnergy.Value
    SaveSetting App.EXEName, "Settings", "HoldPeaks", chkHoldPeaks.Value
    SaveSetting App.EXEName, "Settings", "DTMF", chkDTMF.Value
    SaveSetting App.EXEName, "Settings", "ColorizedScale", chkColorScale.Value
    SaveSetting App.EXEName, "Settings", "Zoom2Scale", chkZoom.Value
    SaveSetting App.EXEName, "Settings", "ShowGrid", chkShowGrid.Value
    
    SaveSetting App.EXEName, "Settings", "Gain", hsPA.Value
    
    SaveSetting App.EXEName, "Settings", "MinFreq", MyPref.Min
    SaveSetting App.EXEName, "Settings", "MaxFreq", MyPref.Max
    
    SaveSetting App.EXEName, "Settings", "Quality", cmbQuality.ListIndex
    SaveSetting App.EXEName, "Settings", "FFTSize", cmbFFTSize.ListIndex

    If IsRunning Then cmdSwitch_Click

End Sub

Private Sub Form_Resize()

    If WindowState = vbMinimized Then Exit Sub

    If Width < 5000 Then Width = 5000
    If Height < 5000 Then Height = 5000
    
    With picFFT
        .Left = 480
        .Width = Width - (280 + .Left)
        .Top = 135 + picRealScale.Height + 15
        .Height = Height - 3390
    End With
    
    cmdSwitch.Move 0, Height - 915
    cmbQuality.Move cmdSwitch.Left + cmdSwitch.Width + 480, cmdSwitch.Top + (cmdSwitch.Height - cmbQuality.Height) \ 2
    chkUseRightChannel.Move cmbQuality.Left + cmbQuality.Width + 60, cmbQuality.Top + (cmbQuality.Height - chkUseRightChannel.Height) \ 2
    
    lblSpectrumStyle.Top = picFFT.Top + picFFT.Height + 515
    lblOptions.Top = lblSpectrumStyle.Top
    lblColors.Top = lblSpectrumStyle.Top
    
    frameStyle.Top = lblSpectrumStyle.Top + 400
    frameOptions.Top = frameStyle.Top
    frameColors.Top = frameStyle.Top
    
    tmrDoUpdate.Enabled = True
    
End Sub

Private Sub DrawSplitters()

    Dim r As RECT
    
    Me.Cls
    
    ' Draw Main Pane
    With r
        .Left = 1
        .Right = Width / Screen.TwipsPerPixelX - 10
        .Top = 2
        .Bottom = Height / Screen.TwipsPerPixelY - 29
    End With
    DrawEdge Me.hDc, r, BDR_SUNKENOUTER, BF_TOP Or BF_LEFT Or BF_RIGHT
    
    ' Draw Real Scale Pane
'    With r
'        .Left = picRealScale.Left / Screen.TwipsPerPixelX - 1
'        .Right = (picRealScale.Left + picRealScale.Width) / Screen.TwipsPerPixelX + 1
'        .Top = picRealScale.Top / Screen.TwipsPerPixelX - 2
'        .Bottom = (picRealScale.Top + picRealScale.Height) / Screen.TwipsPerPixelY + 1
'    End With
'    DrawEdge Me.hDc, r, BDR_RAISEDINNER, BF_RECT
    
    ' Draw FFT Display Pane
    With r
        .Left = 2
        .Right = Width / Screen.TwipsPerPixelX - 11
        .Top = 3
        .Bottom = (picFFT.Top + picFFT.Height) / Screen.TwipsPerPixelY + 3
    End With
    DrawEdge Me.hDc, r, BDR_RAISEDINNER, BF_RECT
    
    ' Draw Scale Pane
    With r
        .Left = 2
        .Right = Width / Screen.TwipsPerPixelX - 11
        .Top = (picFFT.Top + picFFT.Height) / Screen.TwipsPerPixelY + 3
        .Bottom = (picScale.Top + picScale.Height) / Screen.TwipsPerPixelY + 12
    End With
    DrawEdge Me.hDc, r, BDR_RAISEDINNER, BF_TOP Or BF_LEFT Or BF_RIGHT
    
    ' Draw Controls Pane 1
    With r
        .Left = 1
        .Right = .Left + 200
        .Top = (picScale.Top + picScale.Height) / Screen.TwipsPerPixelY + 11
        .Bottom = Height / Screen.TwipsPerPixelY - 29
    End With
    DrawEdge Me.hDc, r, BDR_SUNKENOUTER, BF_RECT
    
    ' Draw Controls Pane 2
    With r
        .Left = .Right + 5
        .Right = .Left + 215
    End With
    DrawEdge Me.hDc, r, BDR_SUNKENOUTER, BF_RECT
    
    ' Draw Controls Pane 3
    With r
        .Left = .Right + 5
        .Right = Width / Screen.TwipsPerPixelX - 10
    End With
    DrawEdge Me.hDc, r, BDR_SUNKENOUTER, BF_RECT

    ' Draw Spectrum Style Label's border
    With r
        .Left = 2
        .Right = .Left + 198
        .Top = lblSpectrumStyle.Top / Screen.TwipsPerPixelX - 3
        .Bottom = .Top + lblSpectrumStyle.Height / Screen.TwipsPerPixelY + 7
    End With
    DrawEdge Me.hDc, r, BDR_RAISEDINNER, BF_RECT
    
    ' Draw Options Label's border
    With r
        .Left = .Right + 7
        .Right = .Left + 213
    End With
    DrawEdge Me.hDc, r, BDR_RAISEDINNER, BF_RECT
    
    ' Draw Colors Style Label's border
    With r
        .Left = .Right + 7
        .Right = Width / Screen.TwipsPerPixelX - 11
    End With
    DrawEdge Me.hDc, r, BDR_RAISEDINNER, BF_RECT
    
    ' Draw Power Splitter
    With r
        .Left = 5
        .Right = .Left + 192
        .Top = cmdSwitch.Top / Screen.TwipsPerPixelY - 1
        .Bottom = .Top + 2
    End With
    DrawEdge Me.hDc, r, BDR_SUNKENOUTER, BF_RECT
    
End Sub

Private Sub UpdateScale(Optional SkipGrid As Boolean)

    Dim f As Long
    Dim k As Long
    Dim i As Integer
    Dim lx As Single
    Dim db As Integer
    Dim PrintText As Boolean
    Dim lf As Single
    Dim hf As Single
    
    If MyPref.Max = 0 Then Exit Sub
    
    If MyPref.LogScale And MyPref.ZoomToScale Then SkipGrid = False
    
    If Not SkipGrid Then
        For i = 1 To lnVDiv.Count - 1
            Unload lnVDiv(i)
        Next i
    
        With picAmp
            .Move 45, picFFT.Top, 420, picFFT.Height
            .ScaleHeight = picFFT.ScaleHeight
            .Cls
        End With
    End If
    
    With picRealScale
        .Height = 195
        .Left = picFFT.Left
        .Top = 135
        .Width = picFFT.Width
        If MyPref.ZoomToScale Then
            .ScaleWidth = FFTLib.Freq2Index((MyPref.Max - MyPref.Min) / 2)
            .ScaleLeft = FFTLib.Freq2Index(MyPref.Min / 2)
        Else
            .ScaleWidth = MyPref.FFTSize / 2
            .ScaleLeft = 0
        End If
        If MyPref.LogScale Then
            .ScaleLeft = FFTLib.Log10(.ScaleLeft)
            .ScaleWidth = FFTLib.Log10(.ScaleWidth)
        End If
        
        .Cls
        
        f = 0
        lx = 0
        PrintText = True
        For k = FFTLib.Freq2Index(MyPref.Min / 2) To FFTLib.Freq2Index(MyPref.Max / 2)
            f = FFTLib.Index2Freq(k)
            .CurrentY = 15
            If MyPref.LogScale Then
                .CurrentX = FFTLib.Log10(k)
            Else
                .CurrentX = k
            End If
            If PrintText Then
                lx = .CurrentX
                If f >= 1000 Then
                    lblDummy.Caption = Format(f, "0,000")
                Else
                    lblDummy.Caption = Format(f, "0")
                End If
                picRealScale.Print lblDummy.Caption
            End If
            If MyPref.LogScale Then
                PrintText = (.CurrentX - lx) >= (lblDummy.Width + 480) / (.Width / .ScaleWidth)
            Else
                PrintText = (.CurrentX - lx) >= (lblDummy.Width + 240) / (.Width / .ScaleWidth)
            End If
        Next k
    End With
    
    With picScale
        .Height = 195
        .Left = picFFT.Left
        .Top = picFFT.Top + picFFT.Height + 90
        .Width = picFFT.Width
        .ScaleWidth = IIf(MyPref.LogScale, FFTLib.Log10(MyPref.FFTSize / 2), MyPref.FFTSize / 2)
        .Cls
        
        i = 0
        lx = 0
        PrintText = True
        For k = 0 To MyPref.FFTSize / 2 Step 10
            If MyPref.LogScale Then
                .CurrentX = FFTLib.Log10(k)
            Else
                .CurrentX = k
            End If
            If PrintText Then
                f = FFTLib.Index2Freq(k)
                .CurrentY = 15
                lx = .CurrentX
                If f >= 1000 Then
                    lblDummy.Caption = Format(f, "0,000")
                Else
                    lblDummy.Caption = Format(f, "0")
                End If
                picScale.Print lblDummy.Caption
            End If
            If MyPref.LogScale Then
                PrintText = (.CurrentX - lx) >= (lblDummy.Width + 480) / (.Width / .ScaleWidth)
            Else
                PrintText = (.CurrentX - lx) >= (lblDummy.Width + 240) / (.Width / .ScaleWidth)
            End If
            If chkShowGrid.Value Then
                If Not SkipGrid Then
                    If (k / 10 = k \ 10) Then
                        If i > 0 Then Load lnVDiv(i)
                        lnVDiv(i).Y1 = picFFT.ScaleTop
                        lnVDiv(i).Y2 = picFFT.ScaleHeight
                        lnVDiv(i).X1 = IIf(MyPref.LogScale, FFTLib.Log10(k), k)
                        lnVDiv(i).X2 = lnVDiv(i).X1
                        lnVDiv(i).Visible = True
                        lnVDiv(i).ZOrder 0
                        i = i + 1
                    End If
                End If
            End If
        Next k
    End With
    
    If Not SkipGrid Then
        picAmp.ScaleTop = picFFT.ScaleTop
        picAmp.ScaleHeight = picFFT.ScaleHeight
        For i = 0 To 9
            Load lnVDiv(lnVDiv.Count)
            With lnVDiv(lnVDiv.Count - 1)
                .Y1 = (i / 10) * picFFT.ScaleHeight + picFFT.ScaleTop
                .Y2 = .Y1
                .X1 = picFFT.ScaleLeft
                .X2 = picFFT.ScaleWidth + picFFT.ScaleLeft
                .Visible = (chkShowGrid.Value = vbChecked)
                .ZOrder 0
                
                If Int(i / 2) = i / 2 Then
                    lblDummy.Caption = db & "dB"
                    picAmp.CurrentY = .Y1
                    picAmp.CurrentX = picAmp.Width - (lblDummy.Width + 30)
                    picAmp.Print lblDummy.Caption
                End If
                db = -(i / 3 * 2) * 10
            End With
        Next i
    End If
    
    lf = FFTLib.Freq2Index(MyPref.Min / 2)
    hf = FFTLib.Freq2Index(MyPref.Max / 2)
    If MyPref.LogScale Then
         lf = FFTLib.Log10(lf)
         hf = FFTLib.Log10(hf)
    End If
    
    
    With picScale
        imgLowF.Move .Left + (lf * .Width / .ScaleWidth) - 60, .Top + .Height + 15
        imgHiF.Move .Left + (hf * .Width / .ScaleWidth) - 60, .Top + .Height + 15
        imgSpan.Move imgLowF.Left + (imgHiF.Left - imgLowF.Left) / 2, .Top + .Height + 15
        
        picScale.Line (lf, 0)-(hf, picScale.Height), vbBlack, BF
    End With
    
    chkZoom.Move picScale.Left - 240, picScale.Top

End Sub

Private Sub hsPA_Change()

    SetPreferences

End Sub

Private Sub hsPA_Scroll()

    SetPreferences

End Sub

Private Sub imgHiF_DblClick()

    MyPref.Max = GetFreq
    SetPreferences
    UpdateScale

End Sub

Private Sub imgHiF_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

    IsDragging = True

End Sub

Private Sub imgHiF_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

    If IsDragging Then
        With MyPref
            If .Max + X > .MaxFreq Then
                .Max = .MaxFreq
            ElseIf .Max + X < .Min + 1000 Then
                .Max = .Min + 1000
            Else
                .Max = .Max + X
            End If
            FFTLib.Preferences = MyPref
            UpdateScale True
        End With
    End If

End Sub

Private Sub imgHiF_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)

    IsDragging = False

End Sub

Private Sub imgLowF_DblClick()

    MyPref.Min = 0
    SetPreferences
    UpdateScale

End Sub

Private Sub imgLowF_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

    IsDragging = True

End Sub

Private Sub imgLowF_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

    If IsDragging Then
        With MyPref
            If .Min + X < 0 Then
                .Min = 0
            ElseIf .Min + X > .Max - 1000 Then
                .Min = .Max - 1000
            Else
                .Min = .Min + X
            End If
            FFTLib.Preferences = MyPref
            UpdateScale True
        End With
    End If

End Sub

Private Sub imgLowF_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)

    IsDragging = False

End Sub

Private Sub imgSpan_DblClick()

    MyPref.Min = 0
    MyPref.Max = MyPref.MaxFreq
    FFTLib.Preferences = MyPref
    UpdateScale

End Sub

Private Sub imgSpan_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

    IsDragging = True

End Sub

Private Sub imgSpan_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

    If IsDragging Then
        With MyPref
            If (MyPref.Min + X) >= 0 And (MyPref.Max + X) <= MyPref.MaxFreq Then
                MyPref.Min = MyPref.Min + X
                MyPref.Max = MyPref.Max + X
            End If
            FFTLib.Preferences = MyPref
            UpdateScale True
        End With
    End If

End Sub

Private Sub imgSpan_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)

    IsDragging = False

End Sub

Private Sub lblInfo_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

    Dim kx As Single
    Dim ky As Single
    
    kx = picFFT.Width / picFFT.ScaleWidth
    ky = picFFT.Height / picFFT.ScaleHeight

    picFFT_MouseMove Button, Shift, X / kx + lblInfo.Left, Y / ky + lblInfo.Top

End Sub

Private Sub msgSC_NewMessage(ByVal hwnd As Long, uMsg As Long, wParam As Long, lParam As Long, Cancel As Boolean)

    If hwnd = Me.hwnd Then
        If uMsg = WM_PAINT Then
            If Not IsDragging Then
                DrawSplitters
                Cancel = False
            End If
        End If
    End If

End Sub

Private Sub opMode_Click(Index As Integer)

    FFTMode = Index
    FixFocus

End Sub

Private Sub picColor_Click(Index As Integer)

    On Error GoTo ExitSub

    With cDlgColor
        .CancelError = True
        .Flags = cdlCCRGBInit
        .Color = picColor(Index).BackColor
        .DialogTitle = IIf(Index = 0, "Graphic", "Background") + " Color"
        .ShowColor
        picColor(Index).BackColor = .Color
    End With
    
    UpdateColors
    
ExitSub:

End Sub

Private Sub picFFT_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

    Dim f As Single
    Dim a As Integer
    Dim h As String
    
    If Shift And vbShiftMask Then
        h = "Hz"
        
        If MyPref.LogScale Then
            f = FFTLib.Index2Freq(CLng(10 ^ X))
        Else
            f = FFTLib.Index2Freq(CLng(X))
        End If
        If f >= 1000 Then
            h = "K" + h
            f = f / 1000
        End If
        
        a = -(Int(Y / picFFT.ScaleHeight * 60) + 60)
    
        With lblInfo
            .Caption = " " + Format(f, "0.00") + h + " " & a & "dB "
            
            X = X + picFFT.ScaleWidth / 150
            If X + .Width > picFFT.ScaleWidth Then X = picFFT.ScaleWidth - .Width
            Y = Y + .Height - 5
            If Y > Abs(picFFT.ScaleHeight) Then Y = Abs(picFFT.ScaleHeight)
            
            .Move X, Y
            .Visible = True
        End With
    Else
        lblInfo.Visible = False
    End If
    
End Sub

Private Sub tmrDoUpdate_Timer()

    Dim sh As Long
    
    tmrDoUpdate.Enabled = False

    SetPreferences
    UpdateScale
    
    With picFFT
        sh = Abs(.ScaleHeight)
        shpLow.Move .ScaleLeft, sh * 0.5, .ScaleWidth, sh * 0.5 + 15
        shpMed.Move .ScaleLeft, shpLow.Top + sh * 0.3, .ScaleWidth, sh * 0.3 + 15
        shpHi.Move .ScaleLeft, sh, .ScaleWidth, sh - shpMed.Top + 15
    End With

End Sub

Private Sub txtDTMF_DblClick()

    txtDTMF.Text = ""

End Sub
