获取窗口样式

发布于 2024-08-29 10:52:27 字数 108 浏览 11 评论 0原文

我正在尝试使用 GetWindowLong(hWnd, GWL_STYLE) 检查窗口是否具有某种样式,但这给了我一个 LONG 类型的变量。您将如何检查常量值类型“WS_CAPTION”中的特定样式?

I'm trying to check if a window has a certain style using GetWindowLong(hWnd, GWL_STYLE) but that gives me a LONG type of variable. how would you check for a specific style from that say a const value type 'WS_CAPTION'?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

魂ガ小子 2024-09-05 10:52:27

使用按位 &与该 long 类型进行比较的运算符,

例如

if (szLng & WS_CAPTION){
    // that window has caption
}

use the bitwise & operator to compare with that long type,

example

if (szLng & WS_CAPTION){
    // that window has caption
}
挽心 2024-09-05 10:52:27

大多数窗口样式 WS_ 都是单位值;
也就是说,它们在 dwStyles 中只占一位。

这里dwStyles可以通过以下方式获得:DWORD dwStyles = CWnd::GetStyle();

但是有些WS_样式,如WS_CAPTION,<代码>WS_OVERLAPPEDWINDOW,
WS_POPUPWINDOW,组合了一些单位样式。

下面的测试代码适用于单位窗口样式
但对于组合样式则不OK

DWORD dwSomeStyle = WS_... ;
BOOL bSomeStyleIsPresentForThisWnd;

if (dwStyles & dwSomeStyle)
  bSomeStyleIsPresentForThisWnd = TRUE;
else
  bSomeStyleIsPresentForThisWnd = FALSE;

Most of the window styles WS_ are single-bit values;
that is each of them occupies only one bit in dwStyles.

Here dwStyles can be obtained from: DWORD dwStyles = CWnd::GetStyle();

But some of the WS_ styles, such as WS_CAPTION, WS_OVERLAPPEDWINDOW,
WS_POPUPWINDOW, combine a few single-bit styles.

The test code below is OK for single-bit window styles
but not OK for combined styles.

DWORD dwSomeStyle = WS_... ;
BOOL bSomeStyleIsPresentForThisWnd;

if (dwStyles & dwSomeStyle)
  bSomeStyleIsPresentForThisWnd = TRUE;
else
  bSomeStyleIsPresentForThisWnd = FALSE;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文