Calling WIN32 API Functions
Regardless of which development environment you use, if you're programming for Windows you need a thorough grasp of the Win32 API. You can call any 32-bit Windows API function from VJ++, but determining the best way to make those API calls can be tricky. WFC makes certain function calls unnecessary, so you need to become familiar with WFC. Other functions are predefined in wrapper classes such as User32, Kernel32, and Gdi32 that are found in the package (In the Java world, a "package" is a code module that contains some portion of the Java runtime library.) These wrapper classes correspond to the Windows DLLs that contain the API functions. If the desired function isn't prewrapped, Microsoft's J/Direct technology permits calling virtually any DLL-based function from a VJ++ program.

When you want to call an API function in a VJ++ program, the first step is to determine which of the Windows DLLs contains it. Next examine the corresponding object in to see whether that function is present. For example, MenuZap calls ExitWindowsEx() to log the user out of Windows. ExitWindowsEx() is defined in User32.dll, and it does exist as a member of the User32 class. The call looks like this:

User32.ExitWindowsEx(win.EWX_LOGOFF, 0);

Note that the EWX_LOGOFF constant is defined as a static member of the win class, the repository for numeric constants used in Win32. Defining constants as static members of the class in which they're used (or of a related class) is standard practice in Java programming.

Calling an API function directly isn't always the best course of action. To define its nonrectangular window, MenuZap could have called Gdi32.CreatePolygonRgn() and User32.SetWindowRgn(). Instead, it uses the createPolygonal() constructor of the WFC Region class to define the region, and calls the setRegion() method of the form itself to restrict the viewable area to the specified region. These class methods are more straightforward to use, and are more likely to be included if WFC is ported to a graphical environment other than Windows.