본문 바로가기

Windows/MFC

CMenu InsertMenu 디렉토리 리스트를 메뉴에 추가하기

[code]동적으로 메뉴를 추가하는데 갑자기 -_ - 여기 이벤트는 어떻게 생성하나? 하는 고민이 생겼다... 정답은 생각보다 간단!!. 미리 함수를 생성해놓은 다음 연결해 두면 된다.[/code]

CString CConfig::GetSelectImage(int nImage)
{
    // Radio 방식으로 선택하기
    CMenu* pMenu = m_pWnd->GetMenu();

    int nLast    = ID_SELECTIMAGES_NORMAL - m_nCntImage;
    int nPos    = ID_SELECTIMAGES_NORMAL - nImage;
    pMenu->CheckMenuRadioItem(nLast, ID_SELECTIMAGES_NORMAL, nPos, MF_CHECKED);

    return CString();
}

void CConfig::GetFileList(void)
{
    // 메뉴에 추가하기...
    // MFC 말고 C++ 자체에서 파일 리스트를 얻는 방법은 없나?
    CFileFind finder;
    CString szFindFile;
    BOOL bWorking        = finder.FindFile(L"image/*.jpg");    
    CMenu* pMenu        = m_pWnd->GetMenu();
    CMenu* pSubmenu        = pMenu->GetSubMenu(1);
    CMenu* pSubmenu2    = pSubmenu->GetSubMenu(1);
    UINT nBaseID        = 9999999999;

    // ./image 폴더에 존재하는 파일명들을 가져와서 menu에 넣자.
    while (bWorking)
    {
        bWorking = finder.FindNextFile();
        szFindFile = finder.GetFileName();

        if (szFindFile != L"." && szFindFile != L"..")
        {
            pSubmenu2->InsertMenu(1, MF_BYPOSITION, nBaseID--, szFindFile);
        }
    }
}