打印

[原创] VB写的一个小程序

VB写的一个小程序

想你的帮助文件也能这样秀一把吗?那就看看下面的:
窗体一:frmMain
复制内容到剪贴板
代码:
Option Explicit

Private Sub mnuHelpAbout_Click()

frmAbout.Show vbModal, Me

End Sub
窗体二:frmAbout
复制内容到剪贴板
代码:
Option Explicit
Private Declare Function DrawText Lib "user32" Alias "DrawTextA" (ByVal hdc As Long, ByVal lpStr As String, ByVal nCount As Long, lpRect As RECT, ByVal wFormat As Long) As Long
Private Declare Function GetTickCount Lib "kernel32" () As Long

Const DT_BOTTOM As Long = &H8
Const DT_CALCRECT As Long = &H400
Const DT_CENTER As Long = &H1
Const DT_EXPANDTABS As Long = &H40
Const DT_EXTERNALLEADING As Long = &H200
Const DT_LEFT As Long = &H0
Const DT_NOCLIP As Long = &H100
Const DT_NOPREFIX As Long = &H800
Const DT_RIGHT As Long = &H2
Const DT_SINGLELINE As Long = &H20
Const DT_TABSTOP As Long = &H80
Const DT_TOP As Long = &H0
Const DT_VCENTER As Long = &H4
Const DT_WORDBREAK As Long = &H10

Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
End Type

'the actual text to scroll. This could also be loaded in from a text file
Const ScrollText As String = "想学习就在HTTP://WWW.HACKERXFILES.NET" & vbCrLf & _
                             ""
                             
Dim EndingFlag As Boolean

Private Sub Form_Activate()
RunMain
End Sub

Private Sub Form_Load()

picScroll.ForeColor = vbYellow
picScroll.FontSize = 14

End Sub

Private Sub RunMain()
Dim LastFrameTime As Long
Const IntervalTime As Long = 40
Dim rt As Long
Dim DrawingRect As RECT
Dim UpperX As Long, UpperY As Long 'Upper left point of drawing rect
Dim RectHeight As Long

'show the form
frmAbout.Refresh

'Get the size of the drawing rectangle by suppying the DT_CALCRECT constant
rt = DrawText(picScroll.hdc, ScrollText, -1, DrawingRect, DT_CALCRECT)

If rt = 0 Then 'err
    MsgBox "Error scrolling text", vbExclamation
    EndingFlag = True
Else
    DrawingRect.Top = picScroll.ScaleHeight
    DrawingRect.Left = 0
    DrawingRect.Right = picScroll.ScaleWidth
    'Store the height of The rect
    RectHeight = DrawingRect.Bottom
    DrawingRect.Bottom = DrawingRect.Bottom + picScroll.ScaleHeight
End If


Do While Not EndingFlag
   
    If GetTickCount() - LastFrameTime > IntervalTime Then
                    
        picScroll.Cls
        
        DrawText picScroll.hdc, ScrollText, -1, DrawingRect, DT_CENTER Or DT_WORDBREAK
        
        'update the coordinates of the rectangle
        DrawingRect.Top = DrawingRect.Top - 1
        DrawingRect.Bottom = DrawingRect.Bottom - 1
        
        'control the scolling and reset if it goes out of bounds
        If DrawingRect.Top < -(RectHeight) Then 'time to reset
            DrawingRect.Top = picScroll.ScaleHeight
            DrawingRect.Bottom = RectHeight + picScroll.ScaleHeight
        End If
        
        picScroll.Refresh
        
        LastFrameTime = GetTickCount()
        
    End If
   
    DoEvents
Loop

Unload Me
Set frmAbout = Nothing

End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
lblExit.ForeColor = vbYellow
End Sub

Private Sub Form_Unload(Cancel As Integer)

    EndingFlag = True
   
End Sub

Private Sub lblExit_Click()

Beep

EndingFlag = True

End Sub

Private Sub lblExit_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
lblExit.ForeColor = vbRed
End Sub
[ 本帖最后由 破风 于 2007-2-1 12:38 编辑 ]

附件

1.jpg (46.78 KB)

2006-12-20 16:04

1.jpg

2.jpg (13.64 KB)

2006-12-20 16:05

2.jpg

gunping.rar (4.32 KB)

2006-12-20 16:07, 下载次数: 124

本帖最近评分记录
  • flyli 金币 +10 精品文章 2006-12-21 10:55

TOP

不错,感觉很好,:handshake
学了6年了,还是初学者。。。。。。。。

回复 #2 flyli 的帖子

谢谢版主的鼓励。我会为黑“X”尽力去做的。:handshake :handshake

TOP

忽忽
不错不错
我也想学VB

回复 #5 遗忘的角落 的帖子

提出你不同的看法来.把不对的地方请你帮助找出来.谢谢了.这样也可以让大家一块学习一下.

TOP

好像用option explicit就可以找到了。
但是一个About窗体就用这么多代码……不大好吧……
觉得不错  希望继续努力
为了黑x再努力!!

TOP

大家有什么好想法,都可以发上来啊,即提高了自己又帮助了他人,何乐而不为呢
测试一下先`~~~``~~~等下再来回```\

TOP

LZ我测试怎么错误啊?>??
   帮我看下??

附件

错误.jpg (13.85 KB)

2007-2-1 12:52

错误.jpg

错误2.jpg (70.93 KB)

2007-2-1 12:52

错误2.jpg

Processed in 0.107414 second(s), 7 queries, Gzip enabled