Q:

WM_ENABLE default processing

I have problem in my control window. How to respond to the WM_ENABLE message?
I have bool flag bEnable which controls WM_ENABLE message:
LRESULT WINAPI OnEnable(HWND hWindow, WPARAM wParam, LPARAM lParam)
{
    LRESULT lReturn = 0;
    BOOL bEnabled = (BOOL)wParam;
    UNREFERENCED_PARAMETER(lParam);
    g_bEnabled = bEnabled;
    InvalidateRect(hWindow, NULL, TRUE);
    return lReturn;
}

But this not affect setting WS_DISABLED by SetWindowLong.
So how I make my OnEnable handler reflects this changes?
Is proper way:
LONG lStyles = GetWindowLong(hWindow, GWL_STYLE);

if (bEnable)
{
        lStyles = lStyles & ~WS_DISABLED;
        g_bEnable = TRUE;
}
else
{
         lStyles = lStyles | WS_DISABLED;
         g_bEnable = FALSE;
}

or is another way?

A:

Use EnableWindow(hwnd, enable)  to enable/disable window
Use IsWindowEnabled(hwnd) to check if window is enabled or disabled.
Calling Invalidate after enable/disable may not have any visible effect. For example if there is a OK button, the OK button may still appear as enabled even if window is disabled. If you want to disable the child controls then use the following:
HWND child = GetWindow(hwnd, GW_CHILD);
while (child)
{
    EnableWindow(child, enable);
    child = GetWindow(child, GW_HWNDNEXT);
}

The following functions will work too, but there is no reason to use them over EnableWindow and IsWindowEnabled
//don't use
BOOL enabled = !(GetWindowLong(hbutton, GWL_STYLE) & WS_DISABLED);

//disable - don't use
SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) | WS_DISABLED);

//enable - don't use
SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_DISABLED);

