Which window style bits belong to whom?

Date:December 3, 2003 / year-entry #149
Tags:code
Orig Link:https://blogs.msdn.microsoft.com/oldnewthing/20031203-00/?p=41633
Comments:    6
Summary:There are 64 bits of styles in the parameters to CreateWindowEx. Which ones belong to whom? Windows defines the meanings of the high word of the dwStyle parameter and all of the bits in the dwExStyle parameter. The low 16 bits of the dwStyle parameter are defined by the implementor of the window class (by...

There are 64 bits of styles in the parameters to CreateWindowEx. Which ones belong to whom?

Windows defines the meanings of the high word of the dwStyle parameter and all of the bits in the dwExStyle parameter. The low 16 bits of the dwStyle parameter are defined by the implementor of the window class (by the person who calls RegisterClass).

In Windows 95, we found several apps that noticed that some bits in the dwExStyle weren't being used, so they decided to use them for themselves. Then when we added meanings to those bits (such as WS_EX_TOOLWINDOW), these programs started acting funny.

So don't be like those programs. Don't use bits that don't belong to you.

If you need more than 16 bits of style information, you can design your class so additional information is passed in the lpParam parameter (the last one) to CreateWindow/Ex, which can be received from the lpCreateParams member of the CREATSTRUCT structure. Alternatively, you can set additional styles with a custom message, such as listview's LVM_SETEXTENDEDLISTVIEWSTYLE message.


Comments (6)
  1. Jack Mathews says:

    Well if the bits are invalid and reserved, then why don’t you make Windows fail if someone tries to use an extended style bit it doesn’t know about? Then a person has to check for capabilities before specifying a bit, and it’ll fail if they try something stupid. You can’t worry about people using a system in a way you don’t intend if you don’t let them.

  2. Raymond Chen says:

    Because CreateWindowEx was designed back in the days when programs were trusted not to be stupid (Windows 3.0).

    But it’s enforced now, so at least nobody will make this mistake in the future. I hope.

  3. Serge Khorun says:

    BTW, what is the reason for it’s not being possible to drop stuff on taskbar buttons?

  4. Raymond Chen says:

    Because there is no GetDropTargetFromWindow API.

  5. This has always bugged me (not being able to drop onto taskbar buttons). I try to do it several times a week, even though I know it won’t work.

    I don’t buy the explanation about why it can’t be done. A drop onto a taskbar button could–and should–be treated the same as a drop onto the corresponding titlebar.

    I’ll have to write a hack to fix this, just to prove it can be done! :-)

  6. Each window class defines its private style bits, and you can’t just mix-and-match.

Comments are closed.


*DISCLAIMER: I DO NOT OWN THIS CONTENT. If you are the owner and would like it removed, please contact me. The content herein is an archived reproduction of entries from Raymond Chen's "Old New Thing" Blog (most recent link is here). It may have slight formatting modifications for consistency and to improve readability.

WHY DID I DUPLICATE THIS CONTENT HERE? Let me first say this site has never had anything to sell and has never shown ads of any kind. I have nothing monetarily to gain by duplicating content here. Because I had made my own local copy of this content throughout the years, for ease of using tools like grep, I decided to put it online after I discovered some of the original content previously and publicly available, had disappeared approximately early to mid 2019. At the same time, I present the content in an easily accessible theme-agnostic way.

The information provided by Raymond's blog is, for all practical purposes, more authoritative on Windows Development than Microsoft's own MSDN documentation and should be considered supplemental reading to that documentation. The wealth of missing details provided by this blog that Microsoft could not or did not document about Windows over the years is vital enough, many would agree an online "backup" of these details is a necessary endeavor. Specifics include:

<-- Back to Old New Thing Archive Index