vc win32 Scintilla编辑器

48 篇文章 0 订阅
7 篇文章 0 订阅

参考: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;

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值