0

我编写了一个简单的基于 Win32 API 对话框的应用程序,其中包含丰富的编辑控件。该控件显示基于 ANSI 的文本文件的内容并进行一些非常基本的语法突出显示。

我正在使用 Visual C++ 2010 Express 编写代码,当我在发布模式下编译时,一切正常。但是,当我在调试模式下编译时,程序运行,语法突出显示似乎正在发生,但控件中的文本没有改变颜色。

关于为什么会发生这种情况的任何想法?

编辑:添加这段代码是为了显示我如何尝试为富编辑控件中的文本着色。

CHARFORMATA _token; // This variable is actually a member variable.
                    // I just pasted it in the body of the function
                    // so the code would make sense.

// _control is a pointer to a rich edit control object. I created a
// REdit class that adds member variables for a rich edit control.
// The class contains an HWND member variable storing the window
// handle. The method GetHandle() returns the window handle.

void SyntaxHighlighter::ColorSelection(COLORREF color)
{
  CHARFORMATA _token;
  _token.cbSize = sizeof(CHARFORMATA);
  _token.dwMask = CFM_COLOR;
  _token.crTextColor = color;
  SendMessageA(_control->GetHandle(), EM_SETCHARFORMAT,
               (WPARAM)SCF_SELECTION, (LPARAM)&_token);
}

正如我上面提到的,当我在发布模式下编译时,文本的颜色会按预期工作。当我在调试模式下编译时,不会发生着色。我想知道是否在调试模式下,如果控件的某些功能不起作用?

4

1 回答 1

1

您将 dwMask 设置为 CFM_COLOR,这表示crTextColor 和 dwEffects 成员都是有效的,但您没有初始化 dwEffects。在发布模式下,它可能最终为零,但在调试模式下,一些随机标志值导致它不起作用。我建议这样做:

CHARFORMATA _token;
memset(&_token, 0, sizeof(_token));
_token.cbSize = sizeof(CHARFORMATA);
_token.dwMask = CFM_COLOR;
_token.crTextColor = color;
于 2012-03-09T17:47:51.820 回答