⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scintillawnd.cpp

📁 一个可以提供语法高亮显示的编辑器
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	SendMessage(SCI_SETMARGINSENSITIVEN, 2, TRUE);
// define a set of markers to displa folding symbols
   SendMessage(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEROPEN, SC_MARK_MINUS);
   SendMessage(SCI_MARKERDEFINE, SC_MARKNUM_FOLDER, SC_MARK_PLUS);
   SendMessage(SCI_MARKERDEFINE, SC_MARKNUM_FOLDERSUB, SC_MARK_EMPTY);
   SendMessage(SCI_MARKERDEFINE, SC_MARKNUM_FOLDERTAIL, SC_MARK_EMPTY);
   SendMessage(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEREND, SC_MARK_EMPTY);
   SendMessage(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEROPENMID, SC_MARK_EMPTY);
   SendMessage(SCI_MARKERDEFINE, SC_MARKNUM_FOLDERMIDTAIL, SC_MARK_EMPTY);
// set the forground color for some styles
   SendMessage(SCI_STYLESETFORE, 0, RGB(0,0,0));
   SendMessage(SCI_STYLESETFORE, 2, RGB(0,64,0));
   SendMessage(SCI_STYLESETFORE, 5, RGB(0,0,255));
   SendMessage(SCI_STYLESETFORE, 6, RGB(200,20,0));
   SendMessage(SCI_STYLESETFORE, 9, RGB(0,0,255));
   SendMessage(SCI_STYLESETFORE, 10, RGB(255,0,64));
   SendMessage(SCI_STYLESETFORE, 11, RGB(0,0,0));
// set the backgroundcolor of brace highlights
   SendMessage(SCI_STYLESETBACK, STYLE_BRACELIGHT, RGB(0,255,0));
// set end of line mode to CRLF
   SendMessage(SCI_CONVERTEOLS, 2, 0);
   SendMessage(SCI_SETEOLMODE, 2, 0);
//   SendMessage(SCI_SETVIEWEOL, TRUE, 0);
// set markersymbol for marker type 0 - bookmark
   SendMessage(SCI_MARKERDEFINE, 0, SC_MARK_CIRCLE);
// display all margins
   SetDisplayLinenumbers(TRUE);
   SetDisplayFolding(TRUE);
   SetDisplaySelection(TRUE);

}
/////////////////////////////////////
// @mfunc Update UI and do brace matching
// @rvalue void | not used
//
void CScintillaWnd::UpdateUI()
{
// do brace matching
   long lStart = SendMessage(SCI_GETCURRENTPOS, 0, 0);
   long lEnd = SendMessage(SCI_BRACEMATCH, lStart-1, 0);
// if there is a matching brace highlight it
   if (lEnd >= 0)
      SendMessage(SCI_BRACEHIGHLIGHT, lStart-1, lEnd);
// if there is NO matching brace erase old highlight
   else
      SendMessage(SCI_BRACEHIGHLIGHT, -1, -1);
}
/////////////////////////////////////
// @mfunc Do default folding for given margin and position - usually called from notification handler
// @rvalue void | not used
//
void CScintillaWnd::DoDefaultFolding(
                                     int nMargin,      //@parm maring we want to handle - normally (2)
                                     long lPosition)   //@parm character position where user clicked margin
{
// simply toggle fold
   if (nMargin == 2)
   {
      long lLine = SendMessage(SCI_LINEFROMPOSITION, lPosition, 0);
      SendMessage(SCI_TOGGLEFOLD, lLine, 0);
   }
}
/////////////////////////////////////
// @mfunc Do default folding for given margin and position - usually called from notification handler
// @rvalue void | not used
//
void CScintillaWnd::Refresh()
{
   SendMessage(SCI_COLOURISE, 0, -1);
}
/////////////////////////////////////
// @mfunc Add a bookmark at given line
// @rvalue void | not used
//
void CScintillaWnd::AddBookmark(
                                long lLine) //@parm line where to add bookmark - lines start at 1
{
   SendMessage(SCI_MARKERADD, lLine-1, 0);
}
/////////////////////////////////////
// @mfunc Delete a bookmark at given line
// @rvalue void | not used
//
void CScintillaWnd::DeleteBookmark(
                                   long lLine) //@parm line where to delete bookmark - lines start at 1
{
   if (HasBookmark(lLine))
   {
      SendMessage(SCI_MARKERDELETE, lLine-1, 0);
   }
}
/////////////////////////////////////
// @mfunc Check if given line has a bookmark
// @rvalue BOOL | TRUE if given line has a bookmark - else FALSE
//
BOOL CScintillaWnd::HasBookmark(
                                long lLine) //@parm line where to add bookmark - lines start at 1
{
   int n = SendMessage(SCI_MARKERGET, lLine-1, 0);
// check mask for markerbit 0
   if (n & 0x1)
      return TRUE;
   return FALSE;
}
/////////////////////////////////////
// @mfunc Find next bookmark from current line
// @rvalue void | not used
//
void CScintillaWnd::FindNextBookmark()
{
	long lLine = SendMessage(SCI_MARKERNEXT, GetCurrentLine(), 1);
   if (lLine >= 0)
      SendMessage(SCI_GOTOLINE, lLine,0);
}
/////////////////////////////////////
// @mfunc Find previous bookmark from current line
// @rvalue void | not used
//
void CScintillaWnd::FindPreviousBookmark()
{
	long lLine = SendMessage(SCI_MARKERPREVIOUS, GetCurrentLine()-2, 1);
   if (lLine >= 0)
      SendMessage(SCI_GOTOLINE, lLine,0);
}
/////////////////////////////////////
// @mfunc Goto givven character position
// @rvalue void | not used
//
void CScintillaWnd::GotoPosition(
                                 long lPos) //@parm new character position
{
	SendMessage(SCI_GOTOPOS, lPos, 0);
}
/////////////////////////////////////
// @mfunc Goto givven line position
// @rvalue void | not used
//
void CScintillaWnd::GotoLine(
                             long lLine) //@parm new line - lines start at 1
{
	SendMessage(SCI_GOTOLINE, lLine-1, 0);
}
/////////////////////////////////////
// @mfunc Search forward for a given string and select it if found. You may use regular expressions on the text.
// @rvalue BOOL | TRUE if text is ffound else FALSE
//
BOOL CScintillaWnd::SearchForward(
                                  LPSTR szText) //@parm text to search
{
   if (szText == NULL)
      return FALSE;
   long lPos = GetCurrentPosition();
   TextToFind tf;
   tf.lpstrText = szText;
   tf.chrg.cpMin = lPos+1;
   tf.chrg.cpMax = SendMessage(SCI_GETLENGTH, 0, 0);
   lPos = SendMessage(SCI_FINDTEXT, m_nSearchflags, (long)&tf);
   if (lPos >= 0)
   {
      SetFocus();
      GotoPosition(lPos);
      SendMessage(SCI_SETSEL, tf.chrgText.cpMin, tf.chrgText.cpMax);
      SendMessage(SCI_FINDTEXT, m_nSearchflags, (long)&tf);
      return TRUE;
   }
   return FALSE;
}
/////////////////////////////////////
// @mfunc Search backward for a given string and select it if found. You may use regular expressions on the text.
// @rvalue BOOL | TRUE if text is ffound else FALSE
//
BOOL CScintillaWnd::SearchBackward(
                                  LPSTR szText) //@parm text to search
{
   if (szText == NULL)
      return FALSE;
   long lPos = GetCurrentPosition();
   long lMinSel = GetSelectionStart();
   TextToFind tf;
   tf.lpstrText = szText;
   if (lMinSel >= 0)
      tf.chrg.cpMin = lMinSel-1;
   else
      tf.chrg.cpMin = lPos-1;
   tf.chrg.cpMax = 0;
   lPos = SendMessage(SCI_FINDTEXT, m_nSearchflags, (long)&tf);
   if (lPos >= 0)
   {
      SetFocus();
      GotoPosition(lPos);
      SendMessage(SCI_SETSEL, tf.chrgText.cpMin, tf.chrgText.cpMax);
      SendMessage(SCI_FINDTEXT, m_nSearchflags, (long)&tf);
      return TRUE;
   }
   return FALSE;
}
/////////////////////////////////////
// @mfunc Replace a text with a new text. You can use regular expression with tagging on the replacement text.
// @rvalue void | not used
//
void CScintillaWnd::ReplaceSearchedText(
                                        LPCSTR szText) //@parm new text
{
   if (szText == NULL)
      return;
	SendMessage(SCI_TARGETFROMSELECTION, 0, 0);
   if (m_nSearchflags & SCFIND_REGEXP)
      SendMessage(SCI_REPLACETARGETRE, strlen(szText), (long)szText);
   else
      SendMessage(SCI_REPLACETARGET, strlen(szText), (long)szText);
}
/////////////////////////////////////
// @mfunc Set lexer format - see scintilla.h
// @rvalue void | not used
//
void CScintillaWnd::SetLexer(
                             int nLexer) //@parm lexer code e.g. 
{
   SendMessage(SCI_SETLEXER, nLexer, 0);
}
/////////////////////////////////////
// @mfunc Get start of selection (anchor) as character position
// @rvalue long | character position of selection start (anchor) - -1 on error
//
long CScintillaWnd::GetSelectionStart()
{
   return SendMessage(SCI_GETSELECTIONSTART, 0, 0);
}
/////////////////////////////////////
// @mfunc Get end of selection as character position
// @rvalue long | character position of selection end - -1 on error
//
long CScintillaWnd::GetSelectionEnd()
{
   return SendMessage(SCI_GETSELECTIONEND, 0, 0);
}
/////////////////////////////////////
// @mfunc Get selected string
// @rvalue CString | string with currentliy selected text
//
CString CScintillaWnd::GetSelectedText()
{
   long lLen = (GetSelectionEnd() - GetSelectionStart()) + 1;
   if (lLen > 0)
   {
      TCHAR *p = new TCHAR[lLen+1];
      if (p != NULL)
      {
         *p = '\0';
         SendMessage(SCI_GETSELTEXT, 0, (long)p);
         CString strReturn = p;
         delete [] p;
         return strReturn;
      }
   }
   return _T("");
}
/////////////////////////////////////
// @mfunc Replace a text in a selection or in the complete file multiple times
// @rvalue int | number of replacements
//
int CScintillaWnd::ReplaceAll(
                              LPCSTR szFind, 
                              LPCSTR szReplace, 
                              BOOL bUseSelection)
{
   int nCount = 0;
// different branches for replace in selection or total file
   if (bUseSelection)
   {
//    get starting selection range
      long lLen = 0;
      long lStart = GetSelectionStart();
      long lEnd = GetSelectionEnd();
//    set target to selection
      SendMessage(SCI_SETTARGETSTART, lStart);
      SendMessage(SCI_SETTARGETEND, lEnd);
//    try to find text in target for the first time
	   long lPos = SendMessage(SCI_SEARCHINTARGET, strlen(szFind), (long)szFind);
//    loop over selection until end of selection reached - moving the target start each time
      while (lPos < lEnd && lPos >= 0)
      {
         if (m_nSearchflags & SCFIND_REGEXP) // check for regular expression flag
            lLen = SendMessage(SCI_REPLACETARGETRE, strlen(szReplace), (long)szReplace);
         else
            lLen = SendMessage(SCI_REPLACETARGET, strlen(szReplace), (long)szReplace);
//       the end of the selection was changed - recalc the end
         lEnd = GetSelectionEnd();
//       move start of target behind last change and end of target to new end of selection
         SendMessage(SCI_SETTARGETSTART, lPos+lLen);
         SendMessage(SCI_SETTARGETEND, lEnd);
//       find again - if nothing found loop exits
	      lPos = SendMessage(SCI_SEARCHINTARGET, strlen(szFind), (long)szFind);
         nCount++;
      }
   }
   else
   {
//    start with first and last char in buffer
      long lLen = 0;
      long lStart = 0;
      long lEnd = SendMessage(SCI_GETTEXTLENGTH, 0, 0);
//    set target to selection
      SendMessage(SCI_SETTARGETSTART, lStart, 0);
      SendMessage(SCI_SETTARGETEND, lEnd, 0);
//    try to find text in target for the first time
	   long lPos = SendMessage(SCI_SEARCHINTARGET, strlen(szFind), (long)szFind);
//    loop over selection until end of selection reached - moving the target start each time
      while (lPos < lEnd && lPos >= 0)
      {
         if (m_nSearchflags & SCFIND_REGEXP) // check for regular expression flag
            lLen = SendMessage(SCI_REPLACETARGETRE, strlen(szReplace), (long)szReplace);
         else
            lLen = SendMessage(SCI_REPLACETARGET, strlen(szReplace), (long)szReplace);
//       the end of the selection was changed - recalc the end
         lEnd = SendMessage(SCI_GETTEXTLENGTH, 0, 0);;
//       move start of target behind last change and end of target to new end of buffer
         SendMessage(SCI_SETTARGETSTART, lPos+lLen);
         SendMessage(SCI_SETTARGETEND, lEnd);
//       find again - if nothing found loop exits
	      lPos = SendMessage(SCI_SEARCHINTARGET, strlen(szFind), (long)szFind);
         nCount++;
      }
   }
   return nCount;
}




⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -