문제

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.

도움이 되었습니까?

해결책

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.

다른 팁

  1. Turn on warnings in your compiler.
  2. Notice that in both conditions you are using assignments (=) instead of comparisons (==).
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top