GetWindowLong Problem.

I'm writing a wrapper around the Win32 API. I have a class for editing a window, this class has methods for getting/setting the location, text, window styles, ect. This is what I have for the GetStyles method:

1
2
3
4
DWORD WindowEditing::GetStyles (int iFlags)
{
    return GetWindowLong (hHandle, iFlags);
}


When I try to use the function, it doesn't return the correct value, example, I'll use this:

1
2
WindowEditing Edit (hWnd);
if (Edit.GetStyles (GWL_STYLE) == WS_OVERLAPPEDWINDOW) MessageBox (0,0,0,0);


And a blank message box will not show up.

Can anyone help? Thanks.
You should change the == to a &. You want to test if the bits(WS_OVERLAPPEDWINDOW) are set, not for the actual value of WS_OVERLAPPEDWINDOW.
Last edited on
In addition to that, WS_OVERLAPPEDWINDOW is in fact a combination of flags. So if you only do & if will give you a false positive if any of those flags are set.

For example:

1
2
3
4
5
6
7
int style = WS_SYSMENU;

if(style & WS_OVERLAPPEDWINDOW)
{
  // this block will execute, because WS_SYSMENU is part of WS_OVERLAPPEDWINDOW
  //  and therefore the & returns nonzero
}


To check for the whole WS_OVERLAPPEDWINDOW style, you need to make sure that all the WS_OVERLAPPEDWINDOW flags are set. You do this with a combination of & and ==:

 
if( (style & WS_OVERLAPPEDWINDOW) == WS_OVERLAPPEDWINDOW )
Thanks guys.
Topic archived. No new replies allowed.