Skip to content

Commit

Permalink
Add BringWindowToTop to User32
Browse files Browse the repository at this point in the history
  • Loading branch information
kahgoh committed Jun 5, 2021
1 parent b7b48c9 commit 935504c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Features
* [#1337](https://github.com/java-native-access/jna/pull/1337): Add `REG_NOTIFY_THREAD_AGNOSTIC` to `c.s.j.p.win32.WinNet` and update `REG_LEGAL_CHANGE_FILTER` - [@Dani-Hub](https://github.com/Dani-Hub).
* [#1338](https://github.com/java-native-access/jna/pull/1338): Add `RegNotifyChangeKeyValue` to `c.s.j.p.win32.Advapi32` - [@Dani-Hub](https://github.com/Dani-Hub).
* [#1340](https://github.com/java-native-access/jna/issues/1340): Added `CM_Get_DevNode_Registry_Property` to `c.s.j.p.win32.Cfgmgr32` and corresponding util in `c.s.j.p.win32.Cfgmgr32Util` - [@dbwiddis](https://github.com/dbwiddis).
* [#1352](https://github.com/java-native-access/jna/pull/1352): Add `BringWindowToTop` to `c.s.j.p.win32.User32` - [@kahgoh](https://github.com/kahgoh)

Bug Fixes
---------
Expand Down
12 changes: 12 additions & 0 deletions contrib/platform/src/com/sun/jna/platform/win32/User32.java
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,18 @@ public interface User32 extends StdCallLibrary, WinUser, WinNT {
*/
boolean EnumThreadWindows(int dwThreadId, WNDENUMPROC lpEnumFunc, Pointer data);


/**
* Brings the specified window to the top of the Z order. If the window is a top-level window, it is activated. If
* the window is a child window, the top-level parent window associated with the child window is activated.
*
* @param hWnd
* A handle to the window to bring to the top of the Z order.
* @return If the function succeeds, the return value is nonzero. If the function fails, the return value is zero.
* To get extended error information, call GetLastError.
*/
boolean BringWindowToTop(HWND hWnd);

/**
* The FlashWindowEx function flashes the specified window. It does not
* change the active state of the window.
Expand Down
21 changes: 21 additions & 0 deletions contrib/platform/test/com/sun/jna/platform/win32/User32Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
import com.sun.jna.platform.win32.WinUser.MONITORINFO;
import com.sun.jna.platform.win32.WinUser.MONITORINFOEX;

import javax.swing.*;

/**
* @author dblock[at]dblock[dot]org
*/
Expand Down Expand Up @@ -439,6 +441,25 @@ public void testGetActiveWindow() {
assertNull("GetActiveWindow result should be null (there is no active window)", result);
}

@Test
public void testBringWindowToTop() {
boolean result = User32.INSTANCE.BringWindowToTop(null);
assertFalse("BringWindowToTop(null) result should be false", result);

final JFrame w = new JFrame("Frame to bring to top");
try {
w.setVisible(true);

HWND hwnd = new HWND();
hwnd.setPointer(Native.getComponentPointer(w));

result = User32.INSTANCE.BringWindowToTop(hwnd);
assertTrue("Couldn't bring frame to top", result);
} finally {
w.dispose();
}
}

@Test
public void testSendMessage() {
DesktopWindow explorerProc = getWindowByProcessPath("explorer.exe");
Expand Down

0 comments on commit 935504c

Please sign in to comment.