API 函数关闭计算机、控制光驱、控制键盘
时 间:2018-01-30 22:52:14
作 者:林岚 ID:3651 城市:中卫
摘 要:1、如何关闭计算机?
2、在程序中如何打开和关闭光驱门?
3、怎样使Ctrl-Alt-Delete无效?
4、怎样确定系统是否安装了声卡?
5、如何找到CD-ROM驱动器的盘号?
6、如何将文件放入回收站?
7、如何得知键盘number lock等开关键的状态?
正 文:
1、如何关闭计算机?
*API函数声明
Declare Function ExitWindows Lib "User" (ByVal dwReturnCode As Long, ByVal wReserved As Integer) As Integer
注释:执行
Dim DUMMY
DUMMY=ExitWindows(0,0)
2、在程序中如何打开和关闭光驱门?
*API函数声明如下:
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
注释:调用时的代码如下
Dim Ret As Long
Dim RetStr As String
注释:打开光驱门
Ret = mciSendString("set CDAudio door open", RetStr, 0, 0)
注释:关闭光驱门
Ret = mciSendString("set CDAudio door closed", RetStr, 0, 0)
3、怎样使Ctrl-Alt-Delete无效?
*API函数声明
Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByVal lpvParam As Any, ByVal fuWinIni As Long) As Long
编写如下函数:
Sub DisableCtrlAltDelete(bDisabled As Boolean)
Dim X As Long
X = SystemParametersInfo(97, bDisabled, CStr(1), 0)
End Sub
使Ctrl-Alt-Delete无效 :
Call DisableCtrlAltDelete(True)
恢复Ctrl-Alt-Delete :
Call DisableCtrlAltDelete(False)
4、怎样确定系统是否安装了声卡?
*API函数声明:
Declare Function waveOutGetNumDevs Lib "winmm.dll" Alias "waveOutGetNumDevs" () As Long
代码如下:
Dim I As Integer
I = waveOutGetNumDevs()
If I > 0 Then MsgBox "你的系统可以播放声音。", vbInformation, "声卡检测"
Else
MsgBox "你的系统不能播放声音。", vbInformation, "声卡检测"
End If
5、如何找到CD-ROM驱动器的盘号?
下面的函数将检查你计算机所有的驱动器看是否是 CD-ROM,如果是就返回驱动器号,如果没有就返回空字符
Public Function GetCDROMDrive() As String
Dim lType As Long,I As Integer,tmpDrive as String,found as Boolean
On Error GoTo errL
For I = 0 To 25
tmpDrive = Chr(65 + I) & ":"
lType = GetDriveType(tmpDrive) 注释:Win32 API 函数
If (lType = DRIVE_CDROM) Then 注释:Win32 API 常数
found = True
Exit For
End If
Next
If Not found Then tmpDrive = ""
BI_GetCDROMDrive = tmpDrive
exit Function
errL: msgbox error$
End Function
6、如何将文件放入回收站?
**API函数声明
Public Type SHFILEOPSTRUCT
hwnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAnyOperationsAborted As Long
hNameMappings As Long
lpszProgressTitle As Long
End Type
Public Declare Function SHFileOperation Lib _ "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
Public Const FO_Delete = &H3
Public Const FOF_ALLOWUNDO = &H40
注释:调用
Dim Shop As SHFILEOPSTRUCT, strFile as string
With Shop
.wFunc = FO_Delete
.pFrom = strFile + Chr(0)
.fFlags = FOF_ALLOWUNDO
End With
7、如何得知键盘number lock等开关键的状态?
Declare Function GetKeyState Lib "User32" (ByVal lngVirtKey As Long) As Integer
GetKeyState(vbKeyNumLock)
GetKeyState(vbKeyCapital)
Access软件网QQ交流群 (群号:54525238) Access源码网店
常见问答:
技术分类:
源码示例
- 【源码QQ群号19834647...(12.17)
- Access对子窗体数据进行批...(10.30)
- 最精简的组合框行来源数据快速输...(10.25)
- Access仿平台的多值选择器...(10.24)
- 【Access日期区间段查询】...(10.22)
- 【Access源码示例】VBA...(10.12)
- Access累乘示例,Acce...(10.09)
- 数值8.88,把整数8去掉,转...(10.08)
- 【Access自定义函数】一个...(09.30)
- 【Access选项卡示例】Ac...(09.09)
学习心得
最新文章
- Access快速开发平台--对上传...(11.22)
- Access快速开发平台企业版--...(11.18)
- 不会用多表联合查询,多表查询没结果...(11.16)
- 【案例分享】主键字段值含有不间断空...(11.16)
- Access快速开发平台--后台D...(11.14)
- 微软Access邀测新Monaco...(11.12)
- Access列表框左右互选、列表框...(11.11)
- 高效率在导入数据前删除记录(11.10)
- Access报价单转订单示例代码(11.08)
- Access系统自带的日期选择器不...(11.08)