views:

122

answers:

5

Hi,

I have a question regarding a window style hexadecimal.

According to http://support.microsoft.com/kb/111011/en-us, 0x16CF0000 contains window styles of WS_VISIBLE, WS_CLIPSIBLINGS, WS_CLIPCHILDREN, WS_CAPTION, WS_SYSMENU, WS_THICKFRAME, WS_MINIMIZEBOX, and WS_MAXIMIZEBOX.

How do I check if a window style exist in a combination of window styles? For example, I would like to check if WS_BORDER (0x00800000) style exists in 0x16CF0000.

+2  A: 
if(0x16CF0000 & WS_BORDER)
chaos
+2  A: 

The standard form is:

if (value & WS_BORDER != 0) {  }

The & will do a bitwise-AND and only if the bit of WS_BORDER is set will the result be non-zero

Henk Holterman
+1. Makes a little more sense than mine, I think.
JamesMLV
+1  A: 

Check IF((0x16CF0000 | WS_BORDER) == 0x16CF0000)

JamesMLV
+1  A: 

Basically, you can just check whether yourValue AND WS_BORDER = WS_BORDER.

Unfortunately, some of the bits inside of the style flags are used twice, depending on context, so for example both WS_TABSTOP and WS_MAXIMIZEBOX are 0x00010000, so it depends on the context (position of the object and maybe other flags) whether a window really has that property (obviously a child control cannot have a maximize box, and a parent control cannot have a tab stop)...

WS_OVERLAPPED      = 0x00000000,
WS_POPUP           = 0x80000000,
WS_CHILD           = 0x40000000,
WS_MINIMIZE        = 0x20000000,
WS_VISIBLE         = 0x10000000,
WS_DISABLED        = 0x08000000,
WS_CLIPSIBLINGS    = 0x04000000,
WS_CLIPCHILDREN    = 0x02000000,
WS_MAXIMIZE        = 0x01000000,
WS_BORDER          = 0x00800000,
WS_DLGFRAME        = 0x00400000,
WS_VSCROLL         = 0x00200000,
WS_HSCROLL         = 0x00100000,
WS_SYSMENU         = 0x00080000,
WS_THICKFRAME      = 0x00040000,
WS_GROUP           = 0x00020000,
WS_TABSTOP         = 0x00010000,

WS_MINIMIZEBOX     = 0x00020000,
WS_MAXIMIZEBOX     = 0x00010000,

WS_CAPTION         = WS_BORDER | WS_DLGFRAME,
WS_TILED           = WS_OVERLAPPED,
WS_ICONIC          = WS_MINIMIZE,
WS_SIZEBOX         = WS_THICKFRAME,
WS_TILEDWINDOW     = WS_OVERLAPPEDWINDOW,

WS_OVERLAPPEDWINDOW    = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | 
                         WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
WS_POPUPWINDOW     = WS_POPUP | WS_BORDER | WS_SYSMENU,
WS_CHILDWINDOW     = WS_CHILD,
mihi
+1  A: 

In the past, I have taken the header file where such things were defined and wrote a script to turn it into code that would take the Variable which the flags were and convert it into a text string containing the symbolic name of the constants.

Parsing #defines is rather easy back in the day I used something like AWK to do this. Now days, if I have it on the machine I'm using at the time, Python or if Python's not readily avalible I'd drop back to AWK.

NoMoreZealots