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++ 기반으로 해야하는 거라서 다시 돌아가게 되었네요.

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

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

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

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