Since the first time use JNA on the Windows OS, met with some headaches.I will create a window, but — oracle-tech

    Forum Stats

  • 3,702,035 Users
  • 2,239,551 Discussions
  • 7,835,727 Comments

Discussions

Since the first time use JNA on the Windows OS, met with some headaches.I will create a window, but

Part of the code is as follows:

public Win32WindowDemo() {

  // define new window class

  WString windowClass = new WString("MyWindowClass");

  HMODULE hInst = Kernel32.INSTANCE.GetModuleHandle("");

  WNDCLASSEX wClass = new WNDCLASSEX();

  wClass.hInstance = hInst;

  wClass.lpfnWndProc = Win32WindowDemo.this;

  wClass.lpszClassName = windowClass;

  // register window class

  User32.INSTANCE.RegisterClassEx(wClass);

  getLastError();

  // create new window

  HWND hWnd = User32.INSTANCE

  .CreateWindowEx(

  User32.WS_EX_TRANSPARENT,

  windowClass,

  "My hidden helper window, used only to catch the windows events",

  0, 50, 50, 100, 100, null, // WM_DEVICECHANGE

  // contradicts

  // parent=WinUser.HWND_MESSAGE

  new HMENU(), hInst, null);

  getLastError();

  System.out.println("window sucessfully created! window hwnd: "

  + hWnd.getPointer().toString());

  getLastError();

  User32.INSTANCE.ShowWindow(hWnd, User32.INSTANCE.SW_SHOW);

  User32.INSTANCE.UpdateWindow(hWnd);

  MSG msg = new MSG();

  while (User32.INSTANCE.GetMessage(msg, hWnd, 0, 0) != 0) {

  User32.INSTANCE.TranslateMessage(msg);

  User32.INSTANCE.DispatchMessage(msg);

  }

  User32.INSTANCE.UnregisterClass(windowClass, hInst);

  User32.INSTANCE.DestroyWindow(hWnd);

  System.out.println("program exit!");

  }

public LRESULT callback(HWND hwnd, int uMsg, WPARAM wParam, LPARAM lParam) {

  switch (uMsg) {

  case WinUser.WM_CREATE: {

  onCreate(wParam, lParam);

  return new LRESULT(0);

  }

  case WinUser.WM_DESTROY: {

  User32.INSTANCE.PostQuitMessage(0);

  return new LRESULT(0);

  }

  case WinUser.WM_SESSION_CHANGE: {

  this.onSessionChange(wParam, lParam);

  return new LRESULT(0);

  }

  case WinUser.WM_DEVICECHANGE: {

  LRESULT lResult = this.onDeviceChange(wParam, lParam);

  return lResult != null ? lResult : User32.INSTANCE.DefWindowProc(

  hwnd, uMsg, wParam, lParam);

  }

  default:

  return User32.INSTANCE.DefWindowProc(hwnd, uMsg, wParam, lParam);

  }

  }

This discussion has been closed.