Skip to content

Commit

Permalink
Add GetParent to User32
Browse files Browse the repository at this point in the history
  • Loading branch information
kahgoh committed Jun 13, 2021
1 parent 80fa84d commit 48b465b
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
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
29 changes: 29 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 @@ -377,6 +377,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");
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 48b465b

Please sign in to comment.