Click to See Complete Forum and Search --> : Funny API
rancor
Sep 14th, 2000, 02:59 PM
Hi..
I'm learning to use API and one silly simple on is this that makes random bip's on the pc-speaker:
Public Declare Function Beep Lib "kernel32" Alias "Beep" (ByVal dwFreq As Long, ByVal dwDuration As Long) As Long
Dim l As Long
Dim i As Integer
Randomize
For i = 1 To 1000
l = Beep(Int(10000 * Rnd), 50)
Next
Anyone that got something more stupid or fun???
gwdash
Sep 14th, 2000, 03:17 PM
I love changing the title bar caption of the Active Window
'didn't include declares
Dim wnd
wnd = GetForegroundWindow()
' Display the text displayed in the title bar of window Form1
Dim textlen As Long ' receives length of text of the window
Dim wintext As String ' receives the text of the window
Dim slength As Long ' receives the length of the returned string
' Find out how many characters are in the window's text.
' Add 1 to compensate for the terminating null.
textlen = GetWindowTextLength(wnd) + 1
' Make sufficient room in the buffer.
wintext = Space(textlen)
' Retrieve the text of window Form1.
slength = GetWindowText(wnd, wintext, textlen)
' Remove the empty space from the string, if any.
wintext = Left(wintext, slength)
' Display the result.
retval = SetWindowText(wnd, "A Joke")
' Flash Form1 five times to get the user's attention
Dim c As Integer ' counter variable & return value
For c = 1 To 10 ' flash on five times, off five times
retval = FlashWindow(wnd, 1) ' toggle the look of the window
Sleep 500 ' halt execution for 500 milliseconds (1/2 minute)
Next c
retval = FlashWindow(wnd, 0) ' make sure the window looks normal
retval = SetWindowText(wnd, wintext) 'reset old text
Here's a pretty good one.
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 Form_Load()
Dim lngReturn As Long
Dim strReturn As Long
opencd = MsgBox("Are you in the mood for a free gift?", 4 + 32)
If opencd = vbYes Then
lngReturn = mciSendString("set CDAudio door open", strReturn, 127, 0)
MsgBox "There you are. A free cup holder :).", 64
Else
MsgBox "Okay, maybe next time.", 16
End If
End Sub
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.