달력

4

« 2024/4 »

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
2008. 6. 16. 09:54

RichEditCtrl Line 정의 Programing/Windows Programing2008. 6. 16. 09:54

RichEdit를 쓸일이 있어서 인터넷을 뒤졌는데...

정보가 없다...  아니 찾기가 무척이나 힘들다..

 

MSDN과 구글링을 뒤지다 결국 노가다로 찾았는데

너무 힘들게 찾아서 여기다 기록해 둘까 한다

 

1. RichEditCtrl 을 사용하기 위한 초기화 (반드시 넣어줘야 초기화가 된다)

   1:  int CXXXDlg::OnCreate(LPCREATESTRUCT lpCreateStruct) 
   2:  {
   3:      if (CDialog::OnCreate(lpCreateStruct) == -1)
   4:          return -1;
   5:   
   6:      // RichEditCtrl 을 사용하기 위한 초기화 (반드시 넣어줘야 초기화가 된다)
   7:      AfxInitRichEdit();
   8:      
   9:      return 0;
  10:  }

 

2. 기본 폰트 정의

   1:  void CTextViewerDlg::LoadDefaultFont()
   2:  {
   3:      m_cf.cbSize = sizeof(m_cf);
   4:       m_cf.dwEffects = CFE_PROTECTED;
   5:       m_cf.dwMask = CFM_BOLD | CFM_FACE | CFM_SIZE | 
   6:                      CFM_CHARSET | CFM_PROTECTED;
   7:       m_cf.yHeight = 200;
   8:       m_cf.bCharSet = 0x00;
   9:       
  10:       strcpy(m_cf.szFaceName, _T("굴림"));
  11:   
  12:      m_TextViewBox.SetDefaultCharFormat(m_cf);
  13:  }

3. 리치에디트 컨트롤 메시지 제어

     m_TextViewBox.SetEventMask(m_TextViewBox.GetEventMask() | EN_MSGFILTER);

4. 눈에 보이는 첫번째 줄 번호 반환

     nVisibleLine = (int) m_TextViewBox.SendMessage( EM_GETFIRSTVISIBLELINE, 0, 0 );

또는 
     nVisibleLine = m_TextViewBox.GetFirstVisibleLine();

 

5.  줄번호로 이동

     m_TextViewBox.LineScroll(nLineNumber);

     ※ 주 : LineScroll은 현재 줄번호 + nLineNumber로 이동한다.
                즉, 앞 뒤로 이동하고 싶으면 

                     LineScroll.(-nBeforLineNumber);
                     LineScroll.(nNowLineNumber);

                이런식으로 라인번호를 0위치로 되돌린 후 해당 줄번호로 이동을 해야 이상이 없다

 

6. 한 페이지에 보여지는 줄 수 계산

   1:  int CXXXDlg::GetCountPerPage()
   2:  {
   3:      //////////////////////////////////////////////////////////////////////////
   4:      // 한 페이지에 한번에 보여질 수 있는 줄 수를 계산한다.
   5:      int nCountPerPage = 0;
   6:   
   7:      TEXTMETRIC tm;
   8:      CDC* pDC = GetDC();
   9:      pDC->GetTextMetrics(&tm);
  10:      ReleaseDC(pDC);
  11:   
  12:      CRect rect;
  13:      m_TextViewBox.GetRect(&rect);
  14:      
  15:      nCountPerPage = rect.Height() / (tm.tmHeight + tm.tmExternalLeading); 
  16:   
  17:      return nCountPerPage;
  18:  }

 

7.  폰트 다이얼로그를 통한 폰트 정의

   1:  void CXXXDlg::SetFont()
   2:  {
   3:      LOGFONT lf;
   4:      memset(&lf, 0, sizeof(LOGFONT));
   5:      
   6:      // Get device resolution for font size calculation:
   7:      CClientDC dc(this);  
   8:      int logPixelsY = dc.GetDeviceCaps(LOGPIXELSY);
   9:      
  10:      // m_cf.yHeight is in TWIPS (20 * Points)
  11:      int lfcfHeight = m_cf.yHeight/20; // In Points  
  12:      
  13:      lf.lfHeight = -MulDiv(lfcfHeight, logPixelsY, 72);
  14:      strcpy(lf.lfFaceName, m_cf.szFaceName);
  15:      lf.lfPitchAndFamily = m_cf.bPitchAndFamily;
  16:      lf.lfUnderline = (m_cf.dwEffects & CFM_UNDERLINE) ? TRUE : FALSE;
  17:      lf.lfStrikeOut = (m_cf.dwEffects & CFM_STRIKEOUT) ? TRUE : FALSE;
  18:      lf.lfItalic =    (m_cf.dwEffects & CFM_ITALIC)    ? TRUE : FALSE;
  19:      lf.lfWeight =    (m_cf.dwEffects & CFM_BOLD)      ? 700  : 400;
  20:      
  21:      lf.lfCharSet = m_cf.bCharSet;
  22:      
  23:      // Create the font dialog initialized with lf: 
  24:      CFontDialog dlg(&lf);
  25:        
  26:      dlg.m_cf.rgbColors = m_cf.crTextColor;
  27:      
  28:      if (dlg.DoModal() == IDOK)
  29:      {
  30:          m_cf.cbSize = sizeof(CHARFORMAT);
  31:          m_cf.dwMask = CFM_BOLD | CFM_COLOR | CFM_FACE |
  32:                      CFM_ITALIC | CFM_SIZE | CFM_UNDERLINE | CFM_STRIKEOUT;
  33:          m_cf.dwEffects =  (dlg.IsBold()      ? CFE_BOLD:0)   | 
  34:                          (dlg.IsItalic()    ? CFE_ITALIC:0) |
  35:                          (dlg.IsStrikeOut() ? CFE_STRIKEOUT:0) |
  36:                          (dlg.IsUnderline() ? CFE_UNDERLINE:0);
  37:              
  38:          // GetSize returns Text size in 10ths of a point,  
  39:          // CHARFORMAT expects it in 20ths of a point
  40:          m_cf.yHeight=dlg.GetSize() *2 ;
  41:      
  42:          m_cf.crTextColor = dlg.GetColor();
  43:              
  44:          strncpy(m_cf.szFaceName, dlg.GetFaceName(),LF_FACESIZE);
  45:          m_cf.bCharSet = 0;
  46:          m_cf.bPitchAndFamily=0;
  47:      
  48:      }
  49:      
  50:      m_TextViewBox.SetDefaultCharFormat(m_cf);
  51:  }
:
Posted by Lunaness