How can Java get handle windows? And how, knowing the handle, can I close this window?

  • one
    It seems to me in this situation that the question is not more “not like" but "why" - jmu

1 answer 1

Naryl is such a method using JNA:

User32 user32 = (User32) Native.loadLibrary("user32", User32.class); HWND foregroundHWND = user32.GetForegroundWindow(); user32.INSTANCE.PostMessage(foregroundHWND, User32.WM_CLOSE, new WinDef.WPARAM(), new WinDef.LPARAM());