Getting window style

I am trying to check if a window has a specific style using GetWindowLong (hWnd, GWL_STYLE), but this gives me the type of the LONG variable. how would you test a particular style, for example, the value type const 'WS_CAPTION'?

+3
source share
2 answers

use the bitwise and operator to compare with this long type,

Example

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

Most WS_ window styles are single-bit values; each of which takes only one bit in dwStyles.

Here dwStylesyou can get from:DWORD dwStyles = CWnd::GetStyle();

But some WS_ styles, such as WS_CAPTION, WS_OVERLAPPEDWINDOW, WS_POPUPWINDOW, merge several single-bit style.

OK .

DWORD dwSomeStyle = WS_... ;
BOOL bSomeStyleIsPresentForThisWnd;

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

Source: https://habr.com/ru/post/1742044/


All Articles