如何检查窗口样式是否存在十六进制?
我有一个关于窗口样式十六进制的问题。
如何检查窗口样式组合中是否存在某种窗口样式?例如,我想检查 0x16CF0000
中是否存在 WS_BORDER
(0x00800000
) 样式。
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
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
修复了我的错误的标准形式是:
&将进行按位与,并且仅当设置 WS_BORDER 位时结果才会非零
The standard form with my bug fixed is:
The & will do a bitwise-AND and only if the bit of WS_BORDER is set will the result be non-zero
基本上,您只需检查
yourValue AND WS_BORDER = WS_BORDER
即可。不幸的是,样式标志内的某些位被使用两次,具体取决于上下文,因此例如
WS_TABSTOP
和WS_MAXIMIZEBOX
都是 0x00010000,因此它取决于上下文(对象的位置,也许还有其他标志)窗口是否真的具有该属性(虽然父控件不能有制表位,但子控件有时可以有最大化框)...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
andWS_MAXIMIZEBOX
are 0x00010000, so it depends on the context (position of the object and maybe other flags) whether a window really has that property (while a parent control cannot have a tab stop, a child control sometimes can have a maximize box)...检查 IF((0x16CF0000 | WS_BORDER) == 0x16CF0000)
Check
IF((0x16CF0000 | WS_BORDER) == 0x16CF0000)
过去,我采用了定义此类内容的头文件,并编写了一个脚本将其转换为代码,该代码将采用标志所在的变量并将其转换为包含常量符号名称的文本字符串。
在我使用 AWK 之类的东西来执行此操作的那天,解析 #defines 相当容易。现在,如果我当时使用的机器上有 Python,或者如果 Python 不容易使用,我会回到 AWK。
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 available I'd drop back to AWK.
当我创建一个 win32 对话框生成器时,这个问题确实让我很担心。其中一项功能是设置所有 win32 通用控件以及用户定义控件的样式。通过观察和 MSDN 提供的少量文档,我学到了很多东西;我想分享我的信息。这将超出回答这个问题的范围。
Microsoft 团队如何格式化他们的窗口样式?
它们是适用于所有窗口的通用窗口样式。它们以“WS_”开头,位于高位。 0xffff0000。
然后是以其指定前缀开头的控件特定/用户定义样式。比如BS代表ButtonStyle,CBS代表ComboBoxStyle等等。它们位于低位。 0x0000ffff。
这两个级别的样式共有 5 种类型:
默认 - 这些样式等于 0。仅在以下情况下才选择此样式
样式等于零。
flag - 这些类型的样式永远不等于零,并且被放置在唯一的
位。这意味着这些样式可以同时使用。
exclusive - 这些类型的样式通常彼此共享位。但情况并非一定如此,因为 WS_POPUP 和 WS_CHILD 是独占的,但它们不共享位。大多数其他样式(例如 CBS_SIMPLE 和 CBS_DROPDOWN)都是独占的,并且实际上共享位。独特的风格通常代表一个类别。 BS_OWNERDRAW、BS_RADIOBUTTON、BS_PUSHBUTTON都代表按钮类别的类型。 BS_CENTER、BS_LEFT、BS_TOP 是对齐类别。请注意,BS_PUSHBUTTON 等于 0,表示类型类别的默认值。
复合 - 这些类型的样式由多种样式组成。例如 WS_OVERLAPPEDWINDOW、WS_POPUPWINDOW、DS_SHELLFONT、LBS_STANDARD。
同义词 - 这些类型的样式指的是同一事物。例如:WS_CHILDWINDOW 与 WS_CHILD、WS_TILED 与 WS_OVERLAPPED、WS_TILEDWINDOW 与 WS_OVERLAPPEDWINDOW。请注意,WS_TABSTOP 和 WS_MAXIMIZEBOX 共享相同的值,但它们不是同义词,因为它们在语义上不同。如何?这超出了我的知识范围。 WS_TABSTOP 应用于对话框中使用的控件,并且对话框实现正确的行为。但是,您可以使用 isDialogMessage 在对话框之外模拟相同的行为。子窗口可以有最大化框。对于我的应用程序,我完全忽略了 WS_TABSTOP 样式。
我们如何测试一种风格?
我创建了一个将样式转换为字符串的函数。但是,测试一种样式是否存在于另一种样式中的函数可能不切实际,因为这需要大量上下文。示例函数原型如下所示...
className 将用作主要上下文。如果 className 是 WC_DIALOG,则所有 DS_* 样式均可用于该窗口。但它不能具有属于按钮类、编辑类等的样式。问题是,以下内容在技术上是错误的...
这是错误的,因为即使样式中存在 requiredStyle,也不意味着 requiredStyle 是该样式的有效样式特定的类名。这将要求我们拥有特定类的所有样式的映射,并且仅当该映射中存在 requiredStyle 时,才返回上述公式。
以上解决了第一个问题。但最后一个问题似乎不太现实。假设您有一个必需的样式,即 CBS_SIMPLE|CBS_LOWERCASE。您如何确定所需的样式是否是组合框样式的一部分。这是一个非常切合实际的问题。
查看我的第 2 部分,了解将窗口样式转换为字符串的函数。
This question really concerned me as I was creating a win32 dialog builder. One of the features was setting the style of all win32 common controls, and also user defined controls. I have learnt alot via observation, and the little documentation provided by MSDN; and I wish to share my information. Which will go beyond answering this question.
How did the Microsoft team format their window styles?
Their are general window styles that applies to all windows. They begin with 'WS_' and are found in the high order bits. 0xffff0000.
Then there are Control specific/ user defined styles that begin with their specified prefix. Such as BS for ButtonStyle, CBS for ComboBoxStyle, and so on. They are found in the low order bits. 0x0000ffff.
There are 5 types in these two levels of styles:
Default - These kinds of style are equal to zero. This style is only chosen if
style is equal to zero.
flag - These kinds of style never equates to zero, and are placed on unique
bits. Meaning that these styles can be used simultaneously.
exclusive - These kinds of styles normally share bits with each other. But this doesn't have to be the case as WS_POPUP and WS_CHILD are exclusive but they don't share bits. Most other styles such as CBS_SIMPLE and CBS_DROPDOWN are exclusive and indeed share bits. Exclusive styles often represent a category. BS_OWNERDRAW, BS_RADIOBUTTON, BS_PUSHBUTTON all represent the type of button category. BS_CENTER, BS_LEFT, BS_TOP are the alignment category. Note that BS_PUSHBUTTON is equal to zero and represents the Default for the type category.
compound - These kinds of styles are comprised of multiply styles. Such as WS_OVERLAPPEDWINDOW, WS_POPUPWINDOW, DS_SHELLFONT, LBS_STANDARD.
synonym - These kinds of styles refer to the same thing. Eg: WS_CHILDWINDOW vs WS_CHILD, WS_TILED vs WS_OVERLAPPED, WS_TILEDWINDOW vs WS_OVERLAPPEDWINDOW. Note that WS_TABSTOP and WS_MAXIMIZEBOX share the same value but they are not synonymns as they are semantically different. How? This is outside my scope of knowledge. WS_TABSTOP is applied to controls used in a dialog and the dialog implements the right behaviour. However, you can use isDialogMessage to simulate the same behaviour outside of a dialog. And child windows can have maximize box. For my application, I completely ignored WS_TABSTOP style.
How do we test for a style?
I created a function that converts a style to string. However, a function that test if a style exists in another style might be impractical, as this requires alot of context. A sample function prototype would look as follows...
className would be used as the major context. If className is WC_DIALOG, then all of the DS_* styles are available to the window. But it cannot have styles that belong to the button class, edit class, etc. Problem is, the following is technically wrong...
This is faulty because, even if requiredStyle exist in style, doesnt mean that requiredStyle is a valid style for the particular className. This would require us to have a map of all styles of the particular class, and only if requiredStyle exist in that map, return the above formula.
The above solved the first problem. But the last problem seems impractical to solve. Lets say you have a required style which is CBS_SIMPLE|CBS_LOWERCASE. How would you determine if this required style was apart of the combobox's style. This is a very contextual question.
Check out my Part 2 for a function that converts window style to string.
第 2 部分
将窗口样式转换为字符串的通用函数。希望这对某人有用。请注意,由于篇幅原因,您必须实现以下两个函数原型。
Jav/string/builder.h
Jav/string/numconv.h
win_styles.cpp
PART 2
A genaral function for converting a window style to string. Hope this is useful to some one. Note that due to space, you will have to implement the following two function prototypes.
Jav/string/builder.h
Jav/string/numconv.h
win_styles.cpp