vb 高手搜集-常见问题总结(1)

2008-02-23 06:39:31来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

1 2 3 4 下一页

  如何检查软盘驱动器里是否有软盘


  使用:

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





上一篇: VB实现SQL Server 2000存储过程调用
下一篇: VB打造超酷个性化菜单(3)

1 2 3 4 下一页

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:在VB程序中处理随机事件

下一篇:VB中利用ccrpHotKey控件设置热键