Question

I am currently trying to make a GUI for some software and I'm having problems with some static controls. In my windows procedure I have the WM_CTLCOLORSTATIC message for when the static controls are to be drawn. Inside the message, I have an IF ELSE statement where it compares the handles of a window to the one that needs to be drawn and performs windows functions accordingly. One is a static text control that has the background color set when drawn while the other is to draw the borders of a static control.

    case WM_CTLCOLORSTATIC:
    {
        if (hwnd = ANNwindow->settingsborder)
        {
            SetBkMode((HDC)wParam, TRANSPARENT);
            return (LRESULT)ANNwindow->backgroundbrush;
        }
        else if (hwnd = ANNwindow->settingstext)
        {
            DrawEdge((HDC)wParam, &ANNwindow->rect, EDGE_ETCHED, BF_BOTTOMRIGHT);
            return (LRESULT)ANNwindow->backgroundbrush;
        }

    }

The settingsborder and settingstext are window handles in my class for creating the GUI.

If I reverse the order of the if else statements, it only does the first one, no matter what order. If changing the background color is under the IF, it does that. If drawing the border is under the IF, then it does that, but never whats under the else part. Is this a simple error in using the C++ language as I can not find the problem. Please help, thanks.

P.S. For the drawedge part, I first create a static control border, then use the drawedge on that, should I do it a different way? Thanks.

Was it helpful?

Solution

Here's your problem.

if (hwnd = ANNwindow->settingsborder)

should be

if (hwnd == ANNwindow->settingsborder)
//       ^^

and the same for the else if statement.

You're assigning the contents of ANNwindow->settingsborder to your hwnd, an operation that virtually always returns true instead of doing an equality test.

OTHER TIPS

  1. Turn on warnings in your compiler.
  2. Notice that in both conditions you are using assignments (=) instead of comparisons (==).
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top