Mark Russinovich is an expert on the subject. He has written the book "Windows Internals". Luckily, there's not only the book but also an article dating 2019-06-27.
First he describes USER objects:
USER objects get their name from the fact that they represent user interface elements like desktops, windows, menus, cursors, icons, and accelerator tables (menu keyboard shortcuts).
And then continues describing the limits:
A basic limitation imposed by the window manager is that no process can create more than 10,000 USER objects.
and
One fundamental limitation on the number of USER objects comes from the fact that their identifiers were 16-bit values in the first versions of Windows, which were 16-bit. When 32-bit support was added in later versions, USER identifiers had to remain restricted to 16-bit values so that 16-bit processes could interact with windows and other USER objects created by 32-bit processes. Thus, 65,535 (2^16) is the limit on the total number of USER objects that can be created on a session
He also explains the number mentioned by @Tobi:
for historical reasons, windows must have even-numbered identifiers, so there can be a maximum of 32,768 windows per session