分享
 
 
 

BCB中封装VC控件CodeSense

王朝vc·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

Q: http://community.csdn.net/Expert/topic/3179/3179109.xml?temp=.7848627

作者想要一个ocx的解决方案,我没有给出来。bcb在这个方面一直是诟病多多,呵呵。不过他的那个控件是open source的。原作者使用vc+mfc来开发的,不过接口就是api+消息了。这样的使用vcl来封装这个控件变得不是十分困难了。

CodeSense 是一个源码着色的编辑控件。

这是原文件的下载地址。

http://www.ticz.com/homes/users/nlewis/HTML/Software_Development/CodeSense/Download/CodeSense/cmcs222.zip

使用之前你需要用implib -a cmcs21.lib cmcs21.dll 来导出import library。

以下我做的封装:

#include <vcl.h>

#define _T //added by cker. A dirty hack.

#include "CodeSense.h"

#include <assert.h>

#define ASSERT assert

class TCodeSenseCtrl : public TWinControl

{

protected:

virtual void __fastcall CreateParams(Controls::TCreateParams &Params)

{

CMRegisterControl();

TWinControl::CreateParams(Params);

CreateSubClass(Params, CODESENSEWNDCLASS);

}

public:

__fastcall virtual TCodeSenseCtrl(TComponent* AOwner) : TWinControl(AOwner)

{

}

__fastcall virtual ~TCodeSenseCtrl()

{

CMUnregisterControl();

}

public:

CME_CODE SetLanguage( LPCTSTR pszName )

{

return CM_SetLanguage( Handle, pszName );

}

CME_CODE GetLanguage( LPTSTR pszName )

{

return CM_GetLanguage( Handle, pszName );

}

CME_CODE EnableColorSyntax( BOOL bEnable = TRUE )

{

return CM_EnableColorSyntax( Handle, bEnable );

}

BOOL IsColorSyntaxEnabled()

{

return CM_IsColorSyntaxEnabled( Handle );

}

CME_CODE OpenFile( LPCTSTR pszFileName )

{

return CM_OpenFile( Handle, pszFileName );

}

CME_CODE InsertFile( LPCTSTR pszFileName, const CM_POSITION *pPos = NULL )

{

return CM_InsertFile( Handle, pszFileName, pPos );

}

CME_CODE InsertText( LPCTSTR pszText, const CM_POSITION *pPos = NULL )

{

return CM_InsertText( Handle, pszText, pPos );

}

CME_CODE SetText( LPCTSTR pszText )

{

return CM_SetText( Handle, pszText );

}

CME_CODE SetColors( const CM_COLORS *pColors )

{

return CM_SetColors( Handle, pColors );

}

CME_CODE GetColors( CM_COLORS *pColors )

{

return CM_GetColors( Handle, pColors );

}

CME_CODE EnableWhitespaceDisplay( BOOL bEnable = TRUE )

{

return CM_EnableWhitespaceDisplay( Handle, bEnable );

}

BOOL IsWhitespaceDisplayEnabled()

{

return CM_IsWhitespaceDisplayEnabled( Handle );

}

CME_CODE EnableTabExpand( BOOL bEnable = TRUE )

{

return CM_EnableTabExpand( Handle, bEnable );

}

BOOL IsTabExpandEnabled()

{

return CM_IsTabExpandEnabled( Handle );

}

CME_CODE EnableSmoothScrolling( BOOL bEnable = TRUE )

{

return CM_EnableSmoothScrolling( Handle, bEnable );

}

BOOL IsSmoothScrollingEnabled()

{

return CM_IsSmoothScrollingEnabled( Handle );

}

CME_CODE SetTabSize( int nTabSize )

{

return CM_SetTabSize( Handle, nTabSize );

}

int GetTabSize()

{

return CM_GetTabSize( Handle );

}

CME_CODE SetReadOnly( BOOL bReadOnly = TRUE )

{

return CM_SetReadOnly( Handle, bReadOnly );

}

BOOL IsReadOnly()

{

return CM_IsReadOnly( Handle );

}

CME_CODE EnableLineToolTips( BOOL bEnable = TRUE )

{

return CM_EnableLineToolTips( Handle, bEnable );

}

BOOL IsLineToolTipsEnabled()

{

return CM_IsLineToolTipsEnabled( Handle );

}

CME_CODE EnableLeftMargin( BOOL bEnable = TRUE )

{

return CM_EnableLeftMargin( Handle, bEnable );

}

BOOL IsLeftMarginEnabled()

{

return CM_IsLeftMarginEnabled( Handle );

}

CME_CODE SaveFile( LPCTSTR pszFileName, BOOL bClearUndo = TRUE )

{

return CM_SaveFile( Handle, pszFileName, bClearUndo );

}

CME_CODE ReplaceText( LPCTSTR pszText, const CM_RANGE *pRange = NULL )

{

return CM_ReplaceText( Handle, pszText, pRange );

}

int GetTextLength( const CM_RANGE *pRange = NULL, BOOL bLogical = FALSE )

{

return CM_GetTextLength( Handle, pRange, bLogical );

}

CME_CODE GetText( LPTSTR pszBuff, const CM_RANGE *pRange = NULL )

{

return CM_GetText( Handle, pszBuff, pRange );

}

// CME_CODE GetText( CString &strText, const CM_RANGE *pRange = NULL )

// { ASSERT( ::IsWindow( Handle ) );

// CME_CODE nCode = CM_GetText( Handle, strText.GetBufferSetLength( GetTextLength( pRange ) + 1 ), pRange );

// strText.ReleaseBuffer();

// return nCode; }

CME_CODE GetLine( int nLine, LPTSTR pszBuff )

{

return CM_GetLine( Handle, nLine, pszBuff );

}

// CME_CODE GetLine( int nLine, CString &strLine )

// { ASSERT( ::IsWindow( Handle ) );

// CME_CODE nCode = CM_GetLine( Handle, nLine, strLine.GetBufferSetLength( GetLineLength( nLine ) + 1 ) );

// strLine.ReleaseBuffer();

// return nCode; }

int GetLineCount()

{

return CM_GetLineCount( Handle );

}

int GetLineLength( int nLine, BOOL bLogical = FALSE )

{

return CM_GetLineLength( Handle, nLine, bLogical );

}

CME_CODE GetWord( LPTSTR pszBuff, CM_POSITION *pPos )

{

return CM_GetWord( Handle, pszBuff, pPos );

}

// CME_CODE GetWord( CString &strWord, CM_POSITION *pPos )

// { ASSERT( ::IsWindow( Handle ) );

// CME_CODE nCode = CM_GetWord( Handle, strWord.GetBufferSetLength( GetWordLength( pPos ) + 1 ), pPos );

// strWord.ReleaseBuffer();

// return nCode; }

int GetWordLength( CM_POSITION *pPos, BOOL bLogical = FALSE )

{

return CM_GetWordLength( Handle, pPos, bLogical );

}

CME_CODE AddText( LPCTSTR pszText )

{

return CM_AddText( Handle, pszText );

}

CME_CODE DeleteLine( int nLine )

{

return CM_DeleteLine( Handle, nLine );

}

CME_CODE InsertLine( int nLine, LPCTSTR pszText )

{

return CM_InsertLine( Handle, nLine, pszText );

}

CME_CODE GetSel( CM_RANGE *pRange, BOOL bNormalized = TRUE )

{

return CM_GetSel( Handle, pRange, bNormalized );

}

CME_CODE SetSel( const CM_RANGE *pRange, BOOL bMakeVisible = TRUE )

{

return CM_SetSel( Handle, pRange, bMakeVisible );

}

CME_CODE DeleteSel()

{

return CM_DeleteSel( Handle );

}

CME_CODE ReplaceSel( LPCTSTR pszText )

{

return CM_ReplaceSel( Handle, pszText );

}

CME_CODE ExecuteCmd( WORD wCmd, DWORD dwCmdData = 0 )

{

return CM_ExecuteCmd( Handle, wCmd, dwCmdData );

}

CME_CODE SetSplitterPos( BOOL bHorz, int nPos )

{

return CM_SetSplitterPos( Handle, bHorz, nPos );

}

int GetSplitterPos( BOOL bHorz )

{

return CM_GetSplitterPos( Handle, bHorz );

}

CME_CODE SetAutoIndentMode( int nMode )

{

return CM_SetAutoIndentMode( Handle, nMode );

}

int GetAutoIndentMode()

{

return CM_GetAutoIndentMode( Handle );

}

BOOL CanCopy()

{

return CM_CanCopy( Handle );

}

BOOL CanCut()

{

return CM_CanCut( Handle );

}

BOOL CanPaste()

{

return CM_CanPaste( Handle );

}

CME_CODE Copy()

{

return CM_Copy( Handle );

}

CME_CODE Cut()

{

return CM_Cut( Handle );

}

CME_CODE Paste()

{

return CM_Paste( Handle );

}

BOOL CanUndo()

{

return CM_CanUndo( Handle );

}

BOOL CanRedo()

{

return CM_CanRedo( Handle );

}

CME_CODE Redo()

{

return CM_Redo( Handle );

}

CME_CODE Undo()

{

return CM_Undo( Handle );

}

CME_CODE ClearUndoBuffer()

{

return CM_ClearUndoBuffer( Handle );

}

CME_CODE SetUndoLimit( int nLimit )

{

return CM_SetUndoLimit( Handle, nLimit );

}

int GetUndoLimit()

{

return CM_GetUndoLimit( Handle );

}

BOOL IsModified()

{

return CM_IsModified( Handle );

}

CME_CODE SetModified( BOOL bModified = TRUE )

{

return CM_SetModified( Handle, bModified );

}

CME_CODE EnableOvertype( BOOL bEnable = TRUE )

{

return CM_EnableOvertype( Handle, bEnable );

}

BOOL IsOvertypeEnabled()

{

return CM_IsOvertypeEnabled( Handle );

}

CME_CODE EnableCaseSensitive( BOOL bEnable = TRUE )

{

return CM_EnableCaseSensitive( Handle, bEnable );

}

BOOL IsCaseSensitiveEnabled()

{

return CM_IsCaseSensitiveEnabled( Handle );

}

CME_CODE EnablePreserveCase( BOOL bEnable = TRUE )

{

return CM_EnablePreserveCase( Handle, bEnable );

}

BOOL IsPreserveCaseEnabled()

{

return CM_IsPreserveCaseEnabled( Handle );

}

CME_CODE EnableWholeWord( BOOL bEnable = TRUE )

{

return CM_EnableWholeWord( Handle, bEnable );

}

BOOL IsWholeWordEnabled()

{

return CM_IsWholeWordEnabled( Handle );

}

CME_CODE EnableRegExp( BOOL bEnable = TRUE )

{

return CM_EnableRegExp( Handle, bEnable );

}

BOOL IsRegExpEnabled()

{

return CM_IsRegExpEnabled( Handle );

}

CME_CODE SetTopIndex( int nView, int nLine )

{

return CM_SetTopIndex( Handle, nView, nLine );

}

int GetTopIndex( int nView )

{

return CM_GetTopIndex( Handle, nView );

}

int GetVisibleLineCount( int nView, BOOL bFullyVisible = TRUE )

{

return CM_GetVisibleLineCount( Handle, nView, bFullyVisible );

}

CME_CODE EnableCRLF( BOOL bEnable = TRUE )

{

return CM_EnableCRLF( Handle, bEnable );

}

BOOL IsCRLFEnabled()

{

return CM_IsCRLFEnabled( Handle );

}

CME_CODE SetFontOwnership( BOOL bEnable )

{

return CM_SetFontOwnership( Handle, bEnable );

}

BOOL GetFontOwnership()

{

return CM_GetFontOwnership( Handle );

}

int GetCurrentView()

{

return CM_GetCurrentView( Handle );

}

CME_CODE SetCurrentView(int nView)

{

return CM_SetCurrentView( Handle, nView );

}

int GetViewCount()

{

return CM_GetViewCount( Handle );

}

CME_CODE ShowScrollBar( BOOL bHorz, BOOL bShow = TRUE )

{

return CM_ShowScrollBar( Handle, bHorz, bShow );

}

BOOL HasScrollBar( BOOL bHorz )

{

return CM_HasScrollBar( Handle, bHorz );

}

CME_CODE GetSelFromPoint( int xClient, int yClient, CM_POSITION *pPos )

{

return CM_GetSelFromPoint( Handle, xClient, yClient, pPos );

}

CME_CODE SelectLine( int nLine, BOOL bMakeVisible = TRUE )

{

return CM_SelectLine( Handle, nLine, bMakeVisible );

}

int HitTest( int xClient, int yClient )

{

return CM_HitTest( Handle, xClient, yClient );

}

CME_CODE EnableDragDrop( BOOL bEnable = TRUE )

{

return CM_EnableDragDrop( Handle, bEnable );

}

BOOL IsDragDropEnabled()

{

return CM_IsDragDropEnabled( Handle );

}

CME_CODE EnableSplitter( BOOL bHorz, BOOL bEnable = TRUE )

{

return CM_EnableSplitter( Handle, bHorz, bEnable );

}

BOOL IsSplitterEnabled( BOOL bHorz )

{

return CM_IsSplitterEnabled( Handle, bHorz );

}

CME_CODE EnableColumnSel( BOOL bEnable = TRUE )

{

return CM_EnableColumnSel( Handle, bEnable );

}

BOOL IsColumnSelEnabled()

{

return CM_IsColumnSelEnabled( Handle );

}

CME_CODE EnableGlobalProps( BOOL bEnable = TRUE )

{

return CM_EnableGlobalProps( Handle, bEnable );

}

BOOL IsGlobalPropsEnabled()

{

return CM_IsGlobalPropsEnabled( Handle );

}

BOOL IsRecordingMacro()

{

return CM_IsRecordingMacro( Handle );

}

BOOL IsPlayingMacro()

{

return CM_IsPlayingMacro( Handle );

}

CME_CODE SetDlgParent( HWND *hWnd )

{

return CM_SetDlgParent( Handle, hWnd );

}

CME_CODE EnableSelBounds( BOOL bEnable = TRUE )

{

return CM_EnableSelBounds( Handle, bEnable );

}

BOOL IsSelBoundsEnabled()

{

return CM_IsSelBoundsEnabled( Handle );

}

CME_CODE SetFontStyles( CM_FONTSTYLES *pFontStyles )

{

return CM_SetFontStyles( Handle, pFontStyles );

}

CME_CODE GetFontStyles( CM_FONTSTYLES *pFontStyles )

{

return CM_GetFontStyles( Handle, pFontStyles );

}

CME_CODE SetItemData( int nLine, LPARAM lParam )

{

return CM_SetItemData( Handle, nLine, lParam );

}

LPARAM GetItemData( int nLine )

{

return CM_GetItemData( Handle, nLine );

}

CME_CODE SetLineStyle( int nLine, DWORD dwStyle )

{

return CM_SetLineStyle( Handle, nLine, dwStyle );

}

DWORD GetLineStyle( int nLine )

{

return CM_GetLineStyle( Handle, nLine );

}

CME_CODE SetBookmark( int nLine, BOOL bEnable = TRUE )

{

return CM_SetBookmark( Handle, nLine, bEnable );

}

BOOL GetBookmark( int nLine )

{

return CM_GetBookmark( Handle, nLine );

}

CME_CODE SetAllBookmarks( int nCount, LPDWORD pdwLines )

{

return CM_SetAllBookmarks( Handle, nCount, pdwLines );

}

int GetAllBookmarks( LPDWORD pdwLines )

{

return CM_GetAllBookmarks( Handle, pdwLines );

}

CME_CODE SetLineNumbering( CM_LINENUMBERING *pNumbering )

{

return CM_SetLineNumbering( Handle, pNumbering );

}

CME_CODE GetLineNumbering( CM_LINENUMBERING *pNumbering )

{

return CM_GetLineNumbering( Handle, pNumbering );

}

CME_CODE PosFromChar( CM_POSITION *pPos, LPRECT pRect )

{

return CM_PosFromChar( Handle, pPos, pRect );

}

CME_CODE EnableHideSel( BOOL bEnable = TRUE )

{

return CM_EnableHideSel( Handle, bEnable );

}

BOOL IsHideSelEnabled()

{

return CM_IsHideSelEnabled( Handle );

}

CME_CODE SetHighlightedLine( int nLine )

{

return CM_SetHighlightedLine( Handle, nLine );

}

int GetHighlightedLine()

{

return CM_GetHighlightedLine( Handle );

}

CME_CODE EnableNormalizeCase( BOOL bEnable = TRUE )

{

return CM_EnableNormalizeCase( Handle, bEnable );

}

BOOL IsNormalizeCaseEnabled()

{

return CM_IsNormalizeCaseEnabled( Handle );

}

CME_CODE SetDivider( int nLine, BOOL bEnable = TRUE )

{

return CM_SetDivider( Handle, nLine, bEnable );

}

BOOL GetDivider( int nLine )

{

return CM_GetDivider( Handle, nLine );

}

CME_CODE EnableOvertypeCaret( BOOL bEnable = TRUE )

{

return CM_EnableOvertypeCaret( Handle, bEnable );

}

BOOL IsOvertypeCaretEnabled()

{

return CM_IsOvertypeCaretEnabled( Handle );

}

CME_CODE SetFindText( LPCTSTR pszText )

{

return CM_SetFindText( Handle, pszText );

}

CME_CODE GetFindText( LPTSTR pszText )

{

return CM_GetFindText( Handle, pszText );

}

// CME_CODE GetFindText( CString &strText )

// {

// CME_CODE nCode = CM_GetFindText( Handle, strText.GetBufferSetLength( CM_MAX_FINDREPL_TEXT ) );

// strText.ReleaseBuffer();

// return nCode;

// }

CME_CODE SetReplaceText( LPCTSTR pszText )

{

return CM_SetReplaceText( Handle, pszText );

}

CME_CODE GetReplaceText( LPTSTR pszText )

{

return CM_GetReplaceText( Handle, pszText );

}

// CME_CODE GetReplaceText( CString &strText )

// {

// CME_CODE nCode = CM_GetReplaceText( Handle, strText.GetBufferSetLength( CM_MAX_FINDREPL_TEXT ) );

// strText.ReleaseBuffer();

// return nCode;

// }

CME_CODE SetImageList( HIMAGELIST hImageList )

{

return CM_SetImageList( Handle, hImageList );

}

HIMAGELIST GetImageList()

{

return CM_GetImageList( Handle );

}

CME_CODE SetMarginImages( int nLine, BYTE byImages )

{

return CM_SetMarginImages( Handle, nLine, byImages );

}

BYTE GetMarginImages( int nLine )

{

return CM_GetMarginImages( Handle, nLine );

}

CME_CODE AboutBox()

{

return CM_AboutBox( Handle );

}

CME_CODE Print( HDC hDC, DWORD dwFlags )

{

return CM_Print( Handle, hDC, dwFlags );

}

CME_CODE SetCaretPos( int nLine, int nCol )

{

return CM_SetCaretPos( Handle, nLine, nCol );

}

int ViewColToBufferCol( int nLine, int nViewCol )

{

return CM_ViewColToBufferCol( Handle, nLine, nViewCol );

}

int BufferColToViewCol( int nLine, int nBufferCol )

{

return CM_BufferColToViewCol( Handle, nLine, nBufferCol );

}

CME_CODE SetBorderStyle( DWORD dwStyle )

{

return CM_SetBorderStyle( Handle, dwStyle );

}

DWORD GetBorderStyle()

{

return CM_GetBorderStyle( Handle );

}

DWORD GetCurrentToken()

{

return CM_GetCurrentToken( Handle );

}

void UpdateControlPositions()

{

CM_UpdateControlPositions( Handle );

}

};

注释掉的是关于Cstring的部分,没什么大意义。懒得再写AnsiString的封装了。

下面是调用示例:

//----------------------------------------------------------------------

#include <vcl.h>

#pragma hdrstop

#include "Unit1.h"

#include "CodeSense.h"

#include "TCodeSenseCtrl.h"

//----------------------------------------------------------------------

#pragma package(smart_init)

#pragma resource "*.dfm"

TForm1 *Form1;

//----------------------------------------------------------------------

TCodeSenseCtrl* s;

__fastcall TForm1::TForm1(TComponent* Owner)

: TForm(Owner)

{

}

//----------------------------------------------------------------------

void __fastcall TForm1::FormDestroy(TObject *Sender)

{

delete s;

}

//----------------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender)

{

s = new TCodeSenseCtrl(this);

Panel1->DoubleBuffered = true;

s->Parent = Panel1;

s->Align = alClient;

s->Visible = true;

s->SetLanguage(CMLANG_CPP);

s->EnableColorSyntax();

s->ShowScrollBar(false);

s->ShowScrollBar(true);

s->EnableSplitter(false,true);

s->EnableSplitter(true,true);

::SendMessage(Handle,WM_SETFONT,(int)Panel1->Font->Handle,0);

}

//----------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)

{

if(OpenDialog->Execute())

{

s->OpenFile(OpenDialog->FileName.c_str());

}

}

//----------------------------------------------------------------------

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有