Esempio n. 1
0
void CInputRichEdit::SetFontSize( UINT fontsize )
{
	CHARFORMAT cf;
	memset(&cf, 0, sizeof(CHARFORMAT));

	GetDefaultCharFormat(cf);
	cf.yHeight = fontsize * 15;
	m_stFont.font_size = fontsize;

	SetDefaultCharFormat(cf);
}
Esempio n. 2
0
void CInputRichEdit::SetFontColor( COLORREF crColor )
{
	CHARFORMAT cf;
	memset(&cf, 0, sizeof(CHARFORMAT));

	GetDefaultCharFormat(cf);
	cf.dwEffects &= ~CFE_AUTOCOLOR;
	cf.crTextColor = crColor;
	m_stFont.font_color = crColor;

	SetDefaultCharFormat(cf);
}
Esempio n. 3
0
/////////////////////////////////////////////////////////////////////////////
// COutputCtrl message handlers
BOOL COutputCtrl::Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID)
{
	dwStyle |= (ES_AUTOVSCROLL | ES_MULTILINE| ES_AUTOHSCROLL | ES_READONLY 
		| WS_BORDER | WS_TABSTOP | WS_VSCROLL | WS_HSCROLL);
	if(!CRichEditCtrl::Create( dwStyle, rect, pParentWnd, nID))
		return FALSE;

	GetDefaultCharFormat(m_fmtCur);	// 获取缺省字体信息

	ResetFormat();					// 初始化字体

	return TRUE;
}
Esempio n. 4
0
void CInputRichEdit::SetDefaultFont(UINT fontsize/* = 12*/)
{
	CHARFORMAT cf;
	memset(&cf, 0, sizeof(CHARFORMAT));

	GetDefaultCharFormat(cf);
	cf.yHeight = fontsize * 15;
	cf.dwEffects &= ~CFE_BOLD;
	cf.dwEffects &= ~CFE_ITALIC;
	cf.dwEffects &= ~CFE_UNDERLINE;
	swprintf_s(cf.szFaceName, L"宋体");

	SetDefaultCharFormat(cf);

	m_stFont.font_size = fontsize;
}
Esempio n. 5
0
void CTWScriptEdit::OnSelectfont() 
{
	// TODO: Add your command handler code here
	CHARFORMAT cf;
	LOGFONT lf;
	memset(&cf, 0, sizeof(CHARFORMAT));
	memset(&lf, 0, sizeof(LOGFONT));
	//判断是否选择了内容
	BOOL m_bSelect = (GetSelectionType() != SEL_EMPTY) ? TRUE : FALSE;
	if (m_bSelect)
	{
		GetSelectionCharFormat(cf);
	}
	else
	{
		GetDefaultCharFormat(cf);
	}
	//得到相关字体属性
	BOOL bIsBold = cf.dwEffects & CFE_BOLD;
	BOOL bIsItalic = cf.dwEffects & CFE_ITALIC;
	BOOL bIsUnderline = cf.dwEffects & CFE_UNDERLINE;
	BOOL bIsStrickout = cf.dwEffects & CFE_STRIKEOUT;
	//设置属性
	lf.lfCharSet = cf.bCharSet;
	lf.lfHeight = cf.yHeight/15;
	lf.lfPitchAndFamily = cf.bPitchAndFamily;
	lf.lfItalic = bIsItalic;
	lf.lfWeight = (bIsBold ? FW_BOLD : FW_NORMAL);
	lf.lfUnderline = bIsUnderline;
	lf.lfStrikeOut = bIsStrickout;
	sprintf(lf.lfFaceName, cf.szFaceName);

	CFontDialog dlg(&lf);
	dlg.m_cf.rgbColors = cf.crTextColor;
	if (dlg.DoModal() == IDOK)
	{
		dlg.GetCharFormat(cf);//获得所选字体的属性
		if (m_bSelect) 
			SetSelectionCharFormat(cf);	//为选定的内容设定所选字体
		else
			SetWordCharFormat(cf);	//为将要输入的内容设定字体
	}



}
Esempio n. 6
0
void CInputRichEdit::SetFontName( std::wstring strFontName )
{
	CHARFORMAT cf;
	memset(&cf, 0, sizeof(CHARFORMAT));

	GetDefaultCharFormat(cf);
	swprintf_s(cf.szFaceName, strFontName.c_str());
	m_stFont.font_type = strFontName;

	//CFontDialog dlg;
	//if (dlg.DoModal() == IDOK)
	//{
	//	dlg.GetCharFormat(cf);
	//}

	SetDefaultCharFormat(cf);
}
Esempio n. 7
0
void CInputRichEdit::SetFontItalic( bool bItalic )
{
	CHARFORMAT cf;
	memset(&cf, 0, sizeof(CHARFORMAT));

	GetDefaultCharFormat(cf);
	if (bItalic)
	{
		cf.dwEffects |= CFE_ITALIC;
		m_stFont.font_style |= core::FONTSTYLETYPE_ITALICS;
	}
	else
	{
		cf.dwEffects &= ~CFE_ITALIC;
		m_stFont.font_style &= ~core::FONTSTYLETYPE_ITALICS;
	}

	SetDefaultCharFormat(cf);
}
Esempio n. 8
0
void CInputRichEdit::SetFontBold( bool bBold )
{
	CHARFORMAT cf;
	memset(&cf, 0, sizeof(CHARFORMAT));

	GetDefaultCharFormat(cf);
	if (bBold)
	{
		cf.dwEffects |= CFE_BOLD;
		m_stFont.font_style |= core::FONTSTYLETYPE_BOLD;
	}
	else
	{
		cf.dwEffects &= ~CFE_BOLD;
		m_stFont.font_style &= ~core::FONTSTYLETYPE_BOLD;
	}

	SetDefaultCharFormat(cf);
}
Esempio n. 9
0
void CInputRichEdit::SetFontUnderLine( bool bUnderLine )
{
	CHARFORMAT cf;
	memset(&cf, 0, sizeof(CHARFORMAT));

	GetDefaultCharFormat(cf);
	if (bUnderLine)
	{
		cf.dwEffects |= CFE_UNDERLINE;
		m_stFont.font_style |= core::FONTSTYLETYPE_UNDERLINE;
	}
	else
	{
		cf.dwEffects &= ~CFE_UNDERLINE;
		m_stFont.font_style &= ~core::FONTSTYLETYPE_UNDERLINE;
	}
	

	SetDefaultCharFormat(cf);
}
Esempio n. 10
0
void CRichEditCtrlX::SetSyntaxColoring(const LPCTSTR* ppszKeywords, LPCTSTR pszSeperators)
{
	int i = 0;
	while (ppszKeywords[i] != NULL)
		m_astrKeywords.Add(ppszKeywords[i++]);
	m_strSeperators = pszSeperators;

	if (m_astrKeywords.GetCount() == 0)
		m_strSeperators.Empty();
	else
	{
		SetEventMask(GetEventMask() | ENM_CHANGE);
		GetDefaultCharFormat(m_cfDef);
		m_cfKeyword = m_cfDef;
		m_cfKeyword.dwMask |= CFM_COLOR;
		m_cfKeyword.dwEffects &= ~CFE_AUTOCOLOR;
		m_cfKeyword.crTextColor = RGB(0,0,255);

		ASSERT( GetTextMode() & TM_MULTILEVELUNDO );
	}
}
void CHTRichEditCtrl::ApplySkin()
{
	if (!m_strSkinKey.IsEmpty())
	{
		// Use the 'ScrollInfo' only, if there is a scrollbar available, otherwise we would
		// use a scrollinfo which points to the top and we would thus stay at the top.
		bool bAtEndOfScroll;
		SCROLLINFO si;
		si.cbSize = sizeof si;
		si.fMask = SIF_ALL;
		if ((GetStyle() & WS_VSCROLL) && GetScrollInfo(SB_VERT, &si))
			bAtEndOfScroll = (si.nPos >= (int)(si.nMax - si.nPage));
		else
			bAtEndOfScroll = true;

		COLORREF cr;
		if (theApp.LoadSkinColor(m_strSkinKey + _T("Fg"), cr)) {
			m_bDfltForeground = false;
			m_crForeground = cr;
		}
		else {
			m_bDfltForeground = m_crDfltForeground == CLR_DEFAULT;
			m_crForeground = m_bDfltForeground ? GetSysColor(COLOR_WINDOWTEXT) : m_crDfltForeground;
		}

		bool bSetCharFormat = false;
		CHARFORMAT cf;
		GetDefaultCharFormat(cf);
		if (!m_bDfltForeground && (cf.dwEffects & CFE_AUTOCOLOR)) {
			cf.dwEffects &= ~CFE_AUTOCOLOR;
			bSetCharFormat = true;
		}
		else if (m_bDfltForeground && !(cf.dwEffects & CFE_AUTOCOLOR)) {
			cf.dwEffects |= CFE_AUTOCOLOR;
			bSetCharFormat = true;
		}
		if (bSetCharFormat) {
			cf.dwMask |= CFM_COLOR;
			cf.crTextColor = m_crForeground;
			VERIFY( SetDefaultCharFormat(cf) );
			VERIFY( GetSelectionCharFormat(m_cfDefault) );
		}

		if (theApp.LoadSkinColor(m_strSkinKey + _T("Bk"), cr)) {
			m_bDfltBackground = false;
			m_crBackground = cr;
			SetBackgroundColor(FALSE, m_crBackground);
		}
		else {
			m_bDfltBackground = m_crDfltBackground == CLR_DEFAULT;
			m_crBackground = m_bDfltBackground ? GetSysColor(COLOR_WINDOW) : m_crDfltBackground;
			SetBackgroundColor(m_bDfltBackground, m_crBackground);
		}

		if (bAtEndOfScroll)
			ScrollToLastLine();
	}
	else
	{
		m_bDfltForeground = m_crDfltForeground == CLR_DEFAULT;
		m_crForeground = m_bDfltForeground ? GetSysColor(COLOR_WINDOWTEXT) : m_crDfltForeground;

		m_bDfltBackground = m_crDfltBackground == CLR_DEFAULT;
		m_crBackground = m_bDfltBackground ? GetSysColor(COLOR_WINDOW) : m_crDfltBackground;

		VERIFY( GetSelectionCharFormat(m_cfDefault) );
	}
	PurgeSmileyCaches();
}
Esempio n. 12
0
void CRichMsgView::appendMsg(IcqMsg &msg, COLORREF color)
{
	const char *nick = "";

	if (!msg.id) {
		IcqContact *c = icqLink->findContact(msg.qid);
		if (c)
			nick = c->nick.c_str();
	} else {
		IcqGroup *g = icqLink->findGroup(msg.id);
		if (g) {
			GroupMember *m = g->getMemberInfo(msg.qid.uin);
			if (m)
				nick = m->nick.c_str();
		}
	}

	long start, end;
	SetSel(-1, -1);
	GetSel(start, end);

	CHARFORMAT defFormat;
	defFormat.cbSize = sizeof(defFormat);
	defFormat.dwMask = CFM_BOLD | CFM_ITALIC | CFM_UNDERLINE | CFM_FACE | CFM_SIZE | CFM_COLOR;
	GetDefaultCharFormat(defFormat);

	PARAFORMAT pf;
	pf.cbSize = sizeof(pf);
	pf.dwMask = PFM_STARTINDENT;
	pf.dxStartIndent = 0;
	SetParaFormat(pf);

	CHARFORMAT cf;
	cf.cbSize = sizeof(cf);

	CString text;
	CString strTime = CTime(msg.when).Format("%H:%M:%S");
	text.Format("%s (%s): \r\n",
		(msg.flags & MF_RECEIVED) ? nick : icqLink->myInfo.nick.c_str(),
		(LPCTSTR) strTime);

	ReplaceSel(text);
	SetSel(start, -1);
	cf = defFormat;
	cf.crTextColor = color;
	cf.dwEffects = 0;
	SetSelectionCharFormat(cf);

	SetSel(-1, -1);
	insertMsg(msg);

	pf.dxStartIndent = 200;
	SetParaFormat(pf);

	uint8 mask = (MF_RELAY | MF_RECEIVED);
	if ((msg.flags & mask) == mask) {
		GetSel(start, end);

		text.LoadString(IDS_SERVER_RELAY);
		ReplaceSel("\r\n");
		ReplaceSel(text);
		SetSel(start, -1);

		cf = defFormat;
		cf.crTextColor = color;
		cf.dwEffects = 0;
		SetSelectionCharFormat(cf);
	}

	SetSel(-1, -1);
	ReplaceSel("\r\n");

	scrollToBottom();
}
Esempio n. 13
0
void CMyRichEdit::OnRButtonDown(UINT nFlags, CPoint point)
{
    // TODO: 在此添加消息处理程序代码和/或调用默认值
    LONG lCharHeight;
    CHARFORMAT cf;
    memset(&cf, 0, sizeof(CHARFORMAT));
    GetDefaultCharFormat(cf);
    
    //int nline = GetLineCount();

    int StartIndex = LineIndex(0);  
    int EndIndex = LineIndex(1);  
    if (EndIndex != -1)  
    {
        CPoint LinePoint = GetCharPos(StartIndex);
        CPoint AfterPoint = GetCharPos(EndIndex);
        lCharHeight = AfterPoint.y - LinePoint.y;
    }else
    {
        lCharHeight = cf.yHeight/15;
    }

    //设置为焦点
    SetFocus();
    //创建一个弹出式菜单
    CMenu popmenu;
    popmenu.CreatePopupMenu();
    //添加菜单项目
    //popmenu.AppendMenu(0, ID_RICH_UNDO, "&Undo");
    //popmenu.AppendMenu(0, MF_SEPARATOR);
    //popmenu.AppendMenu(0, ID_RICH_CUT, "&Cut");
    popmenu.AppendMenu(0, ID_RICH_COPY, _T("复制"));
    //popmenu.AppendMenu(0, ID_RICH_PASTE, "&Paste");
    popmenu.AppendMenu(0, ID_RICH_SELECTALL, _T("选择全部内容"));
    popmenu.AppendMenu(0, MF_SEPARATOR);
    popmenu.AppendMenu(0, ID_RICH_CLEAR, _T("清空全部内容"));
    //popmenu.AppendMenu(0, MF_SEPARATOR);
    //popmenu.AppendMenu(0, ID_RICH_SETFONT, "Select &Font");

    //初始化菜单项
    //UINT nUndo=(CanUndo() ? 0 : MF_GRAYED );
    //popmenu.EnableMenuItem(ID_RICH_UNDO, MF_BYCOMMAND|nUndo);

    CPoint CurrPoint;
    CurrPoint = GetCaretPos();
    long nStartChar;
    long nEndChar;
    GetSel(nStartChar, nEndChar);
    CPoint startPoint;
    CPoint endPoint;
    startPoint = GetCharPos(nStartChar);            // Gets the position (top-left corner) of a given character within this CRichEditCtrl
    endPoint = GetCharPos(nEndChar);

    if(point.y < startPoint.y || point.y > endPoint.y + lCharHeight 
        || (point.x < startPoint.x && point.y > startPoint.y && point.y < startPoint.y + lCharHeight)
        || (point.x > endPoint.x && point.y > endPoint.y && point.y < endPoint.y + lCharHeight))
    {
        //SetSel(0, -1);
        SetSel(-1, 0);                          // 取消文本选中
    }

    CurrPoint.y = point.y/lCharHeight*lCharHeight;
    CurrPoint.x = point.x;
    SetCaretPos(CurrPoint);
    //char chTT[100];
    //sprintf_s(chTT, "y: %d startY: %d endY: %d", CurrPoint.y, startPoint.y, endPoint.y);
    //OutputDebugStringA(chTT);

    UINT nSel=((GetSelectionType()!=SEL_EMPTY) ? 0 : MF_GRAYED) ;
    //popmenu.EnableMenuItem(ID_RICH_CUT, MF_BYCOMMAND|nSel);
    popmenu.EnableMenuItem(ID_RICH_COPY, MF_BYCOMMAND|nSel);
    //popmenu.EnableMenuItem(ID_RICH_CLEAR, MF_BYCOMMAND|nSel);

    //UINT nPaste=(CanPaste() ? 0 : MF_GRAYED) ;
    //popmenu.EnableMenuItem(ID_RICH_PASTE, MF_BYCOMMAND|nPaste);

    //显示菜单
    CPoint pt;
    GetCursorPos(&pt);
    popmenu.TrackPopupMenu(TPM_RIGHTBUTTON, pt.x, pt.y, this);
    popmenu.DestroyMenu();

    CRichEditCtrl::OnRButtonDown(nFlags, point);
}
Esempio n. 14
0
void CIRCEditCtrl::PutIRCText( char *Message,COLORREF Foreground, COLORREF Background)
{
	CHARFORMAT2 fmt;
	long effects = 0;
	int i, si, cfi,cbi;
	char sfgcol[9]; // can hold "0\0" - "16777215\0" in decimal (HEX 0x00FFFFFF)
	char sbgcol[9];
  int colornum;

  int len = lstrlen(Message);
  char *sputbuf=strdup(Message);

  if (!sputbuf)
    return;

  sputbuf[0] = 0; // null terminate


  SetSel(-1,-1); // deselect and move to end
  GetDefaultCharFormat(fmt);
  fmt.dwMask = CFM_BOLD | CFM_COLOR | CFM_BACKCOLOR | CFM_UNDERLINE | CFM_ITALIC;
	fmt.dwEffects = effects;
  fmt.crTextColor = Foreground;
	fmt.crBackColor = Background;  
	fmt.cbSize = sizeof(CHARFORMAT2);
  SetSelectionCharFormat(fmt);  

  // remember some stuff for highlighting
  BOOL HighlightMode;
	COLORREF LastTextColor = fmt.crTextColor;
	COLORREF LastBackColor = fmt.crBackColor;

  si = 0;
	for (i = 0; i < len; i++)
	{
    if (m_ControlCodeMode == CTRLCODE_MODE_DISPLAY)
    {
      if (Message[i] == '\r')
        continue;
      sputbuf[si] = Message[i];
      si++;
      sputbuf[si] = 0; // null terminate

      // count the lines
      if (Message[i] == '\n')
      {
        if (sputbuf[0])
        {
          ReplaceSel(sputbuf);
          SetSel(-1,-1);
        }
        si = 0;
        sputbuf[si] = 0; // null terminate
      }
    }
    else
    {
      switch(Message[i])
		  {
        // bold
			  case '\002':
          if (m_ControlCodeMode == CTRLCODE_MODE_STRIP) break;

				  if (sputbuf[0])
				  {
            ReplaceSel(sputbuf);
            //ScrollCaret();
            SetSel(-1,-1);
				  }
				  //ZeroMemory(&sbuf, sizeof(sbuf));
				  si = 0;
          sputbuf[si] = 0; // null terminate

          //GetDefaultCharFormat(fmt);
				  fmt.cbSize = sizeof(CHARFORMAT2);
				  fmt.dwMask = CFM_BOLD;
					effects ^= CFE_BOLD;
				  fmt.dwEffects = effects;
          SetSelectionCharFormat(fmt);
          break;

        // color (ctrl+k)
			  case '\003':
				  if (sputbuf[0])
				  {
            ReplaceSel(sputbuf);
            //ScrollCaret();
            SetSel(-1,-1);
				  }
          si = 0;
          sputbuf[si] = 0; // null terminate
				  ZeroMemory(&sfgcol, sizeof(sfgcol));
				  ZeroMemory(&sbgcol, sizeof(sbgcol));

          // get the fg color
          if (i < lstrlen(Message)-1)
          {
            if (isdigit((unsigned char)Message[i+1]))
            {
              sfgcol[0] = Message[i+1];
              i++;

              if (i < lstrlen(Message)-1)
              {
                if (isdigit((unsigned char)Message[i+1]))
                {
                  sfgcol[1] = Message[i+1];
                  i++;

                  // check for invalid color number, step back a character if it's not valid
                  colornum = atoi(sfgcol);
                  if ((colornum <0 || colornum >15) && colornum != 99)
                  {
                    sfgcol[1] = 0;
                    i--;
                  }
                }
              }
            }
          }

          // if we've got a , then get the bg color
          if (i < lstrlen(Message)-1 && Message[i+1] == ',')
          {
            i++;

            if (i < lstrlen(Message)-1)
            {
              if (isdigit((unsigned char)Message[i+1]))
              {
                sbgcol[0] = Message[i+1];
                i++;
                if (i < lstrlen(Message)-1)
                {
                  if (isdigit((unsigned char)Message[i+1]))
                  {
                    sbgcol[1] = Message[i+1];
                    i++;

                    // check for invalid color number, step back a character if it's not valid
                    colornum = atoi(sbgcol);
                    if ((colornum <0 || colornum >15) && colornum != 99)
                    {
                      sbgcol[1] = 0;
                      i--;
                    }
                  }
                }
              }
            }
          }

          if (m_ControlCodeMode == CTRLCODE_MODE_INTERPRET)
          {
            if (sfgcol[0])
            {
              fmt.cbSize = sizeof(CHARFORMAT2);
              fmt.dwMask = CFM_COLOR;
              fmt.dwEffects = effects;
              colornum = atoi(sfgcol);
              if (colornum >= 0 && colornum <= 15)
              {
                fmt.crTextColor = m_Colors[colornum];
              }
              else // assume color code 99
              {
                fmt.crTextColor = Foreground;
              }
            }
            if (sbgcol[0])
            {
              fmt.dwMask |= CFM_BACKCOLOR;
              colornum = atoi(sbgcol);
              if (colornum >= 0 && colornum <= 15)
              {                  
                fmt.crBackColor = m_Colors[colornum];
              }
              else // assume color code 99
              {
                fmt.crBackColor = Background;
              }
            }
            if (!sfgcol[0] && !sbgcol[0])
            {
              // didn't get colors, behave as if this was ctrl+o
              fmt.cbSize = sizeof(CHARFORMAT2);
              fmt.dwMask = CFM_COLOR | CFM_BACKCOLOR;
              fmt.dwEffects = 0;
              fmt.crTextColor = Foreground;
              fmt.crBackColor = Background;
            }
            SetSelectionCharFormat(fmt);
          }
          break;

        case '\007': // 16 million color (HydraIRC Highlighting) - hex
        case '\004': // 16 million color - hex

          if (Message[i] == '\007')
            HighlightMode = TRUE;
          else
            HighlightMode = FALSE;

				  if (sputbuf[0])
				  {
            ReplaceSel(sputbuf);
            SetSel(-1,-1);
				  }
          si = 0;
          sputbuf[si] = 0; // null terminate
				  ZeroMemory(&sfgcol, sizeof(sfgcol));
				  ZeroMemory(&sbgcol, sizeof(sbgcol));

          // get the fg color
				  cfi = 0;
          while ((i < lstrlen(Message)-1) && (isxdigit((unsigned char)Message[i+1])) && (cfi < 6))
          {
						sfgcol[cfi++] = Message[i+1];
						i++;
          }
          if (cfi != 6)
            i-=cfi; //step back if we've not got 6 hex digits

          // if we've got a ',' then get the bg color
          cbi = 0;
          if (i < lstrlen(Message)-1 && Message[i+1] == ',')
          {
            i++;
            // get the bg color
            while ((i < lstrlen(Message)-1) && (isxdigit((unsigned char)Message[i+1])) && (cbi < 6))
            {
						    sbgcol[cbi++] = Message[i+1];
						    i++;
            }
            if (cbi != 6)
              i-=cbi; //step back if we've not got 6 hex digits
          }

          if (m_ControlCodeMode == CTRLCODE_MODE_INTERPRET || HighlightMode )
          {
				    fmt.cbSize = sizeof(CHARFORMAT2);
				    fmt.dwMask = CFM_COLOR;
				    fmt.dwEffects = effects;


            if (cfi == 6 || cbi == 6)
            {
              if (HighlightMode)
              {
                LastTextColor = fmt.crTextColor;
                LastBackColor = fmt.crBackColor;
              }
              if (cfi == 6)
				      {
                if (sscanf(sfgcol,"%x",&colornum) == 1 && colornum >= 0 && colornum <= 0xffffff)
                {
                  // RGB(0,0,255) == 0xff0000 not 0x0000ff
                  // so we swap the bytes.
                  fmt.crTextColor = RGBVALTOCOLORREF(colornum);
                }
              }

              if (cbi == 6)
              {
                fmt.dwMask |= CFM_BACKCOLOR;                
                if (sscanf(sbgcol,"%x",&colornum) == 1 && colornum >= 0 && colornum <= 0xffffff)
                {                  
                  fmt.crBackColor = RGBVALTOCOLORREF(colornum);
                }
                else
                {
                  fmt.crBackColor = Background;
                }
              }
              SetSelectionCharFormat(fmt);
            }
            else
            {              
              // didn't get colors, behave as if this was ctrl+o
	            fmt.cbSize = sizeof(CHARFORMAT2);
	            fmt.dwMask = CFM_BOLD | CFM_COLOR | CFM_BACKCOLOR | CFM_UNDERLINE | CFM_ITALIC;
	            fmt.dwEffects = 0;
              if (HighlightMode)
              {
	              fmt.crTextColor = LastTextColor;
	              fmt.crBackColor = LastBackColor;
              }
              else
              {
	              fmt.crTextColor = Foreground;
	              fmt.crBackColor = Background;
              }
              SetSelectionCharFormat(fmt);
            }

				  }
          break;
        // underline
			  case '\037':
          if (m_ControlCodeMode == CTRLCODE_MODE_STRIP) break;
				  if (sputbuf[0])
				  {
            ReplaceSel(sputbuf);
            SetSel(-1,-1);
				  }
				  si = 0;
          sputbuf[si] = 0; // null terminate
				  fmt.cbSize = sizeof(CHARFORMAT2);
				  fmt.dwMask = CFM_UNDERLINE;
          effects ^= CFE_UNDERLINE;
				  fmt.dwEffects = effects;
          SetSelectionCharFormat(fmt);
				  break;

        // italics
			  case '\035':
          if (m_ControlCodeMode == CTRLCODE_MODE_STRIP) break;
				  if (sputbuf[0])
				  {
            ReplaceSel(sputbuf);
            SetSel(-1,-1);
				  }
				  si = 0;
          sputbuf[si] = 0; // null terminate
				  fmt.cbSize = sizeof(CHARFORMAT2);
				  fmt.dwMask = CFM_ITALIC;
          effects ^= CFE_ITALIC;
				  fmt.dwEffects = effects;
          SetSelectionCharFormat(fmt);
				  break;

        // reverse
			  case '\026':
          if (m_ControlCodeMode == CTRLCODE_MODE_STRIP) break;
				  if (sputbuf[0])
				  {
            ReplaceSel(sputbuf);
            SetSel(-1,-1);
				  }
				  si = 0;
          sputbuf[si] = 0; // null terminate
				  fmt.cbSize = sizeof(CHARFORMAT2);
				  fmt.dwMask = CFM_COLOR | CFM_BACKCOLOR;

          // swap the colors.
          colornum = fmt.crBackColor;
          fmt.crBackColor = fmt.crTextColor;
          fmt.crTextColor = colornum;
          
          SetSelectionCharFormat(fmt);
          break;
        // normal
			  case '\017':
          if (m_ControlCodeMode == CTRLCODE_MODE_STRIP) break;
				  if (sputbuf[0])
				  {
            ReplaceSel(sputbuf);
            SetSel(-1,-1);
				  }
				  si = 0;
          sputbuf[si] = 0; // null terminate
	        fmt.cbSize = sizeof(CHARFORMAT2);
	        fmt.dwMask = CFM_BOLD | CFM_COLOR | CFM_BACKCOLOR | CFM_UNDERLINE | CFM_ITALIC;
	        fmt.dwEffects = 0;
	        fmt.crTextColor = Foreground;
	        fmt.crBackColor = Background;
          SetSelectionCharFormat(fmt);

          break;
			  case '\006':
			  case '\023':
			  case '\022':
				  break;

			  default:
				  {
					  sputbuf[si] = Message[i];
					  si++;
            sputbuf[si] = 0; // null terminate

            // count the lines, add a timestamp if needed.
            if (Message[i] == '\n')
            {
              if (sputbuf[0])
              {
                ReplaceSel(sputbuf);
                SetSel(-1,-1);
              }
              si = 0;
              sputbuf[si] = 0; // null terminate
            }
				  }
				  break;
		  }
    }
  }
  if (sputbuf[0])
  {
    ReplaceSel(sputbuf);
    SetSel(-1,-1);
  }

  free (sputbuf);
}