سؤال

I have a simple Win32 API dialog-based application that I've written which contains a rich edit control. The control displays the contents of ANSI-based text files and does some very basic syntax highlighting.

I am using Visual C++ 2010 Express to write the code, and when I compile in Release mode, everything works perfect. However, when I compile in debug mode, the program runs, the syntax highlighting appears to be happening, but the text in the control does not change color.

Any ideas on why this might be happening?

EDIT: This snippet of code was added to show how I am attempting to color the text in the rich edit control.

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);
}

As I mentioned above, when I compile in Release mode, the coloring of the text works as intended. When I compile in Debug mode, the coloring does not happen. I'm wondering if in Debug mode, if certain features of the control don't work?

هل كانت مفيدة؟

المحلول

You're setting dwMask to CFM_COLOR, which says that both the crTextColor and dwEffects members are valid, but you're not initializing dwEffects. In release mode it's probably ending up zero but in debug mode some random flag value that causes it not to work. I would recommend doing it this way:

CHARFORMATA _token;
memset(&_token, 0, sizeof(_token));
_token.cbSize = sizeof(CHARFORMATA);
_token.dwMask = CFM_COLOR;
_token.crTextColor = color;
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top