userover8k
userover8k

Reputation: 33

Childwindow inside MainWindow shows for a second then disappears

I have MainWindow instance and inside I want to create a bunch of child windows which are the instance of GemWindow Class I do so by

    for (unsigned int i = 0; i < win.GetcGem(); i++)
    {
        for (unsigned int j = 0; j < win.GetcGem(); j++)
        {
            if (!win.Gems[i][j].Create(L"gem", WS_CHILDWINDOW | WS_VISIBLE, NULL, 0, 0, 80, 80, win.Window(), NULL))
                return 0;
        }
    }

but child windows show for a second (at least on my machine) then they disappear I checked using spy++ and there are windows as children of my MainWindow but they are not displayed. I couldn't find any solid reason for it to erase them.

Thanks if you take time to help

Upvotes: 0

Views: 89

Answers (1)

Zeus
Zeus

Reputation: 3890

You can modify the background color through the SetClassLong function without processing the WM_PAINT message.

Only need to modify the code as:

for (unsigned int i = 0; i < GetcGem(); i++)
{
    for (unsigned int j = 0; j < GetcGem(); j++)
    {
        if (Gems[i][j].Create(L"gem", WS_CHILD | WS_VISIBLE, NULL, 5 + i * GetsGem().cx + i * 5, 5 + j * GetsGem().cy + j * 5, GetsGem().cx, GetsGem().cy, Window(), NULL))
        {
            HBRUSH hbrush = CreateSolidBrush(0X7d7d7d);//rgb hexadecimal
            HBRUSH hOldBrush = (HBRUSH)SetClassLongPtr(Gems[i][j].Window(), GCLP_HBRBACKGROUND, (LONG_PTR)hbrush);
            DeleteObject(hOldBrush);
            InvalidateRect(Gems[i][j].Window(), NULL, 1);
        }
        else
        {
            return FALSE;
        }
    }
    
}

Upvotes: 1

Related Questions