正在阅读:vb 高手搜集-常见问题总结(1)vb 高手搜集-常见问题总结(1)

2005-06-10 10:20 出处: 作者:阳光宝宝 责任编辑:moningfeng
如何检查软盘驱动器里是否有软盘

  使用:

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

  如何弹出和关闭光驱托盘

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

  如何让你的程序在任务列表隐藏

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

  如何用程序控制滑鼠游标 (Mouse Cursor) 到指定位置   以下这个例子,当 User 在 Text1 中按下 'Enter' 键后,滑鼠游标会自动移到 Command2 按钮上方   请在声明区中加入以下声明:   16 位版本: ( Sub 无传回值 )

Declare Sub SetCursorPos Lib "User" (ByVal X As Integer, ByVal Y As Integer)

  32 位版本: ( Function 有传回值,Integer 改成 Long )

Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long

  在 Form1 中加入以下程序码:

Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then x% = (Form1.Left + Command2.Left + Command2.Width / 2 + 60) / Screen.TwipsPerPixelX y% = (Form1.Top + Command2.Top + Command2.Height / 2 + 360) / Screen.TwipsPerPixelY SetCursorPos x%, y% End If End Sub

键盘也能翻页,试试“← →”键

关注我们

最新资讯离线随时看 聊天吐槽赢奖品