VB制作随机点名程序源码
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
VB制作幻灯片随机点名工具
大家好,我是丶灬尛坏坏"
注:此程序适用于学校班级实用,
此文是原创,转载请标明出处,
本次教程:这个在powerpoint里,完全和powerpoint结合起来,我简单写了一下,新建一个vb程序,在窗体上放一个label,一个timer和一个按钮,timer 的interval设置为1,Enable设置为False。
源码(不解释,自己研究):
Dim a(0 To 9) As String
Private Sub Command1_Click()
Timer1.Enabled = Not Timer1.Enabled
End Sub
Private Sub Form_Load()
SetHotkey Me.hwnd, 1, 0, vbKeyHome, "Add"
a(0) = "张三"
a(1) = "李四"
a(2) = "王五"
a(3) = "刘六"
a(4) = "牛七"
a(5) = "马八"
a(6) = "杨九"
a(7) = "苟十"
a(8) = "朱十一"
a(9) = "吕十二"
End Sub
Private Sub Form_Unload(Cancel As Integer)
SetHotkey Me.hwnd, 1, 0, 0, "Del"
End Sub
Private Sub Timer1_Timer()
Dim i As Integer
i = Int(Rnd * 10)
Label1.Caption = a(i)
Label1.Tag = i
End Sub
新建一个模块,写入以下代码
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function RegisterHotKey Lib "user32" (ByVal hwnd As Long, ByVal id As Long, ByVal fskey_Modifiers As Long, ByVal vk As Long) As Long
Private Declare Function UnregisterHotKey Lib "user32" (ByVal hwnd As Long, ByVal id As Long) As Long
Public Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Public Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal Scan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Const SW_HIDE = 0
Const SW_SHOW = 5
Const WM_HOTKEY = &H312
Const MOD_ALT = &H1
Const MOD_CONTROL = &H2
Const MOD_SHIFT = &H4
Const GWL_WNDPROC = (-4) '窗口函数的地址
Dim FormIsShowing As Boolean
Dim key_preWinProc As Long '用来保存窗口信息
Dim key_IsWinAddress As Boolean '是否取得窗口信息的判断
Function keyWndproc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If Msg = WM_HOTKEY Then
Select Case wParam 'wParam 值就是key_idHotKey
Case 1 '激活多个热键后,多个热键所对应的操作,大家在其他的程序中,只要修改此处就可以了