Search code examples
javaswingwinapijna

Parent Window Slows down a lot on using SetParent through JNA Java


I am trying to Embed a Game Window inside Java JFrame using SetParent. I am using the following kind of Code using Java JNA User32 library.

SetParent(GameWin,JFrameWin);
SetWindowPosF(GameWin,null,Game_X_pos ,Game_Y_pos+1,0,0,0x0020 | 0x0001 | 0x0008);

The above code is working fine and my game window is becoming a part of the JFrame successfully. But the controls kept in my JFrame like Drop down list and Buttons heavily slow down after doing this process.

  • Whenever I am clicking any button or dropdown list in my JFrame, it is responding after a lot of time something like after 1 or 2 minutes.

  • If I don't Embed my game window inside JFrame then everything works fine as usual.


Solution

  • When you make a window from one process be parented by a window of another process you are attaching the message queues of those windows.

    The game window likely has a message loop that is quite different from a normal GUI app. Almost certainly this game is not very interested in dispatching your window's queued messages in a timely fashion. The game did not expect to be hijacked in this way.

    There's probably not much that you can do to ameliorate this situation. Cross process parenting is something that basically should not be done. More reading on the subject here: http://blogs.msdn.com/b/oldnewthing/archive/2013/04/12/10410454.aspx