简体   繁体   中英

Syntax Highlighting for Scintilla in C++

I'm working on MFC based code editor. The part on which I'm stuck is when i need to add color to keywords, bassicaly nothing happens. SCE_C_WORD should be setting it up (I also found SCE_C_WORD2, but also nothing happens).

void ScintillaCtrl::SetUpEditor()
{
    SendEditor(SCI_SETKEYWORDS, NULL, reinterpret_cast<LPARAM>(ini.GetKeywords()));

    SetAStyle(SCE_C_COMMENT, ini.GetColor(_T("comment")));
    SetAStyle(SCE_C_COMMENTLINE, ini.GetColor(_T("comment")));
    SetAStyle(SCE_C_COMMENTDOC, ini.GetColor(_T("comment")));
    SetAStyle(SCE_C_NUMBER, ini.GetColor(_T("number")));
    SetAStyle(SCE_C_STRING, ini.GetColor(_T("string")));
    SetAStyle(SCE_C_CHARACTER, ini.GetColor(_T("string")));
    SetAStyle(SCE_C_UUID, ini.GetColor(_T("uuid")));
    SetAStyle(SCE_C_OPERATOR, ini.GetColor(_T("operators")));
    SetAStyle(SCE_C_PREPROCESSOR, ini.GetColor(_T("preprocessor")));
    SetAStyle(SCE_C_WORD, ini.GetColor(_T("keywords")));
    //SetAStyle(SCE_C_WORD2, ini.GetColor(_T("keywords")));
}

This is method where I'm setting up editor for language (reading colors from ini files). I already checked and color is written in ini file and all other colors work (comments, operators, etc).

Edit: Code for tab width, lexer, etc...

void ScintillaCtrl::LoadDefaultState()
{
    SendEditor(SCI_SETLEXER, SCLEX_NULL);
    SendEditor(SCI_SETTABWIDTH,4);
    SetAStyle(STYLE_DEFAULT, RGB(0, 0, 0), RGB(255, 255, 255), 10, "Arial");
    SendEditor(SCI_SETCARETFORE, RGB(0, 0, 0));
    SendEditor(SCI_STYLECLEARALL, NULL);
    SendEditor(SCI_SETSELBACK, TRUE, ini.GetColor(_T("selection")));
}

Managed to solve it. Problem was that i was sending keywords in wide char (unicode) to Scintilla, but it only accepts them in char, so when i changed it to char it worked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM