Which window style bits belong to whom?

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.

Skip to main content