달력

5

« 2024/5 »

  • 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
  • 31

제목은 거창합니다만....

알고보면 간단한거라는 -ㅂ-ㅋ

 

   1: void CFileSearch::GetFileList( CString strFolder)
   2: {
   3:  
   4:   // 파일 탐색 필터 정의 - Ini에서 확인 - 변경할 것
   5:     CString strMusicFilter = ".MP3.OGG.WMA.WAV";
   6:     CString strMovieFilter = ".AVI.WMV.MKV.MPEG.MPG";
   7:     CString strImageFilter = ".JPEG.JPG.BMP.PNG.GIF";
   8:     CString strDocumentFilter = ".TXT";
   9:  
  10:     CFileFind file;
  11:     BOOL b = file.FindFile(strFolder + "\\*.*");
  12:     CString strFolderItem, strFileExt, strTempString;
  13:  
  14:     CString strTempPath;
  15:     strTempPath = GetSpecialFolderPath(CSIDL_HISTORY);
  16:     strTempPath = strTempPath.Left(strTempPath.ReverseFind('\\')) + "\\Temp";
  17:  
  18:     while(b)
  19:     {
  20:         b = file.FindNextFile();
  21:  
  22:         if(file.IsDirectory() && !file.IsDots())
  23:         {
  24:  
  25:             strFolderItem = file.GetFilePath();
  26:  
  27:             // 사용하지 않는 시스템 폴더들은 탐색에서 제외한다
  28:              if (
  29:                  strFolderItem.Find(GetSpecialFolderPath(CSIDL_WINDOWS))                > -1            ||
  30:                  strFolderItem.Find(GetSpecialFolderPath(CSIDL_INTERNET_CACHE))        > -1        ||
  31:                  strFolderItem.Find(GetSpecialFolderPath(CSIDL_HISTORY))                > -1            ||
  32:                 strFolderItem.Find(GetSpecialFolderPath(CSIDL_COOKIES))                > -1             ||
  33:  
  34:                  strFolderItem.Find(GetSpecialFolderPath(CSIDL_COMMON_APPDATA))        > -1           ||
  35:                 strFolderItem.Find(GetSpecialFolderPath(CSIDL_APPDATA))                > -1   ||
  36:                  strFolderItem.Find(GetSpecialFolderPath(CSIDL_LOCAL_APPDATA))        > -1         ||
  37:  
  38:                  strFolderItem.Find(GetSpecialFolderPath(CSIDL_PROGRAM_FILES))        > -1        ||
  39:                 
  40:                 strFolderItem.Find(strTempPath)                                        > -1    )
  41:              {
  42:                 
  43:                 TRACE("제외 : %s\n", strFolderItem);
  44:                 continue;
  45:              }    
  46:  
  47:             //하위폴더를 검색하는 조건이면 재귀호출 발생
  48:             if (m_bSearchSubFolder)
  49:                 GetFileList(strFolderItem);
  50:         }
  51:  
  52:         strFolderItem = file.GetFilePath();
  53:         strFileExt = strFolderItem.Mid(strFolderItem.ReverseFind('.'));
  54:         strFileExt.MakeUpper();
  55:         
  56:         // 파일 탐색 필터 정의에따라 해당 StringList에 추가
  57:         if (strMusicFilter.Find( strFileExt , 0) > -1 && !file.IsDots())
  58:         {
  59:             m_strlistMusic.AddTail(strFolderItem);
  60:         }
  61:         else if (strMovieFilter.Find( strFileExt , 0) > -1 && !file.IsDots())
  62:         {
  63:             m_strlistMovie.AddTail(strFolderItem);
  64:         }
  65:         else if (strImageFilter.Find( strFileExt , 0) > -1 && !file.IsDots())
  66:         {
  67:             m_strlistImage.AddTail(strFolderItem);
  68:         }
  69:         else if (strDocumentFilter.Find( strFileExt , 0) > -1 && !file.IsDots())
  70:         {
  71:             m_strlistDocument.AddTail(strFolderItem);
  72:         }
  73:     }
  74: }

 

프로그램을 진행하다 보니 특정 파일들을 검색하는 일이 생겼는데..

CFileFind를 이용하면 무척이나 편하다 'ㅂ'b

:
Posted by Lunaness
유니코드에서 한 문자가 Little-Endian또는 Big-Endian으로 정의 되는 것을 볼 수 있다
이는 시스템상의 사용하는 문제로 가끔 변환해 줄 필요가 있는데....

네트워크 관련 API가 있지만, 해더 파일을 넣어줘야 한다는 이유 하나만으로 쓰기가 싫어졌다 -ㅂ-ㅋ

void Trans_Endian(WCHAR *uni)
{
    int nSize = WideCharToMultiByte(CP_UTF8, 0, uni, -1, NULL, 0, NULL, NULL);

    for (int n = 0; n<nSize; n++)
     {
        // UTF-16 little Endian -> Big Endian
        WCHAR high_bit = 0x0000, low_bit = 0x0000;
        high_bit = (*(uni+n) & 0xFF00) >> 8;
        low_bit = (*(uni+n) & 0x00FF)  << 8;

        WCHAR p = low_bit | high_bit;
            
        if (p == 0x00cd) break;
        *(uni+n) = _T(p);
            
     }

}

이것으로 간단하게 해결~!



:
Posted by Lunaness


MP3 ID3v2 Tag 읽기 및 편집을 위한 라이브러리 및 예제 이다
일단 시험중이니..  완성되면 다시 포스팅해야겠다...
:
Posted by Lunaness

리스트 컨트롤에서 Multi Selection후 삭제를 할라보니 몇개가 남는다...

뭥미;;

찾아보니 뒤에서부터 지워라, 인덱스를 만들어 지워라 등등 많았는데...

가장 깔끔하게 해결하는 방법을 Liverpool님께서 블로그에 올려두신 것을 보았으니..

오호 통제라..


POSITION pos = m_LstSelectList.GetFirstSelectedItemPosition();
if(pos == NULL)return;


//처음부터 선택된 값을 해제 한다.
while(pos){
     int index = m_LstSelectList.GetNextSelectedItem(pos);
     m_LstSelectList.DeleteItem(index);
     pos = m_LstSelectList.GetFirstSelectedItemPosition();
}

위치를 초기화 시켜주는 것으로 한방에 해결~!  멋진걸.

출처 :  http://choiks.tistory.com/89

:
Posted by Lunaness
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