56、如何检查软盘驱动器里是否有软盘? 57、如何弹出和关闭光驱托盘? 58、如何计算出本月的最后一天 59、如何让你的程序在任务列表隐藏 60、如何利用API实现代码延时执行
56、如何检查软盘驱动器里是否有软盘?
使用: Dim Flag As Boolean Flag = Fun_FloppyDrive("A:") If Flag =
False Then MsgBox "A:驱没有准备好,请将磁盘插入驱动器!",
vbCritical
'------------------------------- '函数:检查软驱中是否有盘的存在 '------------------------------- Private
Function Fun_FloppyDrive(sDrive As String) As Boolean On Error Resume
Next Fun_FloppyDrive = Dir(sDrive) <> "" End Function
57、如何弹出和关闭光驱托盘?
Option Explicit 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
Private Sub
Command1_Click() mciExecute "set cdaudio door open"
'弹出光驱 Label2.Caption = "弹 出" End Sub
Private Sub
Command2_Click() Label2.Caption = "关 闭" mciExecute "set cdaudio door
closed" '合上光驱 Unload Me End End Sub
58、如何计算出本月的最后一天
首先为下个月的第一天生成一个顺序数值,然后再减去一天
Private Sub Command1_Click() Dim
dtl As Date dtl = DateSerial(Year(Now), Month(Now) + 1, 1) -
1 MsgBox dtl End Sub
59、如何让你的程序在任务列表隐藏
Private Declare Function RegisterServiceProcess Lib "kernel32" (ByVal
ProcessID As Long, ByVal ServiceFlags As Long) As Long Private Declare
Function GetCurrentProcessId Lib "kernel32" () As Long
'请你试试
Ctrl+Alt+Del 是不是你的程序隐藏了 Private Sub Command1_Click() i =
RegisterServiceProcess(GetCurrentProcessId, 1) End Sub
60、如何利用API实现代码延时执行
声明: Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds
As Long)
调用: Sleep 3000
'延时3秒执行 |