Com.ms.win32 Bag

Source: Internet
Author: User
Tags constant win32

The Win32 API is quite large--it contains thousands of functions, constants, and data types. Of course, we don't want to write each WIN32 API function as a corresponding Java form. With this in mind, Microsoft has released a Java package that maps the WIN32 API to Java classes via J/direct. The name of the bag is called Com.ms.win32. When installing Java SDK 2.0, the package will be installed into our classpath if the appropriate settings are set in the installation options. This package consists of a large number of Java classes that fully reproduce the constants, data types, and functions of the Win32 API. The three categories with the greatest capacity for containment are user32.class,kernel.class and gdi32.class. They contain the core content of the Win32 API. To use them, simply import them in your Java code. The previous Showmsgbox example can be com.ms.win32 rewritten as follows (this also takes into account the use of unsatisfiedlinkerror in a more appropriate way):

Import com.ms.win32.*;

public class Usewin32package {public
  static void Main (String args[]) {
    try {
      user32.messagebeep (
        winm). mb_iconexclamation);
      User32.messagebox (0,
        "Created by the MessageBox () Win32 func",
        "thinking in Java",
        winm. Mb_okcancel |
        Winm. mb_iconexclamation);
    } catch (Unsatisfiedlinkerror e) {
      System.out.println ("Can ' t link Win32 API");
      System.out.println (e);
    }
  }

The Java package was imported on the first line. You can now invoke the MessageBeep () and MessageBox () functions without making other declarations. In MessageBeep (), we can see that the WIN32 constant is also declared when the package is imported. These constants are defined in a large number of Java interfaces, all named Winx (x represents the first letter of the constant to be used).
When writing this book, the development of the COM.MS.WIN32 package has not yet been formally completed, but it can be used.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.