Scintilla在WTL中的简易使用

Scintilla在WTL中的简易使用

Scintilla是一个开源的源代码编辑组件。在这里记录下它在WTL中的简易使用。

在 WTL 中使用 Scintilla 的一个比较成功的案例是pnotepadProgrammer's Notepad Development

大家可以访问 http://code.google.com/p/pnotepad/ ,不过其现在代码庞大,阅读有一定难度。

现提供一玩具级的演示示例,如下:

下面将简单介绍在WTLSDI框架下如何使用Scintilla。本文使用的是Scintilla 3.2.5。

1.   下载Scintilla源代码(http://www.scintilla.org/ScintillaDownload.html

编译参照 Scintilla 3.2.5在VC中的编译(动态、静态)

本文使用3.2.5版本

2.新建一WTL SDI项目,如:WtlScintillaSDI


3.(动态、静态) 使用 Scintilla 代码初始化。

在 WtlScintillaSDI.cpp 中添加如下代码:

#ifdef STATIC_BUILD_SCI
#include "Scintilla.h"
#endif
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow)
{
#ifdef STATIC_BUILD_SCI
	Scintilla_RegisterClasses( hInstance );
#else
    HMODULE m_hSciLexerDll = NULL;
	m_hSciLexerDll = LoadLibrary(_T("SciLexer.dll"));
	if (NULL == m_hSciLexerDll)
	{
		MessageBox( NULL, _T("LoadLibrary SciLexer.dll failure..."), _T("Error"), MB_ICONSTOP | MB_OK );
		return FALSE;
	}
#endif

	HRESULT hRes = ::CoInitialize(NULL);
// If you are running on NT 4.0 or higher you can use the following call instead to 
// make the EXE free threaded. This means that calls come in on a random RPC thread.
//	HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
	ATLASSERT(SUCCEEDED(hRes));

	// this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used
	::DefWindowProc(NULL, 0, 0, 0L);

	AtlInitCommonControls(ICC_COOL_CLASSES | ICC_BAR_CLASSES);	// add flags to support other controls

	hRes = _Module.Init(NULL, hInstance);
	ATLASSERT(SUCCEEDED(hRes));

	int nRet = Run(lpstrCmdLine, nCmdShow);

	_Module.Term();
	::CoUninitialize();

#ifdef STATIC_BUILD_SCI
	Scintilla_ReleaseResources();
#else
	if( m_hSciLexerDll != NULL )
	{
		::FreeLibrary( m_hSciLexerDll );
	}
#endif

	return nRet;
}

4. 在 WtlScintillaSDIView.h 增加一 Scintilla 封装类,继承自CWindowImpl,如 CScintillaWnd

#include "Scintilla.h"
#include "SciLexer.h"

class CScintillaWnd : public CWindowImpl<CScintillaWnd>
{
public:
	DECLARE_WND_CLASS(NULL)

	CScintillaWnd()
	{
	}

	BEGIN_MSG_MAP(CScintillaWnd)
	END_MSG_MAP()


	HWND Create( HWND hWndParent, const ATL::_U_RECT& rect, DWORD dwExStyle = 0 )
	{
		// TODO: 在此添加专用代码和/或调用基类
		return CWindow::Create( _T("Scintilla"), hWndParent, rect, _T(""), WS_CHILD | WS_VISIBLE, dwExStyle );
	}


	/
	// @mfunc init the view with reasonable defaults
	// @rvalue void | not used
	//
	void Init()
	{
		// clear all text styles
		SendMessage(SCI_CLEARDOCUMENTSTYLE, 0, 0);
		// set the numbe
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值