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

📄 morphlcd.ctl

📁 PC与单片机双向通讯智能温控程序 #include <AT89X51.H> #include <intrins.h> #define Key_UP P1_0 #def
💻 CTL
📖 第 1 页 / 共 5 页
字号:
VERSION 5.00
Begin VB.UserControl MorphDisplay 
   AutoRedraw      =   -1  'True
   ClientHeight    =   675
   ClientLeft      =   0
   ClientTop       =   0
   ClientWidth     =   2565
   ScaleHeight     =   45
   ScaleMode       =   3  'Pixel
   ScaleWidth      =   171
   ToolboxBitmap   =   "MorphLCD.ctx":0000
End
Attribute VB_Name = "MorphDisplay"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False


Option Explicit

' declares for creating, selecting, coloring and destroying the shaped LCD segment regions.
Private Declare Function CreatePolygonRgn Lib "gdi32.dll" (ByRef lpPoint As POINTAPI, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long
Private Declare Function CreateRectRgn Lib "gdi32" (ByVal x1 As Long, ByVal y1 As Long, ByVal x2 As Long, ByVal y2 As Long) As Long
Private Declare Function CreateSolidBrush Lib "gdi32.dll" (ByVal crColor As Long) As Long
Private Declare Function DeleteObject Lib "gdi32.dll" (ByVal hObject As Long) As Long
Private Declare Function FillRgn Lib "gdi32.dll" (ByVal hdc As Long, ByVal hRgn As Long, ByVal hBrush As Long) As Long
Private Declare Function FrameRgn Lib "gdi32.dll" (ByVal hdc As Long, ByVal hRgn As Long, ByVal hBrush As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function OffsetRgn Lib "gdi32.dll" (ByVal hRgn As Long, ByVal x As Long, ByVal Y As Long) As Long
Private Declare Function SelectClipRgn Lib "gdi32" (ByVal hdc As Long, ByVal hRgn As Long) As Long

' other graphics api declares.
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal nXDest As Long, ByVal nYDest As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function CombineRgn Lib "gdi32.dll" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function CreateDCAsNull Lib "gdi32" Alias "CreateDCA" (ByVal lpDriverName As String, lpDeviceName As Any, lpOutput As Any, lpInitData As Any) As Long
Private Declare Function CreateDIBPatternBrushPt Lib "gdi32" (lpPackedDIB As Any, ByVal iUsage As Long) As Long
Private Declare Function CreateEllipticRgn Lib "gdi32" (ByVal x1 As Long, ByVal y1 As Long, ByVal x2 As Long, ByVal y2 As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function FillRect Lib "user32" (ByVal hdc As Long, lpRect As RECT, ByVal hBrush As Long) As Long
Private Declare Function GetDIBits Lib "gdi32" (ByVal aHDC As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, ByVal nNumScans As Long, lpBits As Any, lpBI As BITMAPINFOHEADER, ByVal wUsage As Long) As Long
Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
Private Declare Function GetObjectAPI Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
Private Declare Function GetObjectType Lib "gdi32" (ByVal hgdiobj As Long) As Long
Private Declare Function OleTranslateColor Lib "olepro32.dll" (ByVal OLE_COLOR As Long, ByVal hPalette As Long, pccolorref As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function SetBrushOrgEx Lib "gdi32" (ByVal hdc As Long, ByVal nXOrg As Long, ByVal nYOrg As Long, lppt As POINTAPI) As Long
Private Declare Function SetRect Lib "user32" (lpRect As RECT, ByVal x1 As Long, ByVal y1 As Long, ByVal x2 As Long, ByVal y2 As Long) As Long
Private Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Long) As Long
Private Declare Function StretchDIBits Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal Y As Long, ByVal dx As Long, ByVal dy As Long, ByVal SrcX As Long, ByVal SrcY As Long, ByVal wSrcWidth As Long, ByVal wSrcHeight As Long, lpBits As Any, lpBitsInfo As Any, ByVal wUsage As Long, ByVal dwRop As Long) As Long
Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef lpDest As Any, ByRef lpSource As Any, ByVal iLen As Long)
Private Declare Sub FillMemory Lib "kernel32.dll" Alias "RtlFillMemory" (Destination As Any, ByVal Length As Long, ByVal Fill As Byte)

'  for separator and colon positioning.
Private Type POINTAPI
   x                            As Long
   Y                            As Long
End Type

'  declares for gradient painting and bitmap tiling.
Private Type BITMAPINFOHEADER
   biSize                       As Long
   biWidth                      As Long
   biHeight                     As Long
   biPlanes                     As Integer
   biBitCount                   As Integer
   biCompression                As Long
   biSizeImage                  As Long
   biXPelsPerMeter              As Long
   biYPelsPerMeter              As Long
   biClrUsed                    As Long
   biClrImportant               As Long
End Type

Private Type BITMAP
   bmType                       As Long
   bmWidth                      As Long
   bmHeight                     As Long
   bmWidthBytes                 As Long
   bmPlanes                     As Integer
   bmBitsPixel                  As Integer
   bmBits                       As Long
End Type

Private Const DIB_RGB_COLORS    As Long = 0                 ' also used in gradient generation.
Private Const OBJ_BITMAP        As Long = 7                 ' used to determine if picture is a bitmap.
Private m_hBrush                As Long                     ' pattern brush for bitmap tiling.

'  used to define various graphics areas.
Private Type RECT
   Left                         As Long
   Top                          As Long
   Right                        As Long
   Bottom                       As Long
End Type

'  gradient generation constants.
Private Const RGN_DIFF          As Long = 4
Private Const PI                As Single = 3.14159265358979
Private Const TO_DEG            As Single = 180 / PI
Private Const TO_RAD            As Single = PI / 180
Private Const INT_ROT           As Long = 1000

'  gradient information for background.
Private BGuBIH                  As BITMAPINFOHEADER
Private BGlBits()               As Long

' enum tied to .Theme property.
Public Enum LCDThemeOptions
   [None] = 0
   [LED Hex Small] = 1
   [LED Hex Medium] = 2
   [LCD Trap Small] = 3
   [LCD Trap Medium] = 4
   [Rectangular Medium] = 5
   [Rectangular Small] = 6
End Enum

' enum tied to .ThousandsSeparator and .DecimalSeparator properties.
Public Enum SeparatorOptions
   [Comma] = 0
   [Period] = 1
End Enum

' enum tied to .SegmentStyle and .SegmentStyleExp properties.
Public Enum SegmentStyleOptions
   [Hexagonal] = 0
   [Trapezoidal] = 1
   [Rectangular] = 2
End Enum

' enum tied to .SegmentFillStyle property.
Public Enum SegmentFillStyleOptions
   [Filament] = 0
   [Solid] = 1
End Enum

'  enum tied to .PictureMode property.
Public Enum LCDPicModeOptions
   [Normal] = 0
   [Stretch] = 1
   [Tiled] = 2
End Enum

' holds all segment region pointers for hexagonal/trapezoidal/rectangular LCD display segment types.
Private LCDSegment(0 To 9)      As Long
Private LCDSegmentExp(0 To 9)   As Long

' pointers to the segment currently being created or displayed.
Private Const VERTICAL_HEXAGONAL_SEGMENT              As Long = 0
Private Const HORIZONTAL_HEXAGONAL_SEGMENT            As Long = 1
Private Const HORIZONTAL_DOWNWARD_TRAPEZOIDAL_SEGMENT As Long = 2
Private Const VERTICAL_LEFTWARD_TRAPEZOIDAL_SEGMENT   As Long = 3
Private Const HORIZONTAL_UPWARD_TRAPEZOIDAL_SEGMENT   As Long = 4
Private Const VERTICAL_RIGHTWARD_TRAPEZOIDAL_SEGMENT  As Long = 5
Private Const VERTICAL_RECTANGULAR_SEGMENT            As Long = 6
Private Const HORIZONTAL_RECTANGULAR_SEGMENT          As Long = 7
Private Const DECIMAL_SEPARATOR_SEGMENT               As Long = 8
Private Const THOUSANDS_SEPARATOR_SEGMENT             As Long = 9

' pointers to which LCD digit type we're currently manipulating.
Private Const MAINVALUE         As Long = 0
Private Const EXPONENT          As Long = 1

' segment lit status constants.
Private Const SEGMENT_LIT       As String = "1"
Private Const SEGMENT_UNLIT     As String = "0"

' used by the DisplayValue routine to determine whether value should
' be fully redisplayed (as when property is changed in design mode).
Private Const FORCE_REDRAW_YES  As Boolean = True
Private Const FORCE_REDRAW_NO   As Boolean = False

Private LCDLitColorBrush        As Long                     '  color brush for lit segments.
Private LCDBurnInColorBrush     As Long                     '  color brush for 'burn-in' segments.
Private LCDLitColorBrushNeg     As Long                     '  for when value is negative.
Private LCDBurnInColorBrushNeg  As Long                     '  for when value is negative.
Private CurrentLitColorBrush    As Long                     '  which lit segment brush we're currently using.
Private CurrentBurnInColorBrush As Long                     '  which 'burn-in' brush we're currently using.

'  holds binary string patterns indicating which segments to "light up".
'  0-9, unlit segment, minus sign and hex A-F.  18 patterns total.
Private DisplayPattern(0 To 17) As String

Private Const MAX_DIGITS                   As Long = 50     '  maximum displayable number of digits.
Private DigitXPos(0 To MAX_DIGITS - 1)     As Long          '  X coordinate of each main value digit.
Private DigitXPosExp(0 To 4)               As Long          '  X coordinate of each exponent digit.
Private ThousandsFlag()                    As Boolean       '  thousands separator flag for after each digit.

' X and Y coordinates of the decimal separator.
Private DecimalSeparatorPos As POINTAPI

' X and Y coordinates of each 'dot' in the colon.
Private Type ColonCoordinateType
   TopPoint                     As POINTAPI
   BottomPoint                  As POINTAPI
End Type
Private ColonPos                As ColonCoordinateType

'  the widths and heights of main and exponent LCD digits.
Private DigitWidth              As Long                     ' width of a main value digit, in pixels.
Private DigitHeight             As Long                     ' height of a main value digit, in pixels.
Private DigitWidthExp           As Long                     ' width of an exponent digit, in pixels.
Private DigitHeightExp          As Long                     ' height of an exponent digit, in pixels.

Private ChangingPicture As Boolean                          ' so control knows to reblit new bg to virtual DC.
Private PreviousMainValue       As String                   ' used to determine whether to display new digit.
Private PreviousExponentValue   As String                   ' used to determine whether to display new digit.
Private PreviousNegative        As Boolean                  ' flag to determine sign of previously displayed value.

'  default property value constants.
Private Const m_def_BackAngle = 90                          ' horizontal gradient.
Private Const m_def_BackColor1 = &H0                        ' black background gradient start color.
Private Const m_def_BackColor2 = &H0                        ' black background gradient end color.
Private Const m_def_BackMiddleOut = True                    ' middle-out gradient display.
Private Const m_def_BorderWidth = 1                         ' 1-pixel wide border.
Private Const m_def_BorderColor = &HFF0000                  ' blue border color.
Private Const m_def_BurnInColor = &H505000                  ' dark cyan simulated segment burn-in color.
Private Const m_def_BurnInColorNeg = &H505000               ' dark cyan negative value burn-in color.
Private Const m_def_CurveBottomLeft = 0                     ' no curvature.
Private Const m_def_CurveBottomRight = 0                    ' no curvature.
Private Const m_def_CurveTopLeft = 0                        ' no curvature.
Private Const m_def_CurveTopRight = 0                       ' no curvature.
Private Const m_def_DecimalSeparator = 1                    ' period decimal separator.
Private Const m_def_InterDigitGap = 6                       ' 6 pixels between main LCD digits.
Private Const m_def_InterDigitGapExp = 2                    ' 2 pixels between exponent digits.
Private Const m_def_InterSegmentGap = 0                     ' no segment gap in main LCD digit segments.
Private Const m_def_InterSegmentGapExp = 0                  ' no segment gap in exponent digits.
Private Const m_def_NumDigits = 20                          ' 20 main value digits.
Private Const m_def_NumDigitsExp = 4                        ' 3 digits + minus sign.
Private Const m_def_PictureMode = 0                         ' normal picture display.
Private Const m_def_SegmentFillStyle = 1                    ' solid filled digits
Private Const m_def_SegmentHeight = 8                       ' main segments 8 pixels high.
Private Const m_def_SegmentHeightExp = 6                    ' exponent digit segments 4 pixels high.
Private Const m_def_SegmentLitColor = &HFFFF00              ' cyan lit positive value segment.
Private Const m_def_SegmentLitColorNeg = &HFFFF00           ' cyan lit negative value segment.
Private Const m_def_SegmentStyle = 2                        ' rectangular main digit segments.
Private Const m_def_SegmentStyleExp = 2                     ' rectangular exponent digit segments.
Private Const m_def_SegmentWidth = 3                        ' main segments 3 pixels high.
Private Const m_def_SegmentWidthExp = 3                     ' exponent segments 3 pixels wide.
Private Const m_def_ShowBurnIn = True                       ' show 'burned-in' segments.
Private Const m_def_ShowExponent = True                     ' show exponent.
Private Const m_def_ShowThousandsSeparator = False          ' don't show thousands separator.
Private Const m_def_Theme = 5                               ' 'rectangular medium' theme selected.
Private Const m_def_ThousandsGrouping = 3                   ' thousands separator every three digits.
Private Const m_def_ThousandsSeparator = 0                  ' comma thousands separator.
Private Const m_def_Value = "1234567890"                    ' displayed at first by default in design mode.
Private Const m_def_XOffset = 5                             ' 5 pixels from control left border.
Private Const m_def_XOffsetExp = 355                        ' 355 pixels from control left border.
Private Const m_def_YOffset = 5                             ' display main digits 5 pixels down from top edge.
Private Const m_def_YOffsetExp = 5                          ' display exponent 5 pixels from control top.

'  property variables.
Private m_BackAngle              As Single                  ' angle of background gradient.
Private m_BackColor1             As OLE_COLOR               ' first color of background gradient.
Private m_BackColor2             As OLE_COLOR               ' second color of background gradient.
Private m_BackMiddleOut          As Boolean                 ' if True, gradient displays in middle-out fashion.
Private m_BorderColor            As OLE_COLOR               ' border color.
Private m_BorderWidth            As Integer                 ' width, in pixels, of control border.
Private m_BurnInColor            As OLE_COLOR               ' color of simulated LCD digit 'burn-in'.
Private m_BurnInColorNeg         As OLE_COLOR               ' burn in color when value is negative.
Private m_CurveBottomLeft        As Long                    ' amount of curve for bottom left corner.
Private m_CurveBottomRight       As Long                    ' amount of curve for bottom right corner.
Private m_CurveTopLeft           As Long                    ' amount of curve for top left corner.
Private m_CurveTopRight          As Long                    ' amount of curve for top right corner.
Private m_DecimalSeparator       As SeparatorOptions        ' decimal separator character ("." in U.S.).
Private m_InterDigitGap          As Long                    ' # of pixels separating each main value digit.
Private m_InterDigitGapExp       As Long                    ' # of pixels separating each exponent digit.
Private m_InterSegmentGap        As Long                    ' # of pixels separating main value LCD segments.
Private m_InterSegmentGapExp     As Long                    ' # of pixels separating exponent LCD segments.
Private m_NumDigits              As Long                    ' number of digits to display.
Private m_NumDigitsExp           As Long                    ' number of exponent digits to display.
Private m_Picture                As Picture                 ' bitmap to be displayed in lieu of gradient.
Private m_PictureMode            As LCDPicModeOptions       ' normal, stretched or tiled bitmap display options.
Private m_SegmentFillStyle       As SegmentFillStyleOptions ' solid or filament-style segment styles.
Private m_SegmentHeight          As Long                    ' # of pixels in long dimension of main value segment.
Private m_SegmentHeightExp       As Long                    ' # of pixels in short dimension of exponent segment.

⌨️ 快捷键说明

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