Scintilla - An excellent source editting control

      Scintilla is a free source editing component written in c++,it's fully open source and you can distribute it anywhere  commercially or non-commercially under its license.
      Scintilla includes features especially useful when editing and debugging source code.These includes syntax styling,error indicators,code indication and call tips.The selection can contain markers like those used in debuggers to indicate the breakpoint and the current line.Scintilla provides a huge amount of user customization .The user can make even more styling choices then other editors.including propotional fonts,bold and italics,multiple foreground and background colors and fonts.
      You can find its full information at http://www.scintilla.org/index.html.
      Here,I'll demo how to use it in MFC dialog program ,for more detailed usage ,please turn to its website given above.
      First,download scintilla src package and extract it somewhere as you like.Open visual c++ 6.0 and create a dialog-based application using App Wizard.Add include subfolder into ur project as well as the SciLexer.dll.
      Let's go on.Add a HMODULE member to your CWinApp derived class,suppose it's m_hScitilla.In InitInstance function,add :
1    m_hScitilla = LoadLibrary( " SciLexer.dll);
2    if (m_hScitilla   ==  NULL){
3      // Quit ??   As ur will!
4   }
       Remember to free the library in ExitInstance funciton:
1  if (m_hScitilla  !=  NULL){
2    FreeLibrary(m_hScitilla);
3    m_hScitilla = NULL;
4  }
     The DLL will register a new class called "Scitilla" if it is loaded successfully.Now you can use this new control just like any other windows controls.
1  hWndSci  =  CreateWindowEx( 0 , " Scintilla " , "" ,
2            WS_CHILD  |  WS_VISIBLE  |  WS_TABSTOP  |  WS_CLIPCHILDREN,
3         10 , 10 , 500 , 400 ,hwndParent,(HMENU)GuiID, hInstance,NULL);
      You can control the edit by sending commands.There are two ways to do that:A simple way and a fast way.
      The simple ways is just like with any other windows.You can send messages to Scintilla Edit control and receive notifications from it ,note that the notification message is sent to its parent window.
      For example,you can use  SendMessage(hWndScintilla,SCI_CREATEDOCUMENT, 0, 0) to ask scintilla to create a new document.
      Some of the commands will return a value and unused parameters should be set to NULL.
      The fast way to control scintilla edit control is to call message handling functions by yourself.You can retrieve the pointer of the message handling
funciton of Scintilla and call it directly to execute a command.
      You have to use SCI_GETDIRECTFUNCTION and SCI_GETDIRECTPOINTER commands to retrieve the pointer to the function and a pointer which
must be the first parameter when calling the retrieved function pointer.YOu have to do this with the SendMessage way.The whole things will be like this:
ContractedBlock.gif ExpandedBlockStart.gif Code
1 int (*fn)(void*,int,int,int);
2 void * ptr;
3 int canundo;
4 fn = (int (__cdecl *)(void *,int,int,int))
5       SendMessage(hwndScintilla,SCI_GETDIRECTFUNCTION,0,0);
6 ptr = (void *)SendMessage(hwndScintilla,SCI_GETDIRECTPOINTER,0,0);
7 canundo = fn(ptr,SCI_CANUNDO,0,0
      References:www.scitilla.org
  Scintilla的windows版本是一个windows控件,所以其主要编程接口都是通过消息机制来实现的.早期的Scintilla版本模仿了标准的windows Edit和RichEdit控件定义的大部分API实现,然而现代这些API在Scintilla中都被摒弃,而改用Scintilla自己的API.
  GTK版本使用了与windows版本类似的消息机制,这与一般的GTK设计方法不同但是更易于快速实现.

转载于:https://www.cnblogs.com/cmleung/archive/2009/09/19/1570031.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值