API - Application Programmer's Interface
Visit us at: http://www.vbparadise.com. As a programmer you might never have to use a Windows API.... Nahhh! The fact is that serious programmers use API all the time. When they need to do something that VB cannot handle, they turn to the Windows API! The API are procedures that exist in files on your PC which you can call from within your VB program - and there are thousands of them!. Written by Microsoft, debugged by tens of thousands of users, and available for free with Windows - the API are one of the very best tools you have available to add power to your VB application.
एआई सारांश: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="712" id="AutoNumber1">
<tr>
<td width="712">
<h4 align="center"><font face="Verdana" size="5">Visit Us At:
<span style="font-weight: 400"><a href="http://www.vbparadise.com">
http://www.vbparadise.com</a></span></font></h4>
<h4></h4>
<h4><font face="Verdana" size="2">API - Application Programmer's Interface</font></h4>
<p><font face="Verdana" size="2">When Microsoft wrote Windows they put a huge
amount of code into procedure libraries which programmers can access. No matter
which language you're using (VB, C++, ...) you can use the Windows API to
greatly expand the power of your application. </font><p>
<font face="Verdana" size="2">There are a lot of Windows programs whose code is
spread across multiple files. The .EXE file does not always contain all of the
code that a programmer might use. For example, by creating his own library of
procedures (usually in the form of a file with a .DLL extension) a programmer
can allow more than one of his applications to access the same code. </font><p>
<font face="Verdana" size="2">Microsoft does a similar thing with Windows.
There are many files which have code that you can access, but the three most
often named files are: </font>
<ul>
<li><font face="Verdana" size="2"><b>user32.dll</b> - controls
the visible objects that you see on the screen </font></li>
<li><font face="Verdana" size="2"><b>gdi32</b> - home of most
graphics oriented API </font></li>
<li><font face="Verdana" size="2"><b>kernel32.dll</b> - provides
access to low level operating system features </font></li>
</ul>
<p><font face="Verdana" size="2">Later, I'll bring up some of the other files
whose procedures you might want access. However, there are some key issues
which you should note before making a decision to use an API call. </font>
<ul>
<li><font face="Verdana" size="2"><b>Version Compatibility</b><br>
Microsoft has long been known to update it's files without much
fanfare - read that as without telling anyone about it until it's
already happened! And often, the updated code may not perform
exactly as did the older version. Users often find this out by
seeing unexected errors or by having their system crash and/or
lock up on them! In VB5 there were a huge number of programmer's
who got bit by this problem. </font><p>
<font face="Verdana" size="2">If you stick with the basic 3 OS
files listed above, you won't see to much of this. But the
further away you go from the main 3 files, the more likely you
are to get into code which hasn't seen the testing and
improvement cycle that the main Windows OS files have gone
through. </font></li>
<li><font face="Verdana" size="2"><b>File Size</b><br>
One of the <b>very major</b> downsides to the concept of API is
that all of this great code lives in some very big files! Worse
yet, sometimes the API you want are spread over multiple files
and you may be using only one or two procedures from enormous
files which have hundreds of procedures in them. Where this
becomes a problem is in a)load time - where it can takes several
seconds to load the procedure libraries, and b) - where you want
to distribute your application and in order to make sure that all
of the procedure libraries are on your user's machine, you have
to put all of them into the distribute files. This can add many
megabytes of files to your distribution applications. It is a
major problem for distribution of software over the net, where 5
minutes per megabyte can deter a usage from trying out an
application just because he doesn't want to wait for the
download! </font></li>
<li><font face="Verdana" size="2"><b>Documentation</b><br>
Finding the documentation of what procedures are in a library and
how to use them can be very difficult. On my PC I have 3,380
files with a .DLL extension with a total size of 539MB. That's a
lot of code! Unfortunately I can count on one hand the pages of
documentation that I have to tell me what that code is or does!
You'll learn <b>how</b> to use DLLs in this tutorial, but without
the documentation from the creator of the DLLs you cannot use
them successfully. </font></li>
</ul>
<p><font face="Verdana" size="2">Despite these problems, the powerful magic of
the API is that they are code which you don't have to write. If you've read my
Beginner's section you know that I am a big fan of using 3rd party software to
lighten my own programming load. As with 3rd party controls, the API provide
procedures which someone else wrote, debugged, and made availble for you to
benefit from. In the Windows DLLs files, there are literally thousands of
procedures. The key to API programming is learning which of these procedures
are useful and which ones you are unlikely to ever need! This tutorial tries to
address just that problem. </font><p><font face="Verdana" size="2"><b>Getting
Started</b> It's actually simpler than you might imagine. By now, you've
already written procedures for your own VB programs. Using procedures from
other files is almost exactly the same as using procedures from within your own
program. </font><p><font face="Verdana" size="2">The one big difference is that
you must tell your application which file the procedure is contained in. To do
so, you must put 1 line of code into your VB program. And, you have to do this
for every external procedure that you plan to use. I suppose it would be nice
for VB to have the ability to find the procedures for you - but you can see
that searching through the 3,380 procedures on my PC might slow my applications
down a lot! </font><p><font face="Verdana" size="2">Ok, let's get to an
example. Telling VB about the procedure you want to use is known as "declaring"
the procedure, and (no surprise) it uses a statement which starts with the word
declare. Here's what a declaration looks like: </font><p>
<pre><font face="Verdana">Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags as Long, ByVal dwReserved as Long) as Long
</font></pre>
<p><font face="Verdana" size="2">Let's take about the parts of the declaration
statement: </font>
<ul>
<li><font face="Verdana" size="2"><b>"Declare"</b><br>
This is reserved word that VB uses to begin a declaration. There
is no alternative - you have to use it. </font></li>
<li><font face="Verdana" size="2"><b>"Function"</b><br>
Also a reserved word, but in this case it distinguishes between a
SUB procedured and a FUNCTION procedure. The API use Function
procedures so that they can return a value to indicate the
results of the action. Although you can discard the returned
value, it's also possible to check the return value to determine
that the action was successfully completed. completed.
alternative - you have to use it. </font></li>
<li><font face="Verdana" size="2"><b>"ExitWindowsEx"</b><br>
Inside each DLL is a list of the procedures that it contains.
Normally, in a VB declaration statement you simply type in the
name of the procedure just as it is named in the DLL. Sometimes,
the DLL true name of the procedure may be a name that is illegal
in VB. For those cases, VB allows you to put in the text string
"Alias NewProcedurename" right behind the filename. In this
example, VB would make a call to the procedure by using the name
"NewProcedureName". </font></li>
<li><font face="Verdana" size="2"><b>"Lib 'user32'"</b><br>
Here's where you tell VB which file the procedure is in. Normally
you would put "user32.dll", showing the extension of the
procedure library. For the special case of the three Windows
system DLLs listed above, the API will recognize the files when
simply named "user32", "kernel32", and "gdi32" - without the DLL
extensions shown. In most other cases you must give the complete
file name. Unless the file is in the system PATH, you must also
give the complete path to the file. </font></li>
<li><font face="Verdana" size="2"><b>"(ByVal uFlags as Long ...)"</b><br>
Exactly like your own procedures, Windows API functions can have
a list of arguments. However, while your VB procedures often use
arguments passed by reference (i.e., their values can be
changed), most Windows API require that the arguments be passed
by value (i.e, a copy of the argument is passed to the DLL and
the originial variable cannot be changed). </font><p>
<font face="Verdana" size="2">Also, you'll note that a constant
or variable is normally used as the argument for an API call.
It's technically acceptable to simply use a number for an
argument but it is common practice among experienced programmers
to create constants (or variables) whose name is easy to remember
and then to use those in the argument list. When you're reading
or debugging your code later, the use of these easy to read
constant/variable names makes it much easier to figure out what
went wrong! </font></li>
<li><font face="Verdana" size="2"><b>"as Long"</b><br>
This is exactly like the code you use to create your own
functions. Windows API are functions which return values and you
must define what type of variable is returned. </font></li>
</ul>
<p><font face="Verdana" size="2">While I make it sound simple (and it is),
there are still issues which ought to concern you when using the Windows API.
Because the API code executes outside the VB program itself, your own program
is susceptable to error in the external procedure. If the external procedure
crashes, then your own program will crash as well. It is very common for an API
problem to freeze your system and force a reboot. </font><p>
<font face="Verdana" size="2">The biggest issue that VB programmers would see
in this case is that any unsaved code <b>will be lost!</b>. So remember the
rule when using API - save often! </font><p><font face="Verdana" size="2">
Because many of the DLLs you will use have been debugged extensively you
probably won't see many cases where the DLL crashes because of programming bug.
Far more frequently VB programmers will see a crash because they passed
arguments to the procedure which the procedure could not handle! For example,
passing a string when an integer was needed will likely crash the system. The
DLLs don't include extensive protection in order to keep their own code size
small and fast. </font><p><font face="Verdana" size="2">It is simple to say
that if you pass the correct type of argument, that you won't see API crashes.
However, the documentation is not always clear exactly what argument type is
needed, plus when writing code it is all too common to simply make a mistake!
</font><p><font face="Verdana" size="2">Finally, it is the case that most of
the DLLs you'll want to use were written in C++. The significance of this is
that the data types in C++ do not map cleanly into the data types that are used
in Visual Basic. Here are some of the issues which you need to be aware of:
</font><p>
<ul>
<li><font face="Verdana" size="2"><b>Issue1</b> </font></li>
<li><font face="Verdana" size="2"><b>Issue2</b> </font></li>
</ul>
<p><font face="Verdana" size="2">Okay, stay with me just a bit longer and we'll
get into the actual use of some API. But first, here is a list of other DLLs
which have procedures that could be of use to you. These DLLs will show up
later in this tutorial when we get to the API which I recommend that you
consider for use in your own applications. </font><p>
<ul>
<li><font face="Verdana" size="2">Advapi32.dll - Advanced API
services including many security and Registry calls </font></li>
<li><font face="Verdana" size="2">Comdlg32.dll - Common dialog
API library </font></li>
<li><font face="Verdana" size="2">Lz32.dll - 32-bit compression
routines </font></li>
<li><font face="Verdana" size="2">Mpr.dll - Multiple Provider
Router library </font></li>
<li><font face="Verdana" size="2">Netapi32.dll - 32-bit Network
API library </font></li>
<li><font face="Verdana" size="2">Shell32.dll - 32-bit Shell API
library </font></li>
<li><font face="Verdana" size="2">Version.dll - Version library
</font></li>
<li><font face="Verdana" size="2">Winmm.dll - Windows multimedia
library </font></li>
<li><font face="Verdana" size="2">Winspool.drv - Print spoolder
interface </font></li>
</ul>
<p><font face="Verdana" size="2">Often, the documentation that you might find
for an API will be written for a C++ programmer. Here's a short table which
helps you translate the C++ variable type declaration to its equivalent in
Visual Basic: </font><p><table cellSpacing="0" cellPadding="0">
<tr>
<td><font face="Verdana" size="2">ATOM </font></td>
<td><font face="Verdana" size="2">ByVal variable as Integer </font></td>
</tr>
<tr>
<td><font face="Verdana" size="2">BOOL </font></td>
<td><font face="Verdana" size="2">ByVal variable as Long </font></td>
</tr>
<tr>
<td><font face="Verdana" size="2">BYTE </font></td>
<td><font face="Verdana" size="2">ByVal variable as Byte </font></td>
</tr>
<tr>
<td><font face="Verdana" size="2">CHAR </font></td>
<td><font face="Verdana" size="2">ByVal variable as Byte </font></td>
</tr>
<tr>
<td><font face="Verdana" size="2">COLORREF </font></td>
<td><font face="Verdana" size="2">ByVal variable as Long </font></td>
</tr>
<tr>
<td><font face="Verdana" size="2">DWORD </font></td>
<td><font face="Verdana" size="2">ByVal variable as Long </font></td>
</tr>
<tr>
<td><font face="Verdana" size="2">HWND </font></td>
<td><font face="Verdana" size="2">ByVal variable as Long </font></td>
</tr>
<tr>
<td><font face="Verdana" size="2">HDC </font></td>
<td><font face="Verdana" size="2">ByVal variable as Long </font></td>
</tr>
<tr>
<td><font face="Verdana" size="2">HMENU </font></td>
<td><font face="Verdana" size="2">ByVal variable as Long </font></td>
</tr>
<tr>
<td><font face="Verdana" size="2">INT </font></td>
<td><font face="Verdana" size="2">ByVal variable as Long </font></td>
</tr>
<tr>
<td><font face="Verdana" size="2">UINT </font></td>
<td><font face="Verdana" size="2">ByVal variable as Long </font></td>
</tr>
<tr>
<td><font face="Verdana" size="2">LONG </font></td>
<td><font face="Verdana" size="2">ByVal variable as Long </font></td>
</tr>
<tr>
<td><font face="Verdana" size="2">LPARAM </font></td>
<td><font face="Verdana" size="2">ByVal variable as Long </font></td>
</tr>
<tr>
<td><font face="Verdana" size="2">LPDWORD </font></td>
<td><font face="Verdana" size="2">variable as Long </font></td>
</tr>
<tr>
<td><font face="Verdana" size="2">LPINT </font></td>
<td><font face="Verdana" size="2">variable as Long </font></td>
</tr>
<tr>
<td><font face="Verdana" size="2">LPUINT </font></td>
<td><font face="Verdana" size="2">variable as Long </font></td>
</tr>
<tr>
<td><font face="Verdana" size="2">LPRECT </font></td>
<td><font face="Verdana" size="2">variable as Type any variable of that User
Type </font></td>
</tr>
<tr>
<td><font face="Verdana" size="2">LPSTR </font></td>
<td><font face="Verdana" size="2">ByVal variable as String </font></td>
</tr>
<tr>
<td><font face="Verdana" size="2">LPCSTR </font></td>
<td><font face="Verdana" size="2">ByVal variable as String </font></td>
</tr>
<tr>
<td><font face="Verdana" size="2">LPVOID </font></td>
<td><font face="Verdana" size="2">variable As Any use ByVal when passing a
string </font></td>
</tr>
<tr>
<td><font face="Verdana" size="2">LPWORD </font></td>
<td><font face="Verdana" size="2">variable as Integer </font></td>
</tr>
<tr>
<td><font face="Verdana" size="2">LPRESULT </font></td>
<td><font face="Verdana" size="2">ByVal variable as Long </font></td>
</tr>
<tr>
<td><font face="Verdana" size="2">NULL </font></td>
<td><font face="Verdana" size="2">ByVal Nothing or ByVal 0& or vbNullString
</font></td>
</tr>
<tr>
<td><font face="Verdana" size="2">SHORT </font></td>
<td><font face="Verdana" size="2">ByVal variable as Integer </font></td>
</tr>
<tr>
<td><font face="Verdana" size="2">VOID </font></td>
<td><font face="Verdana" size="2">Sub Procecure not applicable </font></td>
</tr>
<tr>
<td><font face="Verdana" size="2">WORD </font></td>
<td><font face="Verdana" size="2">ByVal variable as Integer </font></td>
</tr>
<tr>
<td><font face="Verdana" size="2">WPARAM </font></td>
<td><font face="Verdana" size="2">ByVal variable as Long </font></td>
</tr>
</table>
<p><font face="Verdana" size="2">We're not quite ready to get into using the
API. Here is a scattering of issues/comments about using API which you will
want to be aware of: </font><p>
<ul>
<li><font face="Verdana" size="2"><b>Declare</b> </font>
<ul>
<li><font face="Verdana" size="2">DECLARE in
standard module are PUBLIC by default and be used
anywhere in your app </font></li>
<li><font face="Verdana" size="2">DECLARE in any
other module are PRIVATE to that module and MUST BE
marked PRIVATE </font></li>
<li><font face="Verdana" size="2">Procedure names
are CASE-SENSITIVE </font></li>
<li><font face="Verdana" size="2">You cannot
Declare a 16-bit API function in VB6 </font></li>
</ul>
</li>
<li><font face="Verdana" size="2"><b>ALIAS</b> </font>
<ul>
<li><font face="Verdana" size="2">Is the "real"
name of the procedure as found in the DLL </font>
</li>
<li><font face="Verdana" size="2">If the API uses
string, you MUST use ALIAS with "A" to specify the
correct character set (A=ANSI W=UNICODE) </font>
</li>
<li><font face="Verdana" size="2">WinNT supports W,
but Win95/Win98 do not </font></li>
<li><font face="Verdana" size="2">Some DLLs have
illegal VB name, so you must use ALIAS to rename
the procedure </font></li>
<li><font face="Verdana" size="2">Can also be the
ordinal number of the procedure </font></li>
</ul>
</li>
<li><font face="Verdana" size="2"><b>Variable Type</b> </font>
<ul>
<li><font face="Verdana" size="2">Very few DLLs
recognize VARIANT </font></li>
<li><font face="Verdana" size="2">ByRef is VB
default </font></li>
<li><font face="Verdana" size="2">Most DLLs expect
ByVal </font></li>
<li><font face="Verdana" size="2">In C
documentation, C passes all arguments except arrays
by value </font></li>
<li><font face="Verdana" size="2">AS ANY can be
used but it turns off all type checking </font>
</li>
</ul>
</li>
<li><font face="Verdana" size="2"><b>Strings</b> </font>
<ul>
<li><font face="Verdana" size="2">API generally
require fixed length strings </font></li>
<li><font face="Verdana" size="2">Pass string ByVal
means passing pointer to first data byte in the
string </font></li>
<li><font face="Verdana" size="2">Pass string ByRef
means passing memory address to another memory
addresss which refers to first data byte in the
string </font></li>
<li><font face="Verdana" size="2">Most DLLs expect
LPSTR (ASCIIZ) strings (end in a null character),
which point to the first data byte </font></li>
<li><font face="Verdana" size="2">VB Strings should
be passed ByVal (in general) </font></li>
<li><font face="Verdana" size="2">VB uses BSTR
strings (header + data bytes) - BSTR is passed as a
pointer to the header </font></li>
<li><font face="Verdana" size="2">DLL can modify
data in a string variable that it receives as an
argument - WARNING: if returned value is longer
than passed value, system error occurs! </font>
</li>
<li><font face="Verdana" size="2">Generally, API do
not expect string buffers longer than 255
characters </font></li>
<li><font face="Verdana" size="2">C & VB both treat
a string array as an array of pointers to string
data </font></li>
<li><font face="Verdana" size="2">Most API require
you to pass the length of the string and to fill
the string wih spaces </font></li>
</ul>
</li>
<li><font face="Verdana" size="2"><b>Arrays</b> </font>
<ul>
<li><font face="Verdana" size="2">Pass entire array
by passing the first element of the array ByRef
</font></li>
<li><font face="Verdana" size="2">Pass individual
elements of array just like any other variable
</font></li>
<li><font face="Verdana" size="2">If pass pass
binary data to DLL, use array of Byte characters
</font></li>
</ul>
</li>
<li><font face="Verdana" size="2"><b>Callback Function</b> </font>
<ul>
<li><font face="Verdana" size="2">Use AddressOf to
pass a user-defined function that the DLL procedure
can use </font></li>
<li><font face="Verdana" size="2">Must have
specific set of arguments, AS DEFINED by the API
procedure </font></li>
<li><font face="Verdana" size="2">Procedure MUST be
in a .BAS module </font></li>
<li><font face="Verdana" size="2">Passed procedure
must be As Any or As Long </font></li>
</ul>
</li>
<li><font face="Verdana" size="2"><b>Passing a null value</b>
</font>
<ul>
<li><font face="Verdana" size="2">To pass a null
value - zero-length string ("") will not work
</font></li>
<li><font face="Verdana" size="2">To pass a null
value - use vbNullString </font></li>
<li><font face="Verdana" size="2">To pass a null
value - change Type to Long and then use 0& </font>
</li>
</ul>
</li>
<li><font face="Verdana" size="2"><b>Window Handle</b> </font>
<ul>
<li><font face="Verdana" size="2">A handle is
simply a number assigned by Windows to each window
</font></li>
<li><font face="Verdana" size="2">In VB, the handle
is the same as the property hWnd </font></li>
<li><font face="Verdana" size="2">Handles are
always Long variable types </font></li>
</ul>
</li>
<li><font face="Verdana" size="2"><b>Callbacks</b> </font>
<ul>
<li><font face="Verdana" size="2">Some API can run
one of you own VB functions. Your VB function is
called a "Callback" </font></li>
<li><font face="Verdana" size="2">VB supports
callbacks with a function "AddressOf", which give
the API the location of the function to execute
</font></li>
<li><font face="Verdana" size="2">Callback
functions must be in a module. They cannot be in a
form. </font></li>
</ul>
</li>
<li><font face="Verdana" size="2"><b>Subclassing</b> </font>
<ul>
<li><font face="Verdana" size="2">All windows work
by processing messages from the Windows operating
system </font></li>
<li><font face="Verdana" size="2">You can change
how a window responds to a message by intercepting
the message </font></li>
<li><font face="Verdana" size="2">To intercept a
message, use the API SetWindowsLong </font></li>
</ul>
</li>
<li><font face="Verdana" size="2"><b>Miscellaneous</b> </font>
<ul>
<li><font face="Verdana" size="2">Control
properties MUST be passed by value (use
intermediate value to pass ByRef) </font></li>
<li><font face="Verdana" size="2">Handles - always
declare as ByVal Long </font></li>
<li><font face="Verdana" size="2">Variant - to pass
Variant to argument that is not a Variant type,
pass the Variant data ByVal </font></li>
<li><font face="Verdana" size="2">UDT - cannot be
passed except as ByRef </font></li>
</ul>
</li>
</ul>
<p><font face="Verdana" size="2"><b>Which API Should I Use?</b><br>
Finally we get to the good part. First the bad news, then the good news. In
this section I do not provide code that you can simply copy into your own
applications. The good news is that I provide a list of features that you might
want to incorporate into your own application and then tell you which of the
API to use. For the purposes of this relatively short tutorial, the best I can
do is to point you off in the right direction! </font><p>
<font face="Verdana" size="2">In case you don't know, VB6 comes with a tool to
help you use API in your own applications. The <b>API Viewer</b> is installed
automatically with VB, and to use it go to the Start/Programs/VB/Tools menu and
select "API Viewer". The viewer actions much like my own <b>VB Information
Center Code Librarian</b> in that you can browse through the various API,
select one for copying to the clipboard, and then paste the declaration into
your own application's code window. You'll definitely want to try this out. The
data file that comes with the viewer if very extensive, listing 1550 API
Declarations. </font><p><font face="Verdana" size="2">In my case I use API
regularly, but I've never come close to using 1550 API. At best, I barely have
broken the 100 mark. It seems that for the most part I can get VB to do
whatever task I want without resorting to the API. However, in some cases you
just can do any better than a few lines of API code to get the job done! So,
here's my own list of useful tasks and the API needed to perform them: </font>
<p> <p>
<table cellSpacing="0" cellPadding="0" width="712" style="border-collapse: collapse" bordercolor="#111111">
<tr>
<td vAlign="top" noWrap width="300"><font face="Verdana" size="2"><b>Play
sound</b> </font></td>
<td vAlign="top" noWrap width="712"><font face="Verdana" size="2">Declare
Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal
lpszSoundName as string, ByVal uFlags as Long) as Long <br>
Result = sndPlaySound (SoundFile, 1) </font></td>
</tr>
<tr>
<td width="300"> </td>
</tr>
<tr>
<td vAlign="top" noWrap width="300"><font face="Verdana" size="2"><b>
SubClassing</b> </font></td>
<td vAlign="top" noWrap width="712"><font face="Verdana" size="2">Declare
Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal
lpPrevWndFunc as Long, ByVal hwnd as Long, byval msg as long, byval wParam as
long, byval lParam as Long ) as long <br>
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd
As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long </font></td>
</tr>
<tr>
<td width="300"> </td>
</tr>
<tr>
<td vAlign="top" noWrap width="300"><font face="Verdana" size="2"><b>Run
associated EXE</b> </font></td>
<td vAlign="top" noWrap width="712"><font face="Verdana" size="2">Declare
Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As
Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters
As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long </font>
</td>
</tr>
<tr>
<td width="300"> </td>
</tr>
<tr>
<td vAlign="top" noWrap width="300"><font face="Verdana" size="2"><b>List
window handles</b> </font></td>
<td vAlign="top" noWrap width="712"><font face="Verdana" size="2">Declare
Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As
Long) As Long </font></td>
</tr>
<tr>
<td width="300"> </td>
</tr>
<tr>
<td vAlign="top" noWrap width="300"><font face="Verdana" size="2"><b>Find
prior instance of EXE</b> </font></td>
<td vAlign="top" noWrap width="712"><font face="Verdana" size="2">Declare
Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As
String, ByVal lpWindowName As String) As Long </font></td>
</tr>
<tr>
<td width="300"> </td>
</tr>
<tr>
<td vAlign="top" noWrap width="300"><font face="Verdana" size="2"><b>Draw
dotted rectangle</b> </font></td>
<td vAlign="top" noWrap width="712"><font face="Verdana" size="2">Declare
Function DrawFocusRect Lib "user32" Alias "DrawFocusRect" (ByVal hdc As Long,
lpRect As RECT) As Long </font></td>
</tr>
<tr>
<td width="300"> </td>
</tr>
<tr>
<td vAlign="top" noWrap width="300"><font face="Verdana" size="2"><b>Invert
colors of rectangle</b> </font></td>
<td vAlign="top" noWrap width="712"><font face="Verdana" size="2">Declare
Function InvertRect Lib "user32" Alias "InvertRect" (ByVal hdc As Long, lpRect
As RECT) As Long </font></td>
</tr>
<tr>
<td width="300"> </td>
</tr>
<tr>
<td vAlign="top" noWrap width="300"><font face="Verdana" size="2"><b>Get
cursor position</b> </font></td>
<td vAlign="top" noWrap width="712"><font face="Verdana" size="2">Declare
Function GetCursorPos Lib "user32" Alias "GetCursorPos" (lpPoint As POINTAPI)
As Long </font></td>
</tr>
<tr>
<td width="300"> </td>
</tr>
<tr>
<td vAlign="top" noWrap width="300"><font face="Verdana" size="2"><b>Always on
top</b> </font></td>
<td vAlign="top" noWrap width="712"><font face="Verdana" size="2">Declare
Function SetWindowPos Lib "user32" Alias "SetWindowPos" (ByVal hwnd As Long,
ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As
Long, ByVal cy As Long, ByVal wFlags As Long) As Long </font></td>
</tr>
<tr>
<td width="300"> </td>
</tr>
<tr>
<td vAlign="top" noWrap width="300"><font face="Verdana" size="2"><b>Send
messages to a window</b> </font></td>
<td vAlign="top" noWrap width="712"><font face="Verdana" size="2">Declare
Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long,
ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long </font></td>
</tr>
<tr>
<td width="300"> </td>
</tr>
<tr>
<td vAlign="top" noWrap width="300"><font face="Verdana" size="2"><b>Find
directories</b> </font></td>
<td vAlign="top" noWrap width="712"><font face="Verdana" size="2">Declare
Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal
lpBuffer As String, ByVal nSize As Long) As Long <br>
Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA"
(ByVal lpBuffer As String, ByVal nSize As Long) As Long <br>
Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal
nBufferLength As Long, ByVal lpBuffer As String) As Long <br>
Declare Function GetCurrentDirectory Lib "kernel32" Alias "GetCurrentDirectory"
(ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long </font></td>
</tr>
<tr>
<td width="300"> </td>
</tr>
<tr>
<td vAlign="top" noWrap width="300"><font face="Verdana" size="2"><b>Text
alignment</b> </font></td>
<td vAlign="top" noWrap width="712"><font face="Verdana" size="2">Declare
Function GetTextAlign Lib "gdi32" Alias "GetTextAlign" (ByVal hdc As Long) As
Long <br>
Declare Function SetTextAlign Lib "gdi32" Alias "SetTextAlign" (ByVal hdc As
Long, ByVal wFlags As Long) As Long </font></td>
</tr>
<tr>
<td width="300"> </td>
</tr>
<tr>
<td vAlign="top" noWrap width="300"><font face="Verdana" size="2"><b>Flash a
title bar</b> </font></td>
<td vAlign="top" noWrap width="712"><font face="Verdana" size="2">Declare
Function FlashWindow Lib "user32" Alias "FlashWindow" (ByVal hwnd As Long,
ByVal bInvert As Long) As Long </font></td>
</tr>
<tr>
<td width="300"> </td>
</tr>
<tr>
<td vAlign="top" noWrap width="300"><font face="Verdana" size="2"><b>
Manipulate bitmaps</b> </font></td>
<td vAlign="top" noWrap width="712"><font face="Verdana" size="2">Declare
Function BitBlt Lib "gdi32" Alias "BitBlt" (ByVal hDestDC As Long, ByVal x As
Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal
hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long)
As Long <br>
Declare Function PatBlt Lib "gdi32" Alias "PatBlt" (ByVal hdc As Long, ByVal x
As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal
dwRop As Long) As Long <br>
Declare Function StretchBlt Lib "gdi32" Alias "StretchBlt" (ByVal hdc As Long,
ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long,
ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth
As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long <br>
Declare Function CreateCompatibleBitmap Lib "gdi32" Alias "CreateCompatibleBitmap"
(ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long <br>
Declare Function CreateCompatibleDC Lib "gdi32" Alias "CreateCompatibleDC" (ByVal
hdc As Long) As Long </font></td>
</tr>
<tr>
<td width="300"> </td>
</tr>
<tr>
<td vAlign="top" noWrap width="300"><font face="Verdana" size="2"><b>Rotate
text</b> </font></td>
<td vAlign="top" noWrap width="712"><font face="Verdana" size="2">Declare
Function CreateFontIndirect Lib "gdi32" Alias "CreateFontIndirectA" (lpLogFont
As LOGFONT) As Long </font></td>
</tr>
<tr>
<td width="300"> </td>
</tr>
<tr>
<td vAlign="top" noWrap width="300"><font face="Verdana" size="2"><b>Timing</b>
</font></td>
<td vAlign="top" noWrap width="712"><font face="Verdana" size="2">Declare
Function GetTickCount Lib "kernel32" Alias "GetTickCount" () As Long </font>
</td>
</tr>
<tr>
<td width="300"> </td>
</tr>
<tr>
<td vAlign="top" noWrap width="300"><font face="Verdana" size="2"><b>File
information</b> </font></td>
<td vAlign="top" noWrap width="712"><font face="Verdana" size="2">Declare
Function GetFileAttributes Lib "kernel32" Alias "GetFileAttributesA" (ByVal
lpFileName As String) As Long <br>
Declare Function GetFileSize Lib "kernel32" Alias "GetFileSize" (ByVal hFile
As Long, lpFileSizeHigh As Long) As Long <br>
Declare Function GetFullPathName Lib "kernel32" Alias "GetFullPathNameA" (ByVal
lpFileName As String, ByVal nBufferLength As Long, ByVal lpBuffer As String,
ByVal lpFilePart As String) As Long </font></td>
</tr>
<tr>
<td width="300"> </td>
</tr>
<tr>
<td vAlign="top" noWrap width="300"><font face="Verdana" size="2"><b>Get
window information</b> </font></td>
<td vAlign="top" noWrap width="712"><font face="Verdana" size="2">Declare
Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long,
ByVal lpClassName As String, ByVal nMaxCount As Long) As Long <br>
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd
As Long, ByVal lpString As String, ByVal cch As Long) As Long <br>
Declare Function GetParent Lib "user32" Alias "GetParent" (ByVal hwnd As Long)
As Long </font></td>
</tr>
<tr>
<td width="300"> </td>
</tr>
<tr>
<td vAlign="top" noWrap width="300"><font face="Verdana" size="2"><b>Identify
window at cursor</b> </font></td>
<td vAlign="top" noWrap width="712"><font face="Verdana" size="2">Declare
Function WindowFromPoint Lib "user32" Alias "WindowFromPoint" (ByVal xPoint As
Long, ByVal yPoint As Long) As Long </font></td>
</tr>
<tr>
<td width="300"> </td>
</tr>
<tr>
<td vAlign="top" noWrap width="300"><font face="Verdana" size="2"><b>Registry
editing</b> </font></td>
<td vAlign="top" noWrap width="712"><font face="Verdana" size="2">Declare
Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As
Long, ByVal lpSubKey As String, phkResult As Long) As Long <br>
Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal
hKey As Long, ByVal lpSubKey As String) As Long <br>
Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal
hKey As Long, ByVal lpValueName As String) As Long <br>
Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal
hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As
Long, lpData As Any, lpcbData As Long) As Long <br>
Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal
hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal
dwType As Long, lpData As Any, ByVal cbData As Long) As Long </font></td>
</tr>
<tr>
<td width="300"> </td>
</tr>
<tr>
<td vAlign="top" noWrap width="300"><font face="Verdana" size="2"><b>Drawing
functions</b> </font></td>
<td vAlign="top" noWrap width="712"><font face="Verdana" size="2">Declare
Function MoveToEx Lib "gdi32" Alias "MoveToEx" (ByVal hdc As Long, ByVal x As
Long, ByVal y As Long, lpPoint As POINTAPI) As Long <br>
Declare Function LineTo Lib "gdi32" Alias "LineTo" (ByVal hdc As Long, ByVal x
As Long, ByVal y As Long) As Long <br>
Declare Function Ellipse Lib "gdi32" Alias "Ellipse" (ByVal hdc As Long, ByVal
X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
</font></td>
</tr>
<tr>
<td width="300"> </td>
</tr>
<tr>
<td vAlign="top" noWrap width="300"><font face="Verdana" size="2"><b>Get icon
Declare</b> </font></td>
<td vAlign="top" noWrap width="712"><font face="Verdana" size="2">Function
ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (ByVal hInst As Long, ByVal
lpszExeFileName As String, ByVal nIconIndex As Long) As Long </font></td>
</tr>
<tr>
<td width="300"> </td>
</tr>
<tr>
<td vAlign="top" noWrap width="300"><font face="Verdana" size="2"><b>Screen
capture</b> </font></td>
<td vAlign="top" noWrap width="712"><font face="Verdana" size="2">Declare
Function SetCapture Lib "user32" Alias "SetCapture" (ByVal hwnd As Long) As
Long <br>
Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" (ByVal lpDriverName As
String, ByVal lpDeviceName As String, ByVal lpOutput As String, lpInitData As
DEVMODE) As Long <br>
Declare Function DeleteDC Lib "gdi32" Alias "DeleteDC" (ByVal hdc As Long) As
Long <br>
Declare Function BitBlt Lib "gdi32" Alias "BitBlt" (ByVal hDestDC As Long,
ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long,
ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As
Long) As Long <br>
Declare Function ReleaseCapture Lib "user32" Alias "ReleaseCapture" () As Long
<br>
Declare Function ClientToScreen Lib "user32" Alias "ClientToScreen" (ByVal
hwnd As Long, lpPoint As POINTAPI) As Long </font></td>
</tr>
<tr>
<td width="300"> </td>
</tr>
<tr>
<td vAlign="top" noWrap width="300"><font face="Verdana" size="2"><b>Get user
name</b> </font></td>
<td vAlign="top" noWrap width="712"><font face="Verdana" size="2">Declare
Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer
As String, nSize As Long) As LongDeclare Function GetUserName Lib
"advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long)
As Long </font></td>
</tr>
<tr>
<td width="300"> </td>
</tr>
<tr>
<td vAlign="top" noWrap width="300"><font face="Verdana" size="2"><b>Get
computer name</b> </font></td>
<td vAlign="top" noWrap width="712"><font face="Verdana" size="2">Declare
Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal
lpBuffer As String, nSize As Long) As LongDeclare Function GetComputerName Lib
"kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long)
As Long </font></td>
</tr>
<tr>
<td width="300"> </td>
</tr>
<tr>
<td vAlign="top" noWrap width="300"><font face="Verdana" size="2"><b>Get
volume name/serial#</b> </font></td>
<td vAlign="top" noWrap width="712"><font face="Verdana" size="2">Declare
Function GetVolumeInformation Lib "kernel32" Alias "GetVolumeInformationA" (ByVal
lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal
nVolumeNameSize As Long, lpVolumeSerialNumber As Long,
lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal
lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long
</font></td>
</tr>
<tr>
<td width="300"> </td>
</tr>
<tr>
<td vAlign="top" noWrap width="300"><font face="Verdana" size="2"><b>Identify
drive type</b> </font></td>
<td vAlign="top" noWrap width="712"><font face="Verdana" size="2">Declare
Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As
String) As Long </font></td>
</tr>
<tr>
<td width="300"> </td>
</tr>
<tr>
<td vAlign="top" noWrap width="300"><font face="Verdana" size="2"><b>Get free
space</b> </font></td>
<td vAlign="top" noWrap width="712"><font face="Verdana" size="2">Declare
Function GetDiskFreeSpace Lib "kernel32" Alias "GetDiskFreeSpaceA" (ByVal
lpRootPathName As String, lpSectorsPerCluster As Long, lpBytesPerSector As
Long, lpNumberOfFreeClusters As Long, lpTotalNumberOfClusters As Long) As Long
</font></td>
</tr>
<tr>
<td width="300"> </td>
</tr>
<tr>
<td vAlign="top" noWrap width="300"><font face="Verdana" size="2"><b>INI
editing</b> </font></td>
<td vAlign="top" noWrap width="712"><font face="Verdana" size="2">Declare
Function WritePrivateProfileSection Lib "kernel32" Alias "WritePrivateProfileSectionA"
(ByVal lpAppName As String, ByVal lpString As String, ByVal lpFileName As
String) As Long <br>
Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA"
(ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As
Any, ByVal lpFileName As String) As Long <br>
Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA"
(ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault
As Long, ByVal lpFileName As String) As Long <br>
Declare Function GetPrivateProfileSection Lib "kernel32" Alias "GetPrivateProfileSectionA"
(ByVal lpAppName As String, ByVal lpReturnedString As String, ByVal nSize As
Long, ByVal lpFileName As String) As Long <br>
Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA"
(ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As
String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal
lpFileName As String) As Long </font></td>
</tr>
<tr>
<td width="300"> </td>
</tr>
<tr>
<td vAlign="top" noWrap width="300"><font face="Verdana" size="2"><b>Put icon
in system tray</b> </font></td>
<td vAlign="top" noWrap width="712"><font face="Verdana" size="2">Declare
Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal
lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As
Long, ByVal lParam As Long) As Long <br>
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd
As Long, ByVal nIndex As Long) As Long <br>
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd
As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long <br>
Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias " Shell_NotifyIconA"
(ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long <br>
Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As
Any, Source As Any, ByVal Length As Long) <br>
Declare Function DrawEdge Lib "user32" Alias "DrawEdge" (ByVal hdc As Long,
qrc As RECT, ByVal edge As Long, ByVal grfFlags As Long) As Long </font></td>
</tr>
<tr>
<td width="300"> </td>
</tr>
<tr>
<td vAlign="top" noWrap width="300"><font face="Verdana" size="2"><b>Wait for
program to stop</b> </font></td>
<td vAlign="top" noWrap width="712"><font face="Verdana" size="2">Declare
Function CreateProcess Lib "kernel32" Alias "CreateProcessA" (ByVal
lpApplicationName As String, ByVal lpCommandLine As String,
lpProcessAttributes As SECURITY_ATTRIBUTES, lpThreadAttributes As
SECURITY_ATTRIBUTES, ByVal bInheritHandles As Long, ByVal dwCreationFlags As
Long, lpEnvironment As Any, ByVal lpCurrentDriectory As String, lpStartupInfo
As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long <br>
Declare Function WaitForSingleObject Lib "kernel32" Alias "WaitForSingleObject"
(ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long </font></td>
</tr>
<tr>
<td width="300"> </td>
</tr>
<tr>
<td vAlign="top" noWrap width="300"><font face="Verdana" size="2"><b>Stop
ctrl-alt-del</b> </font></td>
<td vAlign="top" noWrap width="712"><font face="Verdana" size="2">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 </font></td>
</tr>
</table>
<p><font face="Verdana" size="2">Hopefully, this section of the tutorial has
sparked some excitement! You should now see that a door of tremendous
proportions has been opened to you. You've begun to leave the limitations of VB
behind and joined the rest of the programming community who have already been
using the API for years. I hope to add quite a bit to this tutorial section so
check back often over the next few weeks.</font></td>
</tr>
</table>