import org.eclipse.swt.internal.Callback; import org.eclipse.swt.internal.win32.MSG; import org.eclipse.swt.internal.win32.OS; import org.eclipse.swt.internal.win32.PAINTSTRUCT; import org.eclipse.swt.internal.win32.RECT; import org.eclipse.swt.internal.win32.TCHAR; import org.eclipse.swt.internal.win32.WNDCLASS; public class Hello { public static int WndProc(int hWnd, int uMsg, int wParam, int lParam) { int hdc; PAINTSTRUCT lpPaint = new PAINTSTRUCT(); String strMessage = "Hello, Win32 GUI(SWT) World!"; switch (uMsg) { case OS.WM_PAINT: RECT rect = new RECT(); hdc = OS.BeginPaint(hWnd, lpPaint); OS.GetClientRect(hWnd, rect); OS.DrawTextW(hdc, strMessage.toCharArray(), strMessage.length(), rect, OS.DT_SINGLELINE); OS.EndPaint(hWnd, lpPaint); return 0; case OS.WM_DESTROY: System.exit(wParam); default: return OS.DefWindowProc(hWnd, uMsg, wParam, lParam); } } public static void WinMain(String[] args) { int hInstance = OS.GetModuleHandle(null); TCHAR className = new TCHAR(0, "helloWindow", true); TCHAR windowName = new TCHAR(0, "Hello, World", true); WNDCLASS wc = new WNDCLASS(); wc.style = OS.CS_HREDRAW | OS.CS_VREDRAW; wc.lpfnWndProc = new Callback(Hello.class, "WndProc", 4).getAddress(); wc.hInstance = hInstance; wc.hCursor = OS.LoadCursor(0, OS.IDC_ARROW); wc.hbrBackground = OS.GetStockObject(OS.COLOR_WINDOW + 1 ); wc.lpszClassName = OS.HeapAlloc(OS.GetProcessHeap(), OS.HEAP_ZERO_MEMORY, className.length() * 2); OS.MoveMemory(wc.lpszClassName, className, className.length() * 2); OS.RegisterClass(wc); int hWnd = OS.CreateWindowEx( 0, className, windowName, OS.WS_OVERLAPPEDWINDOW, OS.CW_USEDEFAULT, OS.CW_USEDEFAULT, 640, 480, 0, 0, hInstance, null); OS.ShowWindow(hWnd, OS.SW_SHOW); OS.UpdateWindow(hWnd); MSG lpMsg = new MSG(); while (OS.GetMessage(lpMsg, 0, 0, 0)) { OS.TranslateMessage(lpMsg); OS.DispatchMessage(lpMsg); } } public static void main(String[] args) { WinMain( args ); } }