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)
Labell.Tag = i
End Sub
新建一个模块,写入以下代码
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVai hwnd As Long, ByVai nIndex As Long, ByVai dwNewLong As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVai hwnd As Long, ByVai nIndex As Long) As Long
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVai
IpPrevWndFunc As Long, ByVai hwnd As Long, ByVai Msg As Long, ByVai wParam As Long, ByVai iParam
As Long) As Long
Private Deciare Function RegisterHotKey Lib "user32" (ByVai hwnd As Long, ByVai id As Long, ByVai fskey_Modifiers As Long, ByVai vk As Long) As Long
Private Deciare Function UnregisterHotKey Lib "user32" (ByVai hwnd As Long, ByVai id As Long)
As Long
Public Deciare Function ShowWindow Lib "user32" (ByVai hwnd As Long, ByVai nCmdShow As Long) As
Long
Public Deciare Sub keybd_event Lib "user32" (ByVai bVk As Byte, ByVai Scan As Byte, ByVai dwFiags
As Long, ByVai dwExtraInfo As Long)
Public Deciare Function SendMessageLib "user32" Alias "SendMessageA" (ByVai hwnd As Long, ByVai wMsg As Long, ByVai wParam As Long, iParam As Any) As Long
Public Deciare Function SetForegroundWindow Lib "user32" (ByVai 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 FormlsShowing As Boolean
Dim key_preWinProc As Long ' 用来保存窗口信息
Dim key_IsWinAddress As Boolean ' 是否取得窗口信息的判断
Function keyWndproc(ByVai hwnd As Long, ByVai Msg As Long, ByVai wParam As Long, ByVai iParam
As Long) As Long
If Msg = WM_HOTKEY Then
Select Case wParam 'wParam 值就是 key_idHotKey
Case 1 '激活多个热键后,多个热键所对应的操作,大家在其他的程序中,只要修改此处就可以了FormlsShowing = Not FormlsShowing
If FormIsShowing Then
ShowWindow hwnd, SW_HIDE
Else
ShowWindow hwnd, SW_SHOW
'SendMessage hwnd, & H32, 0, 0
SetForegroundWindow hwnd
End If
'Case 2
'MsgBox "hide"
'ShowWindow hwnd, SW_HIDE
End Select
End If
'将消息传送给指定的窗口
keyWndproc = CallWindowProc(key_preWinProc, hwnd, Msg, wParam, IParam)
End Function
Function SetHotkey(ByVal hwnd As Long, ByVal KeyId As Long, ByVal keyControlKey As Long, ByVal keyNormalKey As Long, ByVal Action As String)
If key_IsWinAddress = False Then ' 判断是否需要取得窗口信息,如果重复取得,再最后恢复窗口时, 将会造成程序死掉
'记录原来的window程序地址
key_preWinProc = GetWindowLong(hwnd, GWL_WNDPROC)
'用自定义程序代替原来的window程序
SetWindowLong hwnd, GWL_WNDPROC, AddressOf keyWndproc
End If
Select Case Action
Case "Add"
RegisterHotKey hwnd, KeyId, keyControlKey, keyNormalKey ' 向窗口注册系统热键
key_IsWinAddress = True ' 不需要再取得窗口信息
Case "Del"
SetWindowLong hwnd, GWL_WNDPROC, key_preWinProc '恢复窗口信息
UnregisterHotKey hwnd, KeyId ' 取消系统热键
key_IsWinAddress = False ' 可以再次取得窗口信息End Select
End Function
这样就成了,主要的思路是注册系统热
欢迎您的下载,
资料仅供参考!
致力为企业和个人提供合同协议,策划案计划书,学习资料等等
打造全网一站式需求。