参考:http://www.cnblogs.com/superanyi/archive/2011/04/07/2008632.html
环境:xp sp3,vs2008,win32项目,下面主要代码也是从原文复制过来
#include <windows.h>
#include "scintilla/Scintilla.h"
#include "scintilla/SciLexer.h"
LRESULT CALLBACK wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
switch(msg)
{
case WM_CREATE:
return 0;
case WM_PAINT:
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
HWND hWndSci = NULL;
LRESULT SendEditor(UINT Msg,WPARAM wParam = 0L,LPARAM lParam = 0L)
{
return ::SendMessage(hWndSci, Msg, wParam, lParam);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPreInstance, LPSTR lpCmdLine, int nShowCmd)
{
LoadLibrary("SciLexer.dll");
hWndSci = CreateWindow(
"Scintilla",
"windowname",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
if(!hWndSci)
return FALSE;
const char* szKeywords1=
"asm auto break case catch class const "
"const_cast continue default delete do double "
"dynamic_cast else enum explicit extern false "
"for friend goto if inline mutable "
"namespace new operator private protected public "
"register reinterpret_cast return signed "
"sizeof static static_cast struct switch template "
"this throw true try typedef typeid typename "
"union unsigned using virtual volatile while";
const char* szKeywords2=
"bool char float int long short void wchar_t";
// 设置全局风格
SendEditor(SCI_STYLESETFONT, STYLE_DEFAULT,(sptr_t)"Courier New");
SendEditor(SCI_STYLESETSIZE, STYLE_DEFAULT,10);
SendEditor(SCI_STYLECLEARALL);
//C++语法解析
SendEditor(SCI_SETLEXER, SCLEX_CPP);
SendEditor(SCI_SETKEYWORDS, 0, (sptr_t)szKeywords1);//设置关键字
SendEditor(SCI_SETKEYWORDS, 1, (sptr_t)szKeywords2);//设置关键字
// 下面设置各种语法元素风格
SendEditor(SCI_STYLESETFORE, SCE_C_WORD, 0x00FF0000); //关键字
SendEditor(SCI_STYLESETFORE, SCE_C_WORD2, 0x00800080); //关键字
SendEditor(SCI_STYLESETBOLD, SCE_C_WORD2, TRUE); //关键字
SendEditor(SCI_STYLESETFORE, SCE_C_STRING, 0x001515A3); //字符串
SendEditor(SCI_STYLESETFORE, SCE_C_CHARACTER, 0x001515A3); //字符
SendEditor(SCI_STYLESETFORE, SCE_C_PREPROCESSOR, 0x00808080);//预编译开关
SendEditor(SCI_STYLESETFORE, SCE_C_COMMENT, 0x00008000);//块注释
SendEditor(SCI_STYLESETFORE, SCE_C_COMMENTLINE, 0x00008000);//行注释
SendEditor(SCI_STYLESETFORE, SCE_C_COMMENTDOC, 0x00008000);//文档注释(/**开头)
SendEditor(SCI_SETCARETLINEVISIBLE, TRUE);
SendEditor(SCI_SETCARETLINEBACK, 0xb0ffff);
ShowWindow(hWndSci, SW_SHOW);
UpdateWindow(hWndSci);
MSG msg;
while(GetMessage(&msg, (HWND)NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}