How To Check Attribute Flags with Bitwise Operations (227189)



The information in this article applies to:

  • Microsoft Win32 Application Programming Interface (API), when used with:
    • the operating system: Microsoft Windows 2000

This article was previously published under Q227189
This article discusses a Beta release of a Microsoft product. The information in this article is provided as-is and is subject to change without notice.

No formal product support is available from Microsoft for this Beta product. For information about how to obtain support for a Beta release, see the documentation that is included with the Beta product files, or check the Web location from which you downloaded the release.

SUMMARY

When you are using bitwise operations to check flags, always use the bitwise AND operator (&) to determine whether a bit is set.

MORE INFORMATION

You may be using the equality operator (==) to check whether a single bit is set. For example:
if (fItemState == ODS_FOCUS)
				
However, this only works if the single bit set for fItemState is ODS_FOCUS. Instead, you should use the & operator. For example:
if (fItemState & ODS_FOCUS)
				
Even if you only need to check the value of one flag, you should use the & operator to allow for future flags to be added.

Windows 2000 includes new flags for existing flag sets. For example, the DRAWITEMSTRUCT structure has two new flags that help an owner window determine whether a control can be drawn without specific keyboard or focus cues. The ODS_NOACCEL and ODS_NOFOCUSRECT flags must be checked along with the ODS_FOCUS flag to make sure that the control is drawn correctly.

Modification Type:MinorLast Reviewed:6/29/2004
Keywords:kbhowto KB227189