Public Group

# DWORD and usages for passing params

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

## Recommended Posts

Ok i hope this comes as a simple question i am writing my own GUI Still .... anyways i wanted to use a DWORD varable to pass paramaters through as to shorten and make the setup calls to make a button edit box and so on easyer. Example.
#define GUI_SHOW 0x809 //Used as a flag to the Gui's show state true
#define GUI_DISABLED 0x810 //Used as a flag to the Gui's Enabled State

void SetOption(DWORD Options)
{
//To do
}


Now the real problem here and what i can not figure out is if you were to pass in more then one parameter through SetOption() how could i separate them and how would i check for each one individually ! This is a very simple version of a much grander schema but for the most part using the DWORD to pass in an number of predefined sets would be very usefull and shorten setup protoypes greatly. Thanks for your time Regards Jouei.

##### Share on other sites
To check if one of your flags is specified in the "Options" parameter, you use a bit-wise AND operator. Like this:

if ( options & GUI_SHOW )     // Do stuffelse if ( options & GUI_DISABLED )     // Do other stuff

##### Share on other sites
ahh thank you i did not think it would be complicated but for the life of me i could not get it lol.

Thanks and regards Jouei.

##### Share on other sites
hi,

a DWORD has a size of 32-bit.
maybe take a look at a 4 bit broad variable:

0010

you have 4 bits, and each of them can represent a boolean state.
with 32 bit you can now represent 32 different boolean state variables.

now you need to know how to "define" states, set states and check
if a state is set.
therefore there exist bitwise operations: AND, OR, XOR, SHIFT LEFT (SHL).

a good introduction is here:
http://www.gamedev.net/reference/articles/article1563.asp

have phun, shrooms

1. 1
2. 2
Rutin
20
3. 3
4. 4
frob
14
5. 5

• 10
• 9
• 15
• 9
• 33
• ### Forum Statistics

• Total Topics
632593
• Total Posts
3007301

×