开发者

Windows Procedure If Else statement doesn't work for message

开发者 https://www.devze.com 2023-02-01 01:30 出处:网络
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 t

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.


  1. Turn on warnings in your compiler.
  2. Notice that in both conditions you are using assignments (=) instead of comparisons (==).


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号