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

📄 51

📁 51单片机大量源码
💻
📖 第 1 页 / 共 5 页
字号:
                                              m_InterSegmentGap, DigitWidth, DigitHeight
            End If
         Next i

      Case [Rectangular]
         For i = 1 To m_NumDigits
            CurrentDigit = Mid(s, i, 1)
            If (CurrentDigit <> Mid(PreviousMainValue, i, 1)) Or ForceDisplay Then
               DisplayRectangularSegmentDigit CurrentDigit, LCDSegment(), _
                                              DigitXPos(i - 1), m_YOffset, _
                                              m_SegmentHeight, m_SegmentWidth, _
                                              m_InterSegmentGap, DigitWidth, DigitHeight
            End If
         Next i

   End Select

   UserControl.Refresh

'  save the displayed value so we know which LCD digits
'  to update the next time we need to display a value.
   PreviousMainValue = s

End Sub

Private Sub DisplayExponentValue(strValue As String, ByVal ForceDisplay As Boolean)

'*************************************************************************
'* displays exponent portion of value stored in .Value property.         *
'*************************************************************************

   Dim s            As String    ' right-justified version of exponent.
   Dim i            As Long      ' loop variable.
   Dim CurrentDigit As String    ' the current digit we're displaying.

   s = Right(Space(m_NumDigitsExp) & strValue, m_NumDigitsExp)

'  display the exponent.  Only draw a digit if the particular digit being
'  drawn is different from digit the previous time value was displayed.
   Select Case m_SegmentStyleExp

      Case [Hexagonal]
         For i = 1 To m_NumDigitsExp
            CurrentDigit = Mid(s, i, 1)
            If (CurrentDigit <> Mid(PreviousExponentValue, i, 1)) Or ForceDisplay Then
               DisplayHexagonalSegmentDigit CurrentDigit, LCDSegmentExp(), _
                                            DigitXPosExp(i - 1), m_YOffsetExp, _
                                            m_SegmentHeightExp, m_SegmentWidthExp, _
                                            m_InterSegmentGapExp, DigitWidthExp, DigitHeightExp
            End If
         Next i

      Case [Trapezoidal]
         For i = 1 To m_NumDigitsExp
            CurrentDigit = Mid(s, i, 1)
            If (CurrentDigit <> Mid(PreviousExponentValue, i, 1)) Or ForceDisplay Then
               DisplayTrapezoidalSegmentDigit CurrentDigit, LCDSegmentExp(), _
                                              DigitXPosExp(i - 1), m_YOffsetExp, _
                                              m_SegmentHeightExp, m_SegmentWidthExp, _
                                              m_InterSegmentGapExp, DigitWidthExp, DigitHeightExp
            End If
         Next i

      Case [Rectangular]
         For i = 1 To m_NumDigitsExp
            CurrentDigit = Mid(s, i, 1)
            If (CurrentDigit <> Mid(PreviousExponentValue, i, 1)) Or ForceDisplay Then
               DisplayRectangularSegmentDigit CurrentDigit, LCDSegmentExp(), _
                                              DigitXPosExp(i - 1), m_YOffsetExp, _
                                              m_SegmentHeightExp, m_SegmentWidthExp, _
                                              m_InterSegmentGapExp, DigitWidthExp, DigitHeightExp
            End If
         Next i

   End Select

   UserControl.Refresh

'  save the displayed value so we know which LCD digits
'  to update the next time we need to display a value.
   PreviousExponentValue = s

End Sub

Private Sub DetermineThousandsSeparatorPlacement(ByVal sVal As String)

'*************************************************************************
'* determines which digits in the main value get a thousands separator   *
'* afterwards.  ThousandsFlag() elements that correspond to LCD digits   *
'* that need to be followed by a thousands separator are set to True.    *
'* Thanks to Redbird77 for optimizing this routine.                      *
'*************************************************************************

   Dim i    As Long      ' loop variable.
   Dim p1   As Long      ' position of first non-zero/minus sign digit.
   Dim p2   As Long      ' position of decimal separator.
   Dim sTmp As String    ' padded value.

'  reset the ThousandsFlag boolean array to all False.  (Remember that False
'  is an integer (2-byte) value equal to zero, so this is a lightning-quick
'  way to set a dynamic boolean array, as opposed to looping.)
   FillMemory ThousandsFlag(0), 2 * m_NumDigits, False

'  Add decimal point to end if whole number.
   If InStr(sVal, ".") = 0 Then
      sVal = sVal & "."
   End If

'  left-pad value.
   sTmp = Right$(String$(m_NumDigits, "0") & sVal, m_NumDigits)

'  get position of decimal point.
   p2 = InStr(sTmp, ".")

'  get position of first non-zero and non-minus sign digit.
   p1 = m_NumDigits - Len(sVal) + 1
   If Mid$(sTmp, p1, 1) = "-" Then
      p1 = p1 + 1
   End If

'  flag appropriate digits that receive a decimal separator after them.
   For i = p2 - (m_ThousandsGrouping + 1) To p1 Step -m_ThousandsGrouping
      ThousandsFlag(i) = True
   Next i

End Sub

Private Sub DisplayThousandsSeparators()

'*************************************************************************
'* display needed thousands separators and erase any others.             *
'*************************************************************************

   Dim i    As Long   ' loop index.
   Dim r    As Long   ' bitblt function call return.
   Dim xPos As Long   ' x coordinate of thousands separator.
   Dim yPos As Long   ' y coordinate of thousands separator.

'  determine the Y coordinate of the thousands separator. If digit
'  segment style is rectangular, 1 is subtracted from Y coordinate.
   Select Case m_ThousandsSeparator
      Case [Period]
         yPos = m_YOffset + DigitHeight - m_SegmentWidth + 1 + (m_SegmentStyle = [Rectangular])
      Case [Comma]
         yPos = m_YOffset + DigitHeight - m_SegmentWidth - 1
   End Select

   For i = 0 To m_NumDigits - 1

'     calculate the starting X coordinates for the thousands separator.
      Select Case m_ThousandsSeparator
         Case [Period]
            xPos = DigitXPos(i) + DigitWidth + (m_InterDigitGap \ 2) - (m_SegmentWidth \ 2)
         Case [Comma]
            xPos = DigitXPos(i) + (DigitWidth) - (m_SegmentWidth)
      End Select

      If ThousandsFlag(i) Then
'        display a thousands separator.
         DisplaySegment LCDSegment(THOUSANDS_SEPARATOR_SEGMENT), xPos, yPos, SEGMENT_LIT
      Else
'        make sure a possible previous thousands separator is erased.
         Select Case m_ThousandsSeparator
            Case [Period]
               r = BitBlt(hdc, xPos, yPos, m_SegmentWidth, m_SegmentWidth, _
                          VirtualBackgroundDC, xPos, yPos, vbSrcCopy)
            Case [Comma]
               EraseIrregularRegion THOUSANDS_SEPARATOR_SEGMENT, xPos, yPos
         End Select
      End If

   Next i

End Sub

Private Sub ProcessColon(ByRef s As String)

'*************************************************************************
'* erases old colon, if one was displayed.  Displays new colon if needed *
'* and removes colon from passed value string.                           *
'* NOTE:  To use this control as a clock display, set the number of main *
'* value digits to 4, and the number of exponent digits to 2.  Pass the  *
'* time (either 12- or 24-hour mode) to the .Value property like this:   *
'* HH:MMe+SS, where HH:MM is the hours:minutes, and SS is the seconds.   *
'* The 'e+' tricks control into displaying the seconds in the exponent   *
'* part of the display.  If you wish to just display hours and minutes,  *
'* set the .ShowExponent property to False and just send HH:MM.          *
'*************************************************************************

   EraseOldColon
   DrawNewColon s

End Sub

Private Sub EraseOldColon()

'*************************************************************************
'* erases previously drawn colon by drawing background over it.          *
'*************************************************************************

   Dim r As Long    ' bitblt function call return.

'  only bother if there was actually a displayed colon.
   If ColonPos.TopPoint.x > -1 Then
      r = BitBlt(hdc, ColonPos.TopPoint.x, ColonPos.TopPoint.Y, m_SegmentWidth, m_SegmentWidth, _
                 VirtualBackgroundDC, ColonPos.TopPoint.x, ColonPos.TopPoint.Y, vbSrcCopy)
      r = BitBlt(hdc, ColonPos.BottomPoint.x, ColonPos.BottomPoint.Y, m_SegmentWidth, m_SegmentWidth, _
                 VirtualBackgroundDC, ColonPos.BottomPoint.x, ColonPos.BottomPoint.Y, vbSrcCopy)
   End If

End Sub

Private Sub DrawNewColon(ByRef s As String)

'*************************************************************************
'* draws new colon in correct location.                                  *
'*************************************************************************

   Dim i As Long    ' position of colon within value to be displayed.

'  check for existence of colon in value to be displayed.
   i = InStr(s, ":")

   If i > 0 Then

'     if colon needed, calculate the starting X and Y coordinates of each 'dot'.
      ColonPos.TopPoint.x = DigitXPos(i - 1 + (m_NumDigits - Len(s))) + DigitWidth + (m_InterDigitGap \ 2) - (m_SegmentWidth \ 2) + 1
      ColonPos.BottomPoint.x = ColonPos.TopPoint.x
      ColonPos.TopPoint.Y = m_YOffset + m_SegmentHeight \ 2 + m_SegmentWidth \ 2
      ColonPos.BottomPoint.Y = ColonPos.TopPoint.Y + m_SegmentHeight

'     display the colon.
      DisplaySegment LCDSegment(DECIMAL_SEPARATOR_SEGMENT), ColonPos.TopPoint.x, ColonPos.TopPoint.Y, SEGMENT_LIT
      DisplaySegment LCDSegment(DECIMAL_SEPARATOR_SEGMENT), ColonPos.BottomPoint.x, ColonPos.BottomPoint.Y, SEGMENT_LIT

'     remove the colon from the numeric string to be displayed.
      s = Left(s, i - 1) & Right(s, Len(s) - i)

   Else

'     flag it so control knows no colon has been drawn.
      ColonPos.TopPoint.x = -1

   End If

End Sub

Private Sub ProcessDecimalSeparator(ByRef s As String)

'*************************************************************************
'* erases old decimal point, if one was displayed.  Displays new decimal *
'* point if needed and removes decimal point from passed value string.   *
'*************************************************************************

   EraseOldDecimalSeparator
   DisplayNewDecimalSeparator s

End Sub

Private Sub EraseOldDecimalSeparator()

'*************************************************************************
'* erases previously drawn decimal point by drawing background over it.  *
'*************************************************************************

   Dim r As Long    ' bitblt function call return.

'  only bother if there was actually a displayed decimal separator.
   If DecimalSeparatorPos.x > -1 Then
      Select Case m_DecimalSeparator
         Case [Period]
            r = BitBlt(hdc, DecimalSeparatorPos.x, DecimalSeparatorPos.Y, m_SegmentWidth, m_SegmentWidth, _
                       VirtualBackgroundDC, DecimalSeparatorPos.x, DecimalSeparatorPos.Y, vbSrcCopy)
         Case [Comma]
            EraseIrregularRegion DECIMAL_SEPARATOR_SEGMENT, DecimalSeparatorPos.x, DecimalSeparatorPos.Y
      End Select
   End If

End Sub

⌨️ 快捷键说明

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