by DiskJunky (16 Submissions)
Category: Windows API Call/Explanation
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Mon 18th December 2000
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Some API functions for hiding/showing/moving the mouse, etc... enjoy.
API Declarations
Declare Sub SetCursorPos Lib "user32" (ByVal X As Integer, ByVal Y As Integer)
Declare Function ShowCursor Lib "user32" (ByVal bShow As Long) As Long
Declare Function MciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As Any, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
Declare Function FindWindow% Lib "user32" Alias "FindWindowA" (ByVal lpClassName$, ByVal lpWindowName$)
Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByRef lpvParam As Any, ByVal fuWinIni As Long) As Long
'Here's some API functions for moving, hiding
'the mouse etc... enjoy...
'-DiskJunky
Public Const EWX_FORCE = 4
Public Const EWX_REBOOT = 2
Public Const EWX_SHUTDOWN = 1
Public Function CDOpen() As Integer
Dim RetValue As Integer
RetValue = MciSendString("set CDAudio door open", vbNullString, 0, 0)
CDOpen = RetValue
End Function
Sub CDRom_Open()
'Open's your CD Rom drive...AKA cup holder...
RetValue = MciSendString("set CDAudio door open", vbNullString, 0, 0)
End Sub
Sub CDRom_Close()
'Closes your CD Rom drive
RetValue = MciSendString("set CDAudio door closed", vbNullString, 0, 0)
End Sub
Sub CDRom_Ghost()
'Pretty stupid... might be funny if you leave this running on someone's computer
'while they're out to coffe... SET THE PAUSE INTERVALS TO WHATEVER YOU WANT,
'DEPENDING ON WHAT YOU WANT THIS TO ACT LIKE...
Do
Call CDRom_Open
Pause 1
Call CDRom_Close
Pause 3
Loop
End Sub
Sub Computer_Restart()
'Will restart the computer
ForcedShutdown = ExitWindowsEx(EWX_REBOOT, 0&)
End Sub
Sub Computer_Shutdown()
'Will shut-down the computer
StandardShutdown = ExitWindowsEx(EWX_SHUTDOWN, 0&)
End Sub
Sub Computer_ForceShutdown()
'Forces a shut-down of the computer
ForcedShutdown = ExitWindowsEx(EWX_FORCE, 0&)
End Sub
Sub Mouse_Show()
'Shows your mouse cursor
Hid = ShowCursor(True)
End Sub
Sub Mouse_Hide()
'Hides your mouse cursor
Hid = ShowCursor(False)
End Sub
Public Sub MoveCursor(X As Integer, Y As Integer)
Call SetCursorPos(X, Y)
End Sub
Sub Mouse_Insane()
'Crzy mouse movement.. could be useful to make a prog like Fake Surf...
Dim Counter As Long
Do
boob = (Rnd * 800)
boob2 = (Rnd * 600)
'whatever =
Call SetCursorPos(boob, boob2)
'pause
For Counter = 1 To 9000000
DoEvents
Next Counter
DoEvents
Loop
End Sub
Sub StartMenu_Hide()
'Hides the Start Menu
'C% = FindWindow("Shell_TrayWnd", vbNullString)
'A = ShowWindow(C%, SW_HIDE)
End Sub
Sub StartMenu_Show()
'Shows the Start Menu
' doesn't work for me, but maybe that's cause i'm on Windows NT...
'C% = FindWindow("Shell_TrayWnd", vbNullString)
'A = ShowWindow(C%, SW_SHOW)
End Sub
Function CtrlAltDel_Enable()
'This re-enables CTRL+ALT+Delete
Dim ret As Integer
Dim pOld As Boolean
'ret = SystemParametersInfo(SPI_SCREENSAVERRUNNING, False, pOld, 0)
End Function
Function CtrlAltDel_Disable()
'This will disable the CTRL+ALT+DELETE function of Windows.
'Make sure you re-enable this before your prog ends,
'or the person using this is screwed!
Dim ret As Integer
Dim pOld As Boolean
ret = SystemParametersInfo(SPI_SCREENSAVERRUNNING, True, pOld, 0)
End Function
Sub ScreenSaver_On()
'Turns on your screen saver... close the screen saver by doing something... duh...
'Not sure if this works either... i don't use screen savers...
Dim lResult As Long
Const WM_SYSCOMMAND = &H112
Const SC_SCREENSAVE = &HF140
'lResult = SendMessage(-1, WM_SYSCOMMAND, SC_SCREENSAVE, 0&)
End Sub
Sub PlayWav(DiR)
'Plays the specified WAV file...
Dim X%
SoundName$ = DiR
wFlags% = SND_ASYNC Or SND_NODEFAULT
'X% = sndPlaySound(SoundName$, wFlags%)
End Sub
Sub Pause(interval)
'Don't modify this!
'This just puts a delay between actions...
'like...
'Call CtrlAltDel_Disable
'Pause 15
'Call CtrlAltDel_Enable
'That will put a 15 second pause between the
'CTRL ALT DELETE Disable and Enable
Dim Current
Current = Timer
Do While Timer - Current < Val(interval)
DoEvents
Loop
End Sub
Public Sub MoveMouseTo(StartX As Integer, StartY As Integer, X As Integer, Y As Integer, Speed As Integer)
'move the mouse pointer from it's current position
'to the new position
Dim CurrentX As Integer
Dim CurrentY As Integer
CurrentX = StartX
CurrentY = StartY
While (CurrentX <> X) And (CurrentY <> Y)
DoEvents
CurrentX = CurrentX + ((X - StartX) \ Speed)
CurrentY = CurrentY + ((Y - StartY) \ Speed)
Call SetCursorPos(CurrentX, CurrentY)
Wend
End Sub
No comments have been posted about Some API functions for hiding/showing/moving the mouse, etc... enjoy.. Why not be the first to post a comment about Some API functions for hiding/showing/moving the mouse, etc... enjoy..