home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 39 / IOPROG_39.ISO / SOFT / sdkjava40.exe / data1.cab / fg_Samples / Samples / JDirect / automode / AutoMode.java next >
Encoding:
Java Source  |  2000-05-04  |  2.1 KB  |  69 lines

  1. /* (C) Copyright 1995 - 1999 Microsoft Corporation.  All rights reserved.
  2.  *
  3.  * This example shows how to use the "auto" keyword for calling Win32 system
  4.  * apis. The "auto" keyword instructs the VM to use the GetVersion()
  5.  * api to determine whether the Ansi MessageBox (MessageBoxA) or the
  6.  * Unicode MessageBox (MessageBoxW) is to be called.
  7.  *
  8.  * If the running platform is Windows 95, the ansi api is called.
  9.  * If the running platform is Windows NT, the unicode api is called.
  10.  *
  11.  * This algorithm can also be overridden by setting the registry key
  12.  *  
  13.  *    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Java VM\DllImportDefaultType
  14.  *
  15.  * to one of the following DWORD values:
  16.  *
  17.  *    2:        select Ansi
  18.  *    3:        select Unicode
  19.  *    4:        perform the check as described above
  20.  *
  21.  * This key is normally set only by the installation program.
  22.  *
  23.  * In addition, this sample shows how to learn programmatically whether
  24.  * the "auto" mode will choose Ansi or Unicode. All it does is query
  25.  * the com.ms.dll.DllLib.systemDefaultCharSize field.
  26.  */
  27.  
  28.  
  29.  
  30. import com.ms.dll.*;
  31.  
  32. public class AutoMode
  33. {
  34.     public static void main(String args[])
  35.     {
  36.         int charsize = DllLib.systemDefaultCharSize;
  37.         String message;
  38.         switch (charsize) {
  39.             case 1:
  40.                 message = "The \"auto\" keyword will select ANSI.";
  41.                 break;
  42.             case 2:
  43.                 message = "The \"auto\" keyword will select UNICODE.";
  44.                 break;
  45.  
  46.             default:
  47.                 System.err.println("DllLib.systemDefaultCharSize set to illegal value (" + charsize + ")");
  48.                 return;
  49.         }
  50.  
  51.         try {
  52.  
  53.             MessageBox(0, message, "ShowAutoMode", 0);
  54.  
  55.         } catch (UnsatisfiedLinkError ule) {
  56.             System.err.println("Caught exception: " + ule);
  57.             System.err.println("Probably wrong version of Java compiler.");
  58.         }
  59.     }
  60.  
  61.     /** @dll.import("USER32", auto) */
  62.     static native int
  63.     MessageBox(int hwndOwner, String text, String title, int style);
  64.  
  65.  
  66. }
  67.  
  68.  
  69.