Microsoft KB Archive/227189

{|
 * width="100%"|

HOWTO: Check Attribute Flags with Bitwise Operations

 * }

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 obtaining support for a Beta release, please see the documentation included with the Beta product files, or check the Web location from which you downloaded the release.

-

The information in this article applies to:


 * Microsoft Win32 Application Programming Interface (API), included with:
 * the operating system: Microsoft Windows 2000

-

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.

Additional query words: compatguidestability

Keywords : kbOSWin2000 kbGrpDSKernBase

Issue type : kbhowto

Technology : kbAudDeveloper kbWin32sSearch kbWin32API