2010년 7월 8일 목요일

선택한 폴더의 경로 가져오기

void CTestDlg::OnBnClickedButton1()

{

    // TODO: 여기에컨트롤알림처리기코드를추가합니다.

    ITEMIDLIST *pBrowse;

    char pathName[260];

    int count = 0;

     

   

    CString title = (CString)"폴더를선택하세요";

    BROWSEINFO brInfo;

    brInfo.hwndOwner = GetSafeHwnd();

    brInfo.pidlRoot = NULL;

   

    brInfo.pszDisplayName = (LPWSTR)pathName;

    brInfo.lpszTitle = title;

    brInfo.ulFlags = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT;

    brInfo.lpfn = NULL;

    brInfo.lParam = 0;

    ::ZeroMemory(pathName, 260);

    pBrowse = SHBrowseForFolder(&brInfo);

    if(pBrowse != NULL)

    {

        ::SHGetPathFromIDList(pBrowse, (LPWSTR)pathName);

       

    }

   

    UpdateData(TRUE);

    m_Path.SetWindowText((LPCTSTR)pathName);

    strPath.Format((CString)"%s\\*.*", pathName);

     

   

    CFileFind find;

   

    CString fName;

   

    find.FindFile((LPCTSTR)strPath);

       

    while(find.FindNextFile())

    {

        fName = find.GetFileName();

        if(find.IsDirectory() != TRUE)

            fileList.Add(fName);

    }

}

선택한 폴더내에 있는 모든파일들을 파일리스트에 저장

환경설정 파일(ini) 사용

INI 파일의 구성은 크게 3부분으로 구성된다.

Section, Key, Value 이다.

[Section]

Key = value

이런 형태라고 볼 수 있다.

정보가져오기

GetPrivateProfileString, GetPrivateProfileInt 함수를 사용.

정보쓰기

WritePrivateProfileString, WritePrivateProfileInt 함수를 사용.

이미 파일이 생성되어 있지 않더라도 위의 쓰기 함수들을 이용하면 자동으로 생성이 되는 것을

확인 할 수 있다.

CString and char*

CString 형을 char문자열로 변환해서 사용하고 싶으시면

CString str = "abcdef";

Char* ch = (char *)(LPCTSTR)str;

이런 식으로 사용하셔도 됩니다.

AfxBeginThread 함수사용

전역변수로 CWinThread 변수 선언

CwinThread *pThread;

원하는 코드내에 다음과 같이 사용

pThread = AfxBeginThread(ThreadChangedMonitor, NULL);

Thread 구현부

UINT ThreadChangedMonitor(LPVOID lParam)

{

    구현

}

지정폴더 변화 감시 함수

자신이 원하는 폴더에서의 변화를 감지하고 싶을때가 있을 것이다.

이러한 변화 감지를 위해서 WIN32 API 는 FindFirstChangeNotification 과 FindNextChangeNotification 함수를 제공한다.

다음은 MSDN에 정의되어 있는 내용이다.

HANDLE WINAPI FindFirstChangeNotification(

__in LPCTSTR lpPathName,

__in BOOL bWatchSubtree,

__in DWORD dwNotifyFilter

);

LpPathName 은 경로, bWatchSubtree 는 하위폴더까지 감시할 것인지를 dwNotifyFilter 는 변화알림에 대한 상태필터이다.

dwNotifyFilter 에 들어갈 값들에 대한 정의이다.

Value

Meaning

FILE_NOTIFY_CHANGE_FILE_NAME

Any file name change in the watched directory or subtree causes a change notification wait operation to return. Changes include renaming, creating, or deleting a file name.

FILE_NOTIFY_CHANGE_DIR_NAME

Any directory-name change in the watched directory or subtree causes a change notification wait operation to return. Changes include creating or deleting a directory.

FILE_NOTIFY_CHANGE_ATTRIBUTES

Any attribute change in the watched directory or subtree causes a change notification wait operation to return.

FILE_NOTIFY_CHANGE_SIZE

Any file-size change in the watched directory or subtree causes a change notification wait operation to return. The operating system detects a change in file size only when the file is written to the disk. For operating systems that use extensive caching, detection occurs only when the cache is sufficiently flushed.

FILE_NOTIFY_CHANGE_LAST_WRITE

Any change to the last write-time of files in the watched directory or subtree causes a change notification wait operation to return. The operating system detects a change to the last write-time only when the file is written to the disk. For operating systems that use extensive caching, detection occurs only when the cache is sufficiently flushed.

FILE_NOTIFY_CHANGE_SECURITY

Any security-descriptor change in the watched directory or subtree causes a change notification wait operation to return.

전역변수 선언하기

MFC 프로그래밍을 하다가 전역변수 선언을 해야 할 때가 있다.

전역변수 선언은 다음과 같이 하면 되겠다.

[Stdafx.h]

extern 자료형 변수명;

[stdafx.cpp]

자료형 변수명;

이렇게 선언을 해주면 프로젝트 내에서라면 어디서든 사용 할 수 있게 된다.

2010년 7월 6일 화요일

또 다시 C++의 세계로.....

또 다시 C++의 세계로 돌아갑니다.

인턴에서 지금 하는 일이 C++ 기반으로 해야하는 거라서 다시 돌아가게 되었네요.

근데 몇년전이라서 제대로 기억이 안나는 ㅠ.ㅠ

서적도 다 집에 있거나 학교에 있고......

틈나는 대로 서점에서 서적좀 구해서 좀 봐야되겠습니다.

새로 입문하는 기분으로 다시 돌파해야겠네요. 쯔~~~업

2010년 7월 2일 금요일

안드로이드 가사지원 음악 플레이어

완성이라고 하기에는 너무 미흡한 나의 첫 안드로이드 어플리케이션이 완성됐다?? 아니 됐었다.

사실 이 포스팅은 제작을 완료한지 좀 지난시점에서야 올리게 됐다 ㅡ,ㅡ;;

머 이래저래 정신이 없었던 것도 있고 귀차니즘도 좀 있고 해서..... ㅋㅋ

어플에 대해서 잠시 소개를??

아직은 부족한 어플이다. 좀 더 보완해야 할 점도 있고........

먼저 제목그대로 가사를 가져오는 어플이다.

프로그램을 실행시켜 보면 음악을 듣고 그 음악에 대한 가사정보를 가져온다.

순전히 나를 위한 어플이다 ㅡ,ㅡ;;;;;

배포를 해 볼까도 했지만 저작권의 문제때문에 배포는 불가!!!

또한 UI가 문제가 많을 것 같기도 하다. 내 모토로이에 최적화된 UI이고 촌스럽기까지 하다 ㅋㅋ

그래도 한 번 써보고 싶으신 분은 개인적으로 연락을 ㅋㅋㅋㅋㅋ

촌스러운 UI 공개 ㅋㅋㅋㅋ 이런쪽은 너무 약하다. ㅋㅋ 천상남자라서 일까....

마지막 사진은 가사정보를 텍스트파일로 저장한 것이다. 그래서 한 번 가사를 봤던 곡은

다시 인터넷 접속 필요없이 로컬로 볼 수 있다. 적은 데이터도 아껴 사용하자?? 이런거?

몰랐었는데 멜론 플레이어도 이런식으로 되어 있더라.

dcf 파일은 모토로이 내부로 돌아가는 drm 서비스 때문에 재생은 가능하나 가사정보는 받아오지 못했다.

결국은 mp3 파일만 가능하다는 결론.

아무튼 허접한 안드로이드 프로젝트는 잠시 접어두어야........