VIEWING THE POSSIBLE API CALLS

You can view API calls immediately in a couple of ways. One way is by using the API Viewer that comes with Microsoft Office Developer. The other is to copy the example in the text file called Win32api.txt.

Using the API Viewer to Locate Calls

A good source for API calls is the API Viewer that comes with Microsoft Office Developer. The API Viewer that comes with the MOD is useful for getting an idea of the available API calls. To use the API Viewer, follow these steps:

1.
From the Start menu, choose Programs, Microsoft Office Developer, and finally API Viewer. A blank viewer appears.

2.
From the File menu choose Load Text File. The Select a Text API File dialog appears.

3.
Select Win32api.txt and click Open.

The Available Items list box then is populated with API call names (see Figure 15.1).

Figure 15.1. The API Viewer not only displays the API calls available, but it also lets you copy and paste them into your application.


Tip

You might have noticed the Load Text File command on the File menu. This text file is the same one available on this book's CD-ROM. It's faster to use the database method through the API Viewer, however.


The API Type drop-down list allows you to choose from Constants, Declares, and Types. Constants and Types are actually used with the arguments used in declarations.

Cutting and Pasting Calls from the API Viewer

To copy and paste calls from the API Viewer, follow these steps:

1.
Click the Available Items list box.

2.
Type GetSystemDirectory. The list box scrolls through the API calls to the API name you typed.

3.
Click Add. GetSystemDirectory shows up in the Selected Items list box.

4.
Click the Available Items list box again and type GetWindowsDirectory.

5.
Click the Add button again. You see the GetWindowsDirectory API call in the Selected Items list box, under GetSystemDirectory.

6.
Click the Copy button. A message appears under the Selected Items text box, saying the items were copied to the Clipboard (see Figure 15.2).

Figure 15.2. Two entries have been copied to the Clipboard.


Now you need to load Access and pull the declarations into the actual module where they're needed. To do so, open Access and then follow these steps:

1.
Open the Chap15.mdb database, in the ExamplesChap15 folder on the CD-ROM accompanying this book.

2.
Open the module called modWindowsAPIRoutines.

3.
Go to the Declarations section and choose Paste from the Edit menu.

The full declarations should be pasted in the module. It saves a lot of hassle not having to remember the correct syntax. You can see the full declarations that were copied, as follows:

Declare Function GetSystemDirectory Lib "kernel32" Alias _
   "GetSystemDirectoryA" (ByVal lpBuffer As String, _
   ByVal nSize As Long) As Long
Declare Function GetWindowsDirectory Lib "kernel32" Alias _
   "GetWindowsDirectoryA" (ByVal lpBuffer As String, _
   ByVal nSize As Long) As Long

Now all you need to do is place wu_ on the front of the name of the declarations. They would then look like this:

Declare Function wu_GetSystemDirectory Lib "kernel32" Alias _
   "GetSystemDirectoryA" (ByVal lpBuffer As String, _
   ByVal nSize As Long) As Long
Declare Function wu_GetWindowsDirectory Lib "kernel32" Alias _
   "GetWindowsDirectoryA" (ByVal lpBuffer As String, _
   ByVal nSize As Long) As Long

You'll look at these two declarations again later in the section “Looking at Some Examples of API Calls,” where they're used in actual calls to display the Windows main folder and system folder.

Finding API Calls in the Win32api.txt File

You can lookat API calls in another way, by using the Win32api.txt available with the ODE and on the CD-ROM accompanying this book. From Explorer, access the ExamplesChap15 folder on the CD. Then double-click the Win32api.txt file. It will then appear in Notepad or WordPad, depending on how much memory you have available.

In addition to the disclaimer about it being royalty-free and unsupported, notice that the name of the file is Win32 API Declarations for Visual Basic. This is what I meant when I said earlier that these declarations are literally identical in the two products, VB and Access.

As you page down through the file, notice the constants, user-defined type declarations, and the API declarations themselves.

Note

Paging through the Win32api.txt file is a great way to learn the groupings of the API calls. For example, find the word WNet by choosing Find from the Edit menu, and then typing WNet. Now click Find Next. If you scroll down, notice that all the networking routines are grouped together (see Figure 15.3).

Figure 15.3. These network routines are a good example of how API calls are grouped in the Win32api.txt file.



To use the declarations given in the Win32api.txt file, simply copy and paste as you would with any other text into the Declarations section of an Access module.

Another great feature is being able to grab the type declarations right out of this file. The type declaration shown in Figure 15.4, WNDCLASS, is used in the API call declaration that follows it.

Figure 15.4. Rather than enter the user-defined types needed by some API calls, just copy and paste.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.134.99.90