📄 main.frm
字号:
Private dMaxVol As Double 'max vol data range
Private dHeightVol As Double 'height of vol panel
Private iMostRecentBarIndex As Long 'current working bar
Private fSwitch As Boolean 'animation toggle switch
Private iScrolledAmount As Long 'running count of amount chart is scrolled
Private iCalcdAvailBars2Plot As Long 'calculated number of bars to plot
Private Sub DrawingTools_DrawingDone()
'cleanup after drawing is done
stbBottom.Panels(3).Picture = Nothing
txtDrawInstruct.Text = sEmpty
txtDrawInstruct.Visible = False
End Sub
Private Sub DrawingTools_DrawingInstructions(sText As String)
txtDrawInstruct.Text = sText$
End Sub
Private Sub DrawingTools_DrawingStarted()
stbBottom.Panels(3).Picture = LoadResPicture(101, vbResIcon)
'statusBar fonts not individual to each panel so we put a textbox on it
'to change to bold for the drawing instructions
txtDrawInstruct.Top = stbBottom.Top + 30
txtDrawInstruct.Left = stbBottom.Panels(3).Left + stbBottom.Panels(3).Picture.Width * 0.75
txtDrawInstruct.Height = stbBottom.Height - 30
txtDrawInstruct.Width = stbBottom.Panels(3).Width - stbBottom.Panels(3).Picture.Width * 0.75
txtDrawInstruct.ZOrder 0
txtDrawInstruct.Visible = True
End Sub
Private Sub DrawingTools_DrawLoopIsRunning()
'animation routine for visual notification to show that the draw loop is running
fSwitch = Not fSwitch
If fSwitch Then
stbBottom.Panels(3).Picture = LoadResPicture(102, vbResIcon)
Else
stbBottom.Panels(3).Picture = LoadResPicture(101, vbResIcon)
End If
End Sub
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
If GetAsyncKeyState(VK_CONTROL) <> 0 Then
If GetAsyncKeyState(VK_END) <> 0 Then 'ctrl-end reset scroll
If iScrolledAmount = 0 Then Exit Sub
iScrolledAmount = 0
Call ChartBoxDraw
ElseIf GetAsyncKeyState(VK_HOME) <> 0 Then 'ctrl-home Max scroll
If iScrolledAmount >= iUBaData - iCalcdAvailBars2Plot Then Exit Sub
iScrolledAmount = iUBaData - iCalcdAvailBars2Plot
Call tbLeft_MouseUp(1, 1, tbLeft.Buttons("ScrollData").Left + 10, tbLeft.Buttons("ScrollData").Top + 10)
Call ChartBoxDraw
ElseIf GetAsyncKeyState(VK_LEFT) <> 0 Then 'ctrl-left arrow scroll left 1
If iScrolledAmount >= iUBaData - iCalcdAvailBars2Plot Then Exit Sub
Call tbLeft_MouseUp(1, 0, tbLeft.Buttons("ScrollData").Left + 10, tbLeft.Buttons("ScrollData").Top + 10)
Call ChartBoxDraw
ElseIf GetAsyncKeyState(VK_RIGHT) <> 0 Then 'ctrl-right arrow scroll right 1
If iScrolledAmount = 0 Then Exit Sub
Call tbLeft_MouseUp(2, 0, tbLeft.Buttons("ScrollData").Left + 10, tbLeft.Buttons("ScrollData").Top + 10)
Call ChartBoxDraw
ElseIf GetAsyncKeyState(VK_PRIOR) <> 0 Then 'ctrl-page up scroll left scroll amount
If iScrolledAmount >= iUBaData - iCalcdAvailBars2Plot Then Exit Sub
Call tbLeft_MouseUp(1, 1, tbLeft.Buttons("ScrollData").Left + 10, tbLeft.Buttons("ScrollData").Top + 10)
Call ChartBoxDraw
ElseIf GetAsyncKeyState(VK_NEXT) <> 0 Then 'ctrl-page down scroll right scroll amount
If iScrolledAmount = 0 Then Exit Sub
Call tbLeft_MouseUp(2, 1, tbLeft.Buttons("ScrollData").Left + 10, tbLeft.Buttons("ScrollData").Top + 10)
Call ChartBoxDraw
End If
End If
End Sub
Private Sub Form_Load()
frmSplash.Show 0, Me
DoEvents
sINIsetFile$ = App.Path & "\Chart.INI"
If Not ExistFile(sINIsetFile$) Then 'no INI file...create one
Call MakeIniFile
End If
Call GetIniSettings
Set MovAvgs = New MovAvg
Call GetIndicatorSettings
Set DrawingTools = New CDrawingTools
Set DrawingTools.picBx = ChartBox
Set DrawingTools.picBxV = ChartBoxV
sCaption = Me.Caption & " - "
lblMousePrice.Top = ChartBoxV.ScaleTop + 1
lblMousePrice.Left = ChartBoxV.ScaleWidth
Call SetColors
Call SetupToolbar
Show
DoEvents
If LoadData Then 'try to load data, set flag if success, draw chart
fGotData = True
Call SetMargins
Call ChartBoxDraw
End If
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If IsDrawing Then 'still in drawing loop so set cancel flag, cancel exit to kill loop
fCancelDrawingTool = True
Cancel = True
Exit Sub
End If
If UnloadMode = 0 Or UnloadMode = 1 Then
Dim iResult As Long
iResult = MsgBox("Do you really want to exit program?", vbQuestion + vbYesNo, "Exiting Program...")
If iResult = vbNo Then Cancel = True: Exit Sub
End If
Call SaveIniSettings
Call EndWinsock
Set oCurrentIndicator = Nothing
Set DrawingTools = Nothing
Set MovAvgs = Nothing
Set frmMain = Nothing
End Sub
Public Sub SetColors()
ChartBox.BackColor = iBackColor
ChartBox.ForeColor = iForeColor
ChartBoxV.BackColor = iBackColor
ChartBoxV.ForeColor = iForeColor
ChartBox.Font = sFontName
ChartBox.FontSize = iFontSize
ChartBox.FontBold = iFontBold
ChartBox.FontItalic = iFontItalic
ChartBoxV.Font = sFontName
ChartBoxV.FontSize = iFontSize
ChartBoxV.FontBold = iFontBold
ChartBoxV.FontItalic = iFontItalic
lblMousePrice.BackColor = iBackColor
lblMousePrice.ForeColor = iMouseLabelColor
End Sub
Public Sub SetMargins()
iTextHeight = ChartBox.TextHeight("X")
xLeftMargin = ChartBox.ScaleLeft
xRightMargin = ChartBox.ScaleWidth
rRightSideOffset = ChartBox.ScaleWidth - iBlankSpace * 10
If iBarDataPeriodMins < 0 Then 'Daily data... need less space for text
iBottomPlotMargin = ChartBox.ScaleHeight - (iTextHeight)
Else
iBottomPlotMargin = ChartBox.ScaleHeight - (iTextHeight * 2)
End If
'validate the panel dividers location... make sure we can move them with the mouse
'especially after setting defaults... a divider may not even be on the screen
If rSplit1 < iBottomPlotMargin / 2 Then
rSplit1 = iBottomPlotMargin / 2
WriteIni sINIsetFile, "Settings", "WindowSplit1", CStr(rSplit1)
End If
If rSplit2 > iBottomPlotMargin - 50 Then
rSplit2 = iBottomPlotMargin - 50
WriteIni sINIsetFile, "Settings", "WindowSplit2", CStr(rSplit2)
End If
If rSplit1 > rSplit2 Then
rSplit1 = rSplit2 - 10
WriteIni sINIsetFile, "Settings", "WindowSplit1", CStr(rSplit1)
End If
If rSplit2 < rSplit1 Then
rSplit2 = rSplit1 + 10
WriteIni sINIsetFile, "Settings", "WindowSplit2", CStr(rSplit2)
End If
Divider(0).X1 = ChartBox.ScaleLeft - 5
Divider(0).Y1 = rSplit1
Divider(0).X2 = ChartBox.ScaleLeft - 3
Divider(0).Y2 = rSplit1
Divider(1).X1 = ChartBox.ScaleLeft - 5
Divider(1).Y1 = rSplit2
Divider(1).X2 = ChartBox.ScaleLeft - 3
Divider(1).Y2 = rSplit2
End Sub
Public Sub Form_Resize()
ChartBoxV.Width = Me.ScaleWidth - (ChartBoxV.Left * 2) + tbLeft.Width
ChartBoxV.Height = Me.ScaleHeight - (ChartBoxV.Top + stbBottom.Height) ' + 120)
ChartBox.Width = ChartBoxV.Width
ChartBox.Height = ChartBoxV.Height
lblMousePrice.Left = ChartBoxV.ScaleWidth - 95
Call SetMargins
iCalcdAvailBars2Plot = (Int(rRightSideOffset / iBarSpacing) + 1)
If fGotData Then Call ChartBoxDraw
ChartBoxV.Visible = True
End Sub
Private Function SnapToBar(x As Integer) As Integer
Dim iXdiff As Integer, iMod As Integer
Dim iUpperBar As Integer, iLowerBar As Integer
'snap crosshairs to price bar plots
iXdiff = rRightSideOffset - x
iMod = iXdiff Mod iBarSpacing
iUpperBar = x + iMod
iLowerBar = iUpperBar - iBarSpacing
'split the difference.. send to closest bar
If x - iLowerBar <= iUpperBar - x Then
SnapToBar = iLowerBar
ElseIf x - iLowerBar > iUpperBar - x Then
SnapToBar = iUpperBar
End If
End Function
Private Sub CrossHairStart(x As Single, y As Single)
Dim i As Long
'setup & show crosshairs
x = SnapToBar(CInt(x))
ChLine1(0).DrawMode = iCrossHairMode
ChLine2(0).DrawMode = iCrossHairMode ' 8 '6,8,15
ChLine1(0).BorderColor = iCrossHairColor
ChLine2(0).BorderColor = iCrossHairColor
ChLine1(0).Y1 = y
ChLine1(0).Y2 = y
ChLine2(0).X1 = x
ChLine2(0).X2 = x
ChLine2(0).Y1 = ChartBox.ScaleHeight
ChLine2(0).Y2 = ChartBox.ScaleTop
ChLine1(0).X1 = ChartBox.ScaleLeft
ChLine1(0).X2 = ChartBox.ScaleWidth
ChLine1(0).Visible = True
ChLine2(0).Visible = True
Call ShowCursor(False)
End Sub
Private Sub CrossHairMoving(x As Single, y As Single)
Dim i As Long
'move the crosshairs
x = SnapToBar(CInt(x))
ChLine1(0).Y1 = y
ChLine1(0).Y2 = y
ChLine2(0).X1 = x
ChLine2(0).X2 = x
End Sub
Private Function CursorInfo(x As Integer, y As Integer) As String
Dim ssOutput As String, iX As Integer, ssInfo As String
'get the info for the bar under the crosshairs
On Error Resume Next
iX = iUBaData - (rRightSideOffset - x) / iBarSpacing
If iMouseDataInfo = 1 Then
ssInfo$ = aData(iX).sDate & vbCrLf & " " _
& aData(iX).sTime & vbCrLf _
& "O: " & aData(iX).dOpen & vbCrLf _
& "H: " & aData(iX).dHigh & vbCrLf _
& "L: " & aData(iX).dLow & vbCrLf _
& "C: " & aData(iX).dClose & vbCrLf _
& "V: " & aData(iX).iVol
End If
'only get info if in the price plot panel
If y < rSplit1 Then
ssOutput$ = CStr(Format(Round(dMaxPrice - ((y - 4) * dRangePrice) / (rSplit1 - 8), 2), "0.00"))
If iMouseDataInfo = 1 Then
ssOutput$ = ssOutput$ & vbCrLf & ssInfo$
End If
Else
CursorInfo = ""
End If
CursorInfo$ = ssOutput$
End Function
Private Sub ChartBoxv_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim iPrevW As Integer
If Button = 1 Then
If DrawingTools.MouseClickEnabled = True Then
DrawingTools.MouseClickNum = DrawingTools.MouseClickNum + 1 'flag and var for drawing tools
Else
If iCrossHair = 1 Then 'show crosshair
Call CrossHairStart(x, y)
If x <= xRightMargin Then
If Timer - iTimeDataInfo < 1.5 Or IsDrawing = True Then
iMouseDataInfo = 1 'show info flag
End If
lblMousePrice.Visible = True
lblMousePrice.Caption = CursorInfo(x \ 1, y \ 1)
End If
Else
If rSplit1 > y - 3 And rSplit1 < y + 3 Then 'between price-vol panels
iWhichSplit = 1
Divider(0).X2 = ChartBoxV.ScaleWidth + 5
Divider(0).Visible = True
ElseIf rSplit2 > y - 3 And rSplit2 < y + 3 Then 'between vol-ind panels
iWhichSplit = 2
Divider(1).X2 = ChartBoxV.ScaleWidth + 5
Divider(1).Visible = True
End If
End If
End If
DrawingTools.Xcurr = x 'get x&y for drawing tools click
DrawingTools.Ycurr = y
iTimeDataInfo = Timer 'set begin time for mouse info label show
ElseIf Button = 2 Then
'If iMouseClickNum <> 0 Then Exit Sub
PopupMenu mnuChartPopUp
End If
End Sub
Private Sub ChartBoxv_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim dy As Double, iOldMode As Integer
dy = ScaleY(2, vbTwips, vbPixels)
'Me.Caption = sCapCurrent$ & " " & _
CStr(Format(dMaxPrice - ((y * dRangePrice) / (rSplit1)), "0.####"))
Select Case Button
Case 1
If iMoveSplit = 0 Then 'not resizing the panels
Call CrossHairMoving(x, y) 'crosshairs tracking mouse
If x <= xRightMargin Then 'show info label if not past price plot
lblMousePrice.Visible = True
lblMousePrice.Caption = CursorInfo(x \ 1, y \ 1)
End If
Else 'resize the plot panels
If iWhichSplit = 1 Then
If y < rSplit2 - 10 And y > iBottomPlotMargin / 2 Then 'set extend bounds
rSplit1 = y
Divider(0).Y1 = rSplit1
Divider(0).Y2 = rSplit1
Else
Call ResetMousePointerAfterSplitMove
Call ChartBoxDraw
End If
ElseIf iWhichSplit = 2 Then
If y > rSplit1 + 10 And y < iBottomPlotMargin - 50 Then 'set extend bounds
rSplit2 = y
Divider(1).Y1 = rSplit2
Divider(1).Y2 = rSplit2
Else
Call ResetMousePointerAfterSplitMove
Call ChartBoxDraw
End If
End If
End If
Case Else
If IsDrawing = False Then
If (y > rSplit1 - 3 And y < rSplit1 + 3) Or _
(y > rSplit2 - 3 And y < rSplit2 + 3) Then 'over the divider
ChartBoxV.MousePointer = 99 'set curser to Horzsplitter
iMoveSplit = 1
iCrossHair = 0
Else 'normal curser status
Call ResetMousePointerAfterSplitMove
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -