Welcome to my Windows 95 API Guide! This guide is my attempt to help other programmers learn about how to use the Windows API to add a lot of functionality to their programs. Of course, although this guide specializes in Windows 95, almost everything here applies to Windows 98 and Windows NT, as well as Win32s. Likewise, although this guide uses examples and declarations written in Visual Basic, the API can be used by any Windows-based applications. See your own language's help for details on converting the code.
If you are completely new to the concept of the API, please take a few minutes and read the rest of this page. If you would just instead like to brush up on the vocabulary used throughout this guide, you can skip down to the vocabulary section. Or, if you think you know what you are doing, you should jump down to the example entry to learn how this guide is laid out.
And as always, if you have a question, clarification, correction, or want something added to this page or anything else in this guide, don't hesitate to e-mail me at Borg953@aol.com. If I can, I'll try to help you out.
The API saves the programmer incredible amounts of time and effort. Think about it. Say you want to create a window that lets the user select a file to open. You could create a window, add list boxes and combo boxes and buttons on it, fill them with the file and directory structure on the disk drive, add a pop-up window telling the user that the file doesn't exist, and so on. That could take days, even weeks! But have you noticed that the Open File dialog boxes in 99% of Windows programs are indentical? That's because the API provides a function, GetOpenFileName, that does all of this for you! You just tell it what kind of files you want, a little more information, and that's it! It saves time, not to mention program size!
Using the API is simple. Usually the most you need to do is to add a declaration of the function to your program. This just tells the programming language that you want to use that API function. You might also have to define any special data types or constants that it uses. (Your programming language may pre-declare these API functions for you automatically. See your documentation for details.) Then, you use the API function just like any other function in your program! It's incredibly easy.
The Windows API consists of hundreds of functions ranging from almost every possible topic. No one could possibly remember everything! Also, you need to use the correct syntax when you use the functions so Windows knows what you're talking about. This guide explains many of these functions in plain English, shows you what the various pieces of information you have to tell it are, and even shows you an example of how it is used. Armed with this information, you should be able to utilize the API for your own programs.
The following is a list of the terms that will be used throughout the API. Some sections honestly won't make sense if you don't know what the terms mean. I'm not just making these up. These terms are used whenever you talk about the API.
The following is an example of an entry in this guide. Superscript numbers refer to notes on the format that follow the example. Information about a function is shown here, but the entries for data types and constants are very similar.
-- begin example --
Declare Function GetWindowRect Lib "user32.dll" (ByVal hwnd As Long, lpRect As RECT3) As Long2
GetWindowRect reads the size and position of a window. This information is put into the variable passed as lpRect. The rectangle receives the coordinates of the upper-left and lower-right corners of the window. If the window is past one of the edges of the screen, the values will reflect that (for example, if the left edge of a window is off the screen, the rectangle's .Left property will be negative). The function returns 0 if an error occured, or a non-zero value if successful.4
Example:6
' Find the width and height of Form1
Dim r As RECT
x = GetWindowRect(Form1.hWnd, r)
Debug.Print "Width ="; r.Right - r.Left
Debug.Print "Height ="; r.Bottom - r.Top
Related Call: SetWindowPos7
Category: Windows8
Back to the index.9
-- end example --
The sections on data types and constants have an almost identical format, except there is no example and the Related Calls and Category entries are replaced by Used by, which lists any functions and data types that use it.