The Beginners Guide To API
This article teaches you the basics of Windows API
by giving you a walk through of Declaring API
Functions from Start to Finish & uses real examples
of useful code you can use in your Projects!
Original Author: Dave Greenwood
Code
The Beginners Guide To API What is Windows API It is Windows Application Programming So What can these functions do for me (you These pre-built functions allow your program to Example: You want your VB program to Restart In your module Privatesize="2"> Declaresize="2"> Functionsize="2"> ExitWindowsEx size="2">Lib "user32" If you wanted your computer to shutdown after Sub Command1_Click () X = ExitWindowsEx (15, 0) End Sub ---------------- Privatesize="2"> Declaresize="2"> Functionsize="2"> ExitWindowsEx size="2">Lib "user32" Now to Explain what the above means Privatesize="2"> Declaresize="2"> Functionsize="2"> ExitWindowsEx tells VB to Declare a Private Function The size="2">Lib "user32" part The final part tells VB to expect the variables (ByVal uFlags As Long, ByVal dwReserved As The ByVal means pass this variable by The As Long tells VB what data type the You can find more about data types in your VB Now you should know what each part of the X = ExitWindowsEx (15, 0) For VB to run a function it needs to know where What's the point of X = If the function runs or fails it will give you For example if the function fails it might give If x <> 1 Then MsgBox "Restart has ---------- Now you should know what everything in the To get you started I have included some PLAY A WAVEFILE (WAV) Declare color="#000080" size="2">Function Public color="#000080" size="2">Const SND_SYNC = Sub Command1_Click () SoundName$ = File 'file you want to play End sub CHANGE WALLPAPER Declare color="#000080" size="2">Function End sub ADD FILE TO DOCUMENTS OF WINDOWS MENU BAR Declare color="#000080" size="2">Sub MAKE FORM TRANSPARENT Private Sub Form_Load() SetWindowLong Me.hwnd, GWL_EXSTYLE, End Any Problems email me at href="mailto:DSG@hotbot.com">DSG@hotbot.comsize="2">
Interface. This basically means that Windows has built in
functions that programmers can use. These are built into its DLL
files. (Dynamic Link Library)
might ask) ?
do stuff without you actually have to program them.
Windows, instead of your program communicating directly to the
various bits & pieces to restart your computer. All you have
to do is run the pre-built function that Windows has kindly made
for you. This would be what you would type if you have VB4 32, or
higher.
(ByVal uFlags As Long, ByVal dwReserved As Long) As Long
you press Command1 then type this In your Form under
(ByVal uFlags As Long, ByVal dwReserved As Long) As Long
called "ExitWindowsEx".
tells VB that the function ExitWindowsEx is in the Library
(DLL file) called "user32".
that the ExitWindowsEx function uses.
Long) As Long
value instead of by reference.
information is.
help files.
Declaration means so now we go on to what does
to put the data it returns from the function. The X = tells
VB to put the response from ExitWindowsEx into the
variable X.
back a response number so you know what it has done.
you back a number other than 1 so you can write some code to tell
the user this.
Failed"
Declaration above means. You are now ready to start using API
calls in your own VB projects.
useful API calls you might want to use that I've found on Planet
Source Code.
sndPlaySound Libsize="2"> "winmm.dll" size="2">Alias "sndPlaySoundA"
(ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
&H0 Public color="#000080">Const SND_ASYNC = &H1
Public Const SND_NODEFAULT = &H2
Public Const SND_MEMORY = &H4
Public Const SND_LOOP = &H8
Public Const SND_NOSTOP = &H10
example "C:windowskerchunk.wav" wFlags% = SND_ASYNC Or SND_NODEFAULT
X = sndPlaySound(SoundName$, wFlags%)
SystemParametersInfo Libsize="2"> "user32" size="2">Alias
"SystemParametersInfoA" (ByVal uAction As Long, ByVal
uParam As Long, ByVal lpvParam As Any, ByVal fuWinIni As Long) As
Long
Public Const SPI_SETDESKWALLPAPER = 20
Sub Command1_Click ()
Dim strBitmapImage As color="#000080">String
strBitmapImage = "c:windowsstraw.bmp"
x = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, strBitmapImage, 0)
SHAddToRecentDocs Libsize="2"> "shell32.dll" (ByVal uFlags As Long, ByVal pv
As String)Dim NewFile as color="#000080">String
NewFile="c:
ewfile.file"
Call SHAddToRecentDocs(2,NewFile)Declare Function SetWindowLong color="#000080">Lib "user32" color="#000080">Alias "SetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long,ByVal dwNewLong As Long) As Long
Public Const GWL_EXSTYLE = (-20)
Public Const WS_EX_TRANSPARENT = &H20&
WS_EX_TRANSPARENT
Loading Comments ...
Comments
No comments have been added for this post.
You must be logged in to make a comment.