#### Archived

This topic is now archived and is closed to further replies.

# How does windows do it?

This topic is 5848 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

When you use the CreateWindow() function, you are allowed to choose what styles to incorporate with the window. for example: when you create a Button, you can choose WS_CHILD | WS_xxx | BS_xxx | etc... How can i do that? lets say void foo(int a, int styles) how can i do this: foo(10, STYLE1 | STYLE2 | STYLE3 | STYLE4) ?? thanks for your help!

##### Share on other sites
Each of the flags occupies one bit in a larger data type.

const int STYLE1 = 0x0001;
const int STYLE2 = 0x0002;
const int STYLE3 = 0x0004;
const int STYLE4 = 0x0008;
const int STYLE5 = 0x0010;

You glue them together with ''|'', and you check for a bit with ''&''.

int x = STYLE1 | STYLE2;

if(x & STYLE1)
DoSomething();

Take care,
Bill

##### Share on other sites
quote:
Original post by Siebharinn
Each of the flags occupies one bit in a larger data type.

const int STYLE1 = 0x0001;
const int STYLE2 = 0x0002;
const int STYLE3 = 0x0004;
const int STYLE4 = 0x0008;
const int STYLE5 = 0x0010;

You glue them together with '|', and you check for a bit with '&'.

int x = STYLE1 | STYLE2;

if(x & STYLE1)
DoSomething();

Take care,
Bill

hmm. how about if its int x = style | style2 | style 3 ??

anyways,,,is there anyplace where i can find tutorials on this?? i dont really want to take up yor time asking for more example. id rather read and learn about it.

Edited by - ELS1 on February 19, 2002 5:03:57 PM

##### Share on other sites
x would test true for all three styles...
in the "articles and resources" section (see link at the top of the page) there is an article called "bitwise operations in c" or something to that effect. i think it is what you need.

--- krez (krezisback@aol.com)

##### Share on other sites
Look up bitwise operations in any programming book, or do a search on the web. Understanding binary/hex/etc will also help.

Or just look on this site :-)

http://www.gamedev.net/reference/programming/features/bitwise/

Quickly,

u8 cValue = 0;

cValue |= 0x01; // Turns on first bit
cValue &= ~0x01 // Turns off first bit

cValue = (0x01 | 0x02); // Turn on bits 1 and 2 etc

if (cValue & 0x01)
// First bit is on, etc

Best of luck!

##### Share on other sites
so if i would create a simple win32api wrapper of ALL the controls...the code for detecting which styles the user picks would get MESSY....UGH...

##### Share on other sites
First, some example code:

  //Define flagsconst unsigned long FLAG1 = 1 << 0 FLAG2 = 1 << 1 FLAG3 = 1 << 2 FLAG4 = 1 << 3;//...void foo(unsigned long flags){ if(flags & FLAG1) //Do one thing if(flags & FLAG2) //Do another thing if(flags & FLAG3) //Do a third thing if(flags & FLAG4) //Do a fourth thing }

Look up the following:

• Bitwise operators
• Bitpacking

• 21
• 11
• 17
• 11
• 13