#### Archived

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

# win32 question

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

## Recommended Posts

hi, i have a question about how win32 and dx hanle their function parameters. for example CreateWindow(WS_OVERLAPPED||WS_VISIBLE); now, i know thats not the full function, but those parameters are what i dont understand. i know that they are constants, and i know there are a LOT of them. and you can OR like 10 together at a time. but i thought when you use the || and the && operators, that they only return a 1 or a 0. how can they represent all the combinations of constants that are posible, with just one bit? i didnt think c had individual bit manipulation like assembly does. i could understand if it did. but whenever i use ||, i only returns one or zero. i dont understand.

##### Share on other sites
This is exactly the reasons why the | and & operators are used for bitmasks...

Tim

--------------------------
glvelocity.gamedev.net
www.gamedev.net/hosted/glvelocity

##### Share on other sites
You use the || operator when creating windows?

Try just |.

Because, if you take the values 3 (0011) and 5 (0101), the value returns 7 (0111).

The reason why they can take like 10 parameters, is that CreateWindow takes a DWORD for it''s style, which is 32 bits. When using a bitwise inclusive or, it allows for a lot of variation, and can handle all that.

##### Share on other sites
Let me explain tcs'' reply in a little more depth.

The proper statement is CreateWindow( WS_OVERLAPPED | WS_VISIBLE ). The single | (bitwise-OR) differs from the logical-OR, which you used, in that it doesn''t return a boolean result but rather an integral value that is the result of OR''ing the individual bits in each argument. So, as Nytgard pointed out, OR''ing 3 (0011) and 5 (0101) bitwise yields 7 (0111) as follows:
   0011OR 0101-------   0111 - OR each bit vertically ( 1 OR 1 = 1; 1 OR 0 = 1; 0 OR 0 = 0)

Since the dwStyle variable is a DWORD (32-bit, as Nytegard pointed out), it can hold up to 4,294,967,296 different values unsigned . If each style constant is exactly one value, think how many can be combined.

##### Share on other sites
quote:
Original post by Oluseyi

Since the dwStyle variable is a DWORD (32-bit, as Nytegard pointed out), it can hold up to 4,294,967,296 different values unsigned . If each style constant is exactly one value, think how many can be combined.

I''m not sure what you''re thinking, but you can only have 32 different flags with a 32-bit value. You can have flags that go: 1 2 4 8 16, etc. But if you have a flag that''s 3, you can''t tell if the value you''ve been given was meant to be 3 or (1 | 2)

##### Share on other sites
I''m not exactly sure how windows works things out, whether you can have 32 or 4 billion different signs, but with certain things I do, you can manipulate a 32 bit DWORD to hold more than just 32 flags.

For instance, certain flags can only be used with other flags, and certain flags can''t be used with other flags.

Lets take a 4 bit value here.

Flag 1 can''t be used with Flag 4. The default alignment is if the first and fourth bit are used, the fourth bit becomes flag 5. Therefore, you''ve just increased the total amount of values and saved a little space. Granted, I doubt 4 billion+ different combo''s are allowed, but I wouldn''t be surprised if you could compress around 100 or so flags into a DWORD.

##### Share on other sites
thanks a lot. i was just confusing the || and the |. i was using
just the | when calling CreateWindow. it does make sense now,
thanks. i was wondering if anybody learned bit manipulation stuff in a c\c++ class. i''ve taken intro and advanced at my college, and haven''t had any of this stuff in class. in fact, most of the advanced stuff(even though this probably isnt advanced), i have learned from the help of this message board. does anyone recommend a good book on advanced c\c++ programming? thanks.

##### Share on other sites
quote:
Original post by jharkey
thanks a lot. i was just confusing the || and the |. i was using
just the | when calling CreateWindow. it does make sense now,
thanks. i was wondering if anybody learned bit manipulation stuff in a c\c++ class. i''ve taken intro and advanced at my college, and haven''t had any of this stuff in class. in fact, most of the advanced stuff(even though this probably isnt advanced), i have learned from the help of this message board. does anyone recommend a good book on advanced c\c++ programming? thanks.

I''ve noticed this too. Classes and even a lot of books just tell "you use this here" or "this does this" without tell you how are why. I also would be interested in a book that explains those things in deeper.

##### Share on other sites
| is the bitwise or.
|| is the logical or.

With the logical or, the compiler evaluates each statement as "true" or "false", where zero is false and anything else is true.

(10011 || 11001) is interpreted as (true || true), which of course evaluates to true. It then returns the standard value of "true", which is simply 1.