Archive for 1月 6th, 2013

  1. Hello, Win32 API(SWT) World!

    Posted on 1月 6th, 2013 by cx20

    Win32 API(SWT)

    Win32 API は、Windows の機能にアクセスする為の API(Application Programming Interface)である。
    以下は Java の GUI ツールキット SWT の非公開 API を使用した Win32 API 呼出しの例となっている。

    ソースコード

    import org.eclipse.swt.internal.win32.OS;
    import org.eclipse.swt.internal.win32.TCHAR;
     
    public class Hello {
        public static void main(String[] args) {
            TCHAR lpText = new TCHAR(0, "Hello, Win32 API World!", true);
            TCHAR lpCaption = new TCHAR(0, "Hello, World", true);
            OS.MessageBox(0, lpText, lpCaption, OS.MB_OK );
        }
    }

    コンパイル&実行方法

    C:¥> javac -cp org.eclipse.swt.win32.win32.x86_3.6.1.v3655c.jar;. Hello.java
    C:¥> java -cp org.eclipse.swt.win32.win32.x86_3.6.1.v3655c.jar;. Hello

    実行結果

    ---------------------------
    Hello, World!
    ---------------------------
    Hello, Win32 API World!
    ---------------------------
    OK   
    ---------------------------