|
-
Apr 15th, 2003, 05:38 PM
#1
Thread Starter
New Member
VB - Creating a Matrix LCD simulation
Hi all,
following is a sample on how to create matrix lcd display simulations with VB that look like my signature line using a third party library. You need to download the library from here http://www.inside.net/matrixlcd/MatrixLCD.zip. This zip file also contains this sample.
The basic steps involved are:
- Initialize the matrix LCD library
- Setup the parameters for the given display (any number of displays is possible on a form)
- set the text / optionally also make it scroll.
Create a new project with a form and two buttons on that form, do not change the default names of the buttons.
Add a module (for instance modMatrixLCD.bas) to the project and paste this code:
VB Code:
Public Type POINTAPI
x As Long
y As Long
End Type
Const WS_CUSTOM = 0
Const WS_NORMAL = 1
Const WS_HEAVY = 2
Const WS_HIGH = 3
Const WS_WIDE = 4
Const WS_TINY = 5
Const WS_HUGE = 6
Const CS_CUSTOM = 0
Const CS_GREEN_LCD = 1
Const CS_ORANGE_LCD = 2
Const CS_BLUE_LCD = 3
Const CS_RED_LED = 4
Const CS_ORANGE_LED = 5
Const CS_YELLOW_LED = 6
Const CS_GREEN_LED = 7
Const CS_WHITE_LED = 8
Const CS_BLUE_LED = 9
Const FT_6x9 = 0
Const FT_5x7 = 1
Public Type MatrixLCDSettings
lWeightScheme As Long 'WS_ consts
lColorScheme As Long 'CS_ consts
lFontSize As Long 'FT_ consts
lDotX As Long 'x size for custom weight scheme
lDotY As Long 'y size for custom weight scheme
lXDots As Long 'how many x dots
lYDots As Long 'how many y dots
lDotSpacing As Long 'spacing between dots
lDot1Color As Long 'RGB value for active dot color
lDot0Color As Long 'RGB value for inactive dot
lBackColor As Long 'RGB value for background color
lElementSpacingX As Long 'Horiz spacing between elements
lElementSpacingY As Long 'Vertical spacing between elements
lElementsX As Long 'X dimensions of display (how many elements)
lElementsY As Long 'Y dimentions of display (how many lines)
sText As String * 1024 'text to display
Scrolling As Long '> 0 indicates number of milliseconds for scroll timer
'output
ClientPixelsX As Long 'the calculated X size for the control client area
ClientPixelsY As Long 'the calculated Y size for the control client area
End Type
Declare Function InitializeMatrixLCD Lib "MatrixCtrl.dll" Alias "INITIALIZEMATRIXLCD" (hWnd As Long, sSerial As String) As Long
Declare Function SetupMatrixWindow Lib "MatrixCtrl.dll" Alias "SETUPMATRIXWINDOW" (hWnd As Long, udtMatSet As Long) As Long
Declare Function CreateMatrixWindow Lib "MatrixCtrl.dll" Alias "CREATEMATRIXWINDOW" (hWnd As Long, CtrlID As Long) As Long
Declare Sub MoveMatrixWindow Lib "MatrixCtrl.dll" Alias "MOVEMATRIXWINDOW" (hWnd As Long, pt As POINTAPI)
Declare Sub MatrixPrint Lib "MatrixCtrl.dll" Alias "MATRIXPRINT" (hWnd As Long, ByVal sText As String)
Declare Sub DestroyMatrixWindow Lib "MatrixCtrl.dll" Alias "DESTROYMATRIXWINDOW" (hWnd As Long)
Declare Sub ToggleDisplayScrolling Lib "MatrixCtrl.dll" Alias "TOGGLEDISPLAYSCROLLING" (hWnd As Long, lInterval As Long)
'this only pertains to this sample:
Global hWndCtrl As Long
Open the code section for form1 and paste this code:
VB Code:
Private Sub Command1_Click()
ToggleDisplayScrolling hWndCtrl, 150
End Sub
Private Sub Command2_Click()
Dim pt As POINTAPI
Dim x As Long
Dim y As Long
Dim udtMS As MatrixLCDSettings
Dim pUDT As Long
Dim sText As String
If hWndCtrl > 0 Then
DestroyMatrixWindow hWndCtrl
End If
hWndCtrl = CreateMatrixWindow(Form1.hWnd, 505)
udtMS.lWeightScheme = WS_NORMAL
udtMS.lColorScheme = CS_ORANGE_LCD
udtMS.lFontSize = FT_6x9
udtMS.lElementsX = 35
udtMS.lElementsY = 4
pUDT = SetupMatrixWindow(hWndCtrl, VarPtr(udtMS))
pt.x = 0
pt.y = 30
MoveMatrixWindow hWndCtrl, pt
MatrixPrint hWndCtrl, "VBFORUMS.COM rocks!"
End Sub
Private Sub Form_Load()
Call InitializeMatrixLCD(Form1.hWnd, "1234-DEMO")
End Sub
Discussion on what is done where:
1. When the form is loaded, matrixLCD needs to be initialized with the parent window handle and the license key by calling the InitializeMatrixLCD API. Check the website http://www.inside.net/matrixlcd for information on how to obtain a valid license code.
2. The Command2 button is then used to start the matrix display: first, any existing matrix window is destroyed using DestroyMatrixWindow. Then, a new one is created using the CreateMatrixWindow function with the parent window handle and the control ID which you choose, it should be unique on that form. Then, some standard settings are set up for that instance of the control and applied using the SetupMatrixWindow API. This function returns a pointer to the UDT containing for instance the by then automatically calculated size in X and Y in pixels.
Finally, we want to position and display the text: Simply assign a valid X and Y coordinate to the POINT type and use the MoveMatrixWindow API accordingly. Then to print text use the MatrixPrint API giving the text ByVal (!) and the matrix window handle as parameters.
All done!
3. Finally, if you wish to scroll the text automatically, simply use the ToggleDisplayScrolling API which lets you specify which matrix window to scroll and the interval in milliseconds between each update.
Enjoy!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|