Skip to content

Commit 4032b5e

Browse files
authored
Add BringWindowToTop to User32 (#1352)
1 parent b7b48c9 commit 4032b5e

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

Diff for: CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Features
1111
* [#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).
1212
* [#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).
1313
* [#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).
14+
* [#1352](https://github.com/java-native-access/jna/pull/1352): Add `BringWindowToTop` to `c.s.j.p.win32.User32` - [@kahgoh](https://github.com/kahgoh)
1415

1516
Bug Fixes
1617
---------

Diff for: contrib/platform/src/com/sun/jna/platform/win32/User32.java

+12
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,18 @@ public interface User32 extends StdCallLibrary, WinUser, WinNT {
359359
*/
360360
boolean EnumThreadWindows(int dwThreadId, WNDENUMPROC lpEnumFunc, Pointer data);
361361

362+
363+
/**
364+
* Brings the specified window to the top of the Z order. If the window is a top-level window, it is activated. If
365+
* the window is a child window, the top-level parent window associated with the child window is activated.
366+
*
367+
* @param hWnd
368+
* A handle to the window to bring to the top of the Z order.
369+
* @return If the function succeeds, the return value is nonzero. If the function fails, the return value is zero.
370+
* To get extended error information, call GetLastError.
371+
*/
372+
boolean BringWindowToTop(HWND hWnd);
373+
362374
/**
363375
* The FlashWindowEx function flashes the specified window. It does not
364376
* change the active state of the window.

Diff for: contrib/platform/test/com/sun/jna/platform/win32/User32Test.java

+21
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363
import com.sun.jna.platform.win32.WinUser.MONITORINFO;
6464
import com.sun.jna.platform.win32.WinUser.MONITORINFOEX;
6565

66+
import javax.swing.JFrame;
67+
6668
/**
6769
* @author dblock[at]dblock[dot]org
6870
*/
@@ -439,6 +441,25 @@ public void testGetActiveWindow() {
439441
assertNull("GetActiveWindow result should be null (there is no active window)", result);
440442
}
441443

444+
@Test
445+
public void testBringWindowToTop() {
446+
boolean result = User32.INSTANCE.BringWindowToTop(null);
447+
assertFalse("BringWindowToTop(null) result should be false", result);
448+
449+
final JFrame w = new JFrame("Frame to bring to top");
450+
try {
451+
w.setVisible(true);
452+
453+
HWND hwnd = new HWND();
454+
hwnd.setPointer(Native.getComponentPointer(w));
455+
456+
result = User32.INSTANCE.BringWindowToTop(hwnd);
457+
assertTrue("Couldn't bring frame to top", result);
458+
} finally {
459+
w.dispose();
460+
}
461+
}
462+
442463
@Test
443464
public void testSendMessage() {
444465
DesktopWindow explorerProc = getWindowByProcessPath("explorer.exe");

0 commit comments

Comments
 (0)