Skip to content

Commit

Permalink
Merge pull request #1354 from kahgoh/master
Browse files Browse the repository at this point in the history
Add `GetParent` to `c.s.j.p.win32.User32`
  • Loading branch information
matthiasblaesing authored Jun 22, 2021
2 parents 80fa84d + 92fc845 commit 7b9322d
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Features
* [#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).
* [#1354](https://github.com/java-native-access/jna/pull/1352): Add `GetParent` to `c.s.j.p.win32.User32` - [@kahgoh](https://github.com/kahgoh).

Bug Fixes
---------
Expand Down
24 changes: 24 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 @@ -2274,6 +2274,30 @@ LRESULT SendMessageTimeout(HWND hWnd, int msg, WPARAM wParam, LPARAM lParam,
*/
HWND GetAncestor(HWND hwnd, int gaFlags);

/**
* Retrieves a handle to the specified window's parent or owner.
*
* To retrieve a handle to a specified ancestor, use the GetAncestor function.
*
* @param hwnd
* A handle to the window whose parent window handle is to be retrieved.
* @return Type: HWND<br />
* If the window is a child window, the return value is a handle to the
* parent window. If the window is a top-level window with the WS_POPUP style,
* the return value is a handle to the owner window.
*
* If the function fails, the return value is NULL. To get extended error
* information, call GetLastError.
*
* This function typically fails for one of the following reasons:
* <ul>
* <li>The window is a top-level window that is unowned or does not have
* the WS_POPUP style
* <li>The owner window has WS_POPUP style
* </ul>
*/
HWND GetParent(HWND hwnd);

/**
* Retrieves the position of the mouse cursor, in screen coordinates.
*
Expand Down
30 changes: 30 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 @@ -64,6 +64,7 @@
import com.sun.jna.platform.win32.WinUser.MONITORINFOEX;

import javax.swing.JFrame;
import javax.swing.JWindow;

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

@Test
public void testGetParent() {
HWND desktopWindow = User32.INSTANCE.GetDesktopWindow();
assertNotNull("Failed to get desktop window HWND", desktopWindow);

HWND result = User32.INSTANCE.GetParent(desktopWindow);
assertNull("GetParent result should be null", result);

final JFrame parent = new JFrame("Parent");
final JWindow child = new JWindow(parent);

try {
parent.setVisible(true);
child.setVisible(true);

HWND parentHwnd = new HWND();
parentHwnd.setPointer(Native.getComponentPointer(parent));

HWND childHwnd = new HWND();
childHwnd.setPointer(Native.getComponentPointer(child));

result = User32.INSTANCE.GetParent(childHwnd);
assertEquals("GetParent of child should be parent", parentHwnd, result);
} finally {
child.dispose();
parent.dispose();
}
}

@Test
public void testGetCursorPos() {
POINT cursorPos = new POINT();
Expand Down

0 comments on commit 7b9322d

Please sign in to comment.