Skip to content

Commit 7b9322d

Browse files
Merge pull request #1354 from kahgoh/master
Add `GetParent` to `c.s.j.p.win32.User32`
2 parents 80fa84d + 92fc845 commit 7b9322d

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

CHANGES.md

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

1617
Bug Fixes
1718
---------

contrib/platform/src/com/sun/jna/platform/win32/User32.java

+24
Original file line numberDiff line numberDiff line change
@@ -2274,6 +2274,30 @@ LRESULT SendMessageTimeout(HWND hWnd, int msg, WPARAM wParam, LPARAM lParam,
22742274
*/
22752275
HWND GetAncestor(HWND hwnd, int gaFlags);
22762276

2277+
/**
2278+
* Retrieves a handle to the specified window's parent or owner.
2279+
*
2280+
* To retrieve a handle to a specified ancestor, use the GetAncestor function.
2281+
*
2282+
* @param hwnd
2283+
* A handle to the window whose parent window handle is to be retrieved.
2284+
* @return Type: HWND<br />
2285+
* If the window is a child window, the return value is a handle to the
2286+
* parent window. If the window is a top-level window with the WS_POPUP style,
2287+
* the return value is a handle to the owner window.
2288+
*
2289+
* If the function fails, the return value is NULL. To get extended error
2290+
* information, call GetLastError.
2291+
*
2292+
* This function typically fails for one of the following reasons:
2293+
* <ul>
2294+
* <li>The window is a top-level window that is unowned or does not have
2295+
* the WS_POPUP style
2296+
* <li>The owner window has WS_POPUP style
2297+
* </ul>
2298+
*/
2299+
HWND GetParent(HWND hwnd);
2300+
22772301
/**
22782302
* Retrieves the position of the mouse cursor, in screen coordinates.
22792303
*

contrib/platform/test/com/sun/jna/platform/win32/User32Test.java

+30
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
import com.sun.jna.platform.win32.WinUser.MONITORINFOEX;
6565

6666
import javax.swing.JFrame;
67+
import javax.swing.JWindow;
6768

6869
/**
6970
* @author dblock[at]dblock[dot]org
@@ -377,6 +378,35 @@ public void testGetAncestor() {
377378
assertNull("GetAncestor result should be null", result);
378379
}
379380

381+
@Test
382+
public void testGetParent() {
383+
HWND desktopWindow = User32.INSTANCE.GetDesktopWindow();
384+
assertNotNull("Failed to get desktop window HWND", desktopWindow);
385+
386+
HWND result = User32.INSTANCE.GetParent(desktopWindow);
387+
assertNull("GetParent result should be null", result);
388+
389+
final JFrame parent = new JFrame("Parent");
390+
final JWindow child = new JWindow(parent);
391+
392+
try {
393+
parent.setVisible(true);
394+
child.setVisible(true);
395+
396+
HWND parentHwnd = new HWND();
397+
parentHwnd.setPointer(Native.getComponentPointer(parent));
398+
399+
HWND childHwnd = new HWND();
400+
childHwnd.setPointer(Native.getComponentPointer(child));
401+
402+
result = User32.INSTANCE.GetParent(childHwnd);
403+
assertEquals("GetParent of child should be parent", parentHwnd, result);
404+
} finally {
405+
child.dispose();
406+
parent.dispose();
407+
}
408+
}
409+
380410
@Test
381411
public void testGetCursorPos() {
382412
POINT cursorPos = new POINT();

0 commit comments

Comments
 (0)