1、我的精彩我做主用 VB制作精彩屏保 我的精彩我做主用 VB制作精彩屏保以下为程序代码Public Declare Function ShowCursor Lib “user32“ (ByVal bShow As Long) As LongOption Explicit声明 DX7变量Public dxMatrix As New DxVBLib.DirectX7Public dxMatrixDraw As DxVBLib.DirectDraw7Public dxMatrixDDSDESC As DxVBLib.DDSURFACEDESC2Public dxMatrixDDS As DxVBLib
2、.DirectDrawSurface7Public dxMatrixDDSDESCBF As DxVBLib.DDSURFACEDESC2Public dxMatrixDDSBF As DxVBLib.DirectDrawSurface7定义类型Public Type ColumnItemx As Integery As IntegerintGreenColour As IntegerintCharacter As IntegerEnd TypePublic Type ColumnItem() As ColumnItemintX As IntegerintY As IntegerintLeng
3、th As IntegerbolActive As BooleanbolOffScreen As BooleanintCounter As IntegerEnd Type79个字符Public intColumn(79) As Column字体Public fntCustom As New StdFont字符总数Public intTotalColumns As Integer是否轮换Public bolAlternate As Boolean启动程序Sub Main()Select Case Mid(Command, 1, 2)Case “/c“frmSettings.ShowCase “/
4、s“InitializeRandomizedxMatrixDDS.SetFontBackColor vbBlackdxMatrixDDS.SetFontTransparency FalseWith fntCustom.Name = “Matrix“.Size = 8.Bold = FalseEnd WithdxMatrixDDS.SetFont fntCustomDim i As Integer, h As IntegerFor i = 0 To 79intColumn(i).intLength = Int(Rnd * 10) + 30ReDim intColumn(i).Item(intCo
5、lumn(i).intLength)intColumn(i).bolActive = FalseintColumn(i).intCounter = 0intColumn(i).bolOffScreen = FalseintColumn(i).intX = iintColumn(i).intY = 0For h = 0 To intColumn(i).intLengthintColumn(i).Item(h).intCharacter=Int(Rnd*43)+65intColumn(i).Item(h).intGreenColour=Int(Rnd*255)Next hNext iintTota
6、lColumns = 0bolAlternate = TruefrmMain.tmrMain.Enabled = TrueEnd SelectEnd Sub初始化Sub Initialize()隐藏光标ShowCursor (0)Set dxMatrixDDSBF = NothingSet dxMatrixDDS = Nothing通过 DX7绘制出效果Set dxMatrixDraw = dxMatrix.DirectDrawCreate(“)dxMatrixDraw.SetCooperativeLevel frmMain.hWnd, DDSCL_FULLSCREEN Or DDSCL_EX
7、CLUSIVE Or DDSCL_ALLOWMODEXCall dxMatrixDraw.SetDisplayMode(640, 480, 32, 0, DDSDM_DEFAULT)dxMatrixDDSDESC.lFlags = DDSD_CAPS Or DDSD_BACKBUFFERCOUNTdxMatrixDDSDESC.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE Or DDSCAPS_COMPLEX Or DDSCAPS_FLIPdxMatrixDDSDESC.lBackBufferCount = 1Set dxMatrixDDS = dxMatrix
8、Draw.CreateSurface(dxMatrixDDSDESC)Dim ddCaps As DDSCAPS2ddCaps.lCaps = DDSCAPS_BACKBUFFERSet dxMatrixDDSBF = dxMatrixDDS.GetAttachedSurface(ddCaps)dxMatrixDDSBF.GetSurfaceDesc dxMatrixDDSDESCBFEnd SubPrivate Sub tmrMain_Timer()Dim intStartColumn As Integer, x As Integer, y As IntegerIf intTotalColu
9、mns 20 ThenCall dxMatrixDDS.SetForeColor(vbBlack)Call dxMatrixDDS.DrawText(x * 8, intColumn(x).intCounter * 12, Chr(intColumn(x).Item(intColumn(x).intCounter).intCharacter),False)intColumn(x).intCounter = intColumn(x).intCounter + 1If intColumn(x).intCounter = intColumn(x).intLength ThenintColumn(x)
10、.bolActive = FalseintColumn(x).bolOffScreen = FalseintTotalColumns = intTotalColumns - 1intColumn(x).intCounter = 0End IfEnd IfEnd IfIf intColumn(x).intCounter = intColumn(x).intLength Or intColumn(x).intCounter = 41 ThenCall dxMatrixDDS.SetForeColor(RGB(0, intColumn(x).Item(intColumn(x).intCounter
11、- 1).intGreenColour, 0)Call dxMatrixDDS.DrawText(x * 8, (intColumn(x).intCounter - 1) * 12, Chr(intColumn(x).Item(intColumn(x).intCounter - 1).intCharacter), False)intColumn(x).bolOffScreen = TrueintColumn(x).intCounter = 0End IfEnd IfEnd IfNext xEnd SubDim intWaitTime As Integer按下键盘时退出Private Sub F
12、orm_KeyDown(KeyCode As Integer, Shift As Integer)按下 P键暂停,否则退出If KeyCode = vbKeyP ThenIf tmrMain.Enabled = False ThentmrMain.Enabled = TrueElsetmrMain.Enabled = FalseEnd IfElsedxMatrixDraw.RestoreDisplayModedxMatrixDraw.SetCooperativeLevel frmMain.hWnd, DDSCL_NORMALShowCursor (1)Unload MeEnd IfEnd Sub鼠标移动时退出Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)做一个循环来进行延时intWaitTime = intWaitTime + 1If intWaitTime 10 ThendxMatrixDraw.RestoreDisplayModedxMatrixDraw.SetCooperativeLevel frmMain.hWnd, DDSCL_NORMALShowCursor (1)Unload MeEnd IfEnd Sub