Skip to content

Conversation

@Zakariathr22
Copy link
Contributor

@Zakariathr22 Zakariathr22 commented Feb 28, 2025

Summary

This PR adds HWNDPARENT (-8) to the documentation for SetWindowLong... functions. This value exists in the Windows API but was not previously documented. The update clarifies its role and ensures developers can use it correctly.

Reason for Change

  • HWNDPARENT is a valid window attribute that allows setting the owner of a top-level window.
  • The documentation did not mention this, making it unclear how to properly set window ownership.
  • This change helps developers understand the correct use of SetWindowLong... when managing window relationships.

Changes Made

  • Added HWNDPARENT (-8) to the table of valid SetWindowLong... values.
  • Provided a short description of its function.
  • Clarified the difference between parent and owner relationships.

Impact

  • Improves documentation clarity.
  • Helps developers avoid confusion between SetWindowLongPtr(GWLP_HWNDPARENT) and SetParent().
  • Prevents misuse.

Sources

  • PDC 2005 - Five Things Every Win32 Developer Should Know - Raymond Chen - 2005/09 Slide 32
    YouTube Video - minute: 52:00
  • Devblogs - A window can have a parent or an owner but not both - Raymond Chen - March 15th, 2010 link

Additional Context

In the first mentioned source above, I’m not sure if the "Set Owner Window" approach was presented solely as a hack, but it is an effective solution that proves useful in many scenarios. It is widely used by developers, including in WPF, as seen in the WPF source code. Personally, I use this approach in WinUI 3 by leveraging C#/Win32 P/Invoke, as demonstrated in this use case example.

Please let me know if any further improvements are needed!

@prmerger-automator
Copy link

@Zakariathr22 : Thanks for your contribution! The author(s) have been notified to review your proposed change.

@Zakariathr22 Zakariathr22 changed the title Update gwlp hwndparent docs Update: SetWindowLong... hwndparent docs Mar 1, 2025
@Zakariathr22 Zakariathr22 changed the title Update: SetWindowLong... hwndparent docs Document HWNDPARENT (-8) for SetWindowLong... to Clarify Window Ownership Mar 2, 2025
@Zakariathr22
Copy link
Contributor Author

@jwmsft
I would really appreciate it if you could review this.

@jwmsft
Copy link
Contributor

jwmsft commented Mar 4, 2025

@Zakariathr22, thanks for the updates, and for providing links to sources.

@jwmsft jwmsft merged commit 1d55a62 into MicrosoftDocs:docs Mar 4, 2025
1 check passed
@Zakariathr22 Zakariathr22 deleted the update-gwlp-hwndparent-docs branch March 5, 2025 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants