vc 6.0开发的浏览器代码解释。请高手帮我解释一下下面的代码,要详细一点的 ..非常感谢,小弟有急用,谢谢

intCMainFrame::BuildFavoritesMenu(LPCTSTRpszPath,intnStartPos,CMenu*pMenu){CStringstr... int CMainFrame::BuildFavoritesMenu(LPCTSTR pszPath, int nStartPos, CMenu *pMenu)
{
CString strPath(pszPath);
CString strPath2;
CString str;
WIN32_FIND_DATA wfd;
HANDLE h;
int nPos;
int nEndPos;
int nNewEndPos;
int nLastDir;
TCHAR buf[INTERNET_MAX_PATH_LENGTH];
CStringArray astrFavorites;
CStringArray astrDirs;
CMenu* pSubMenu;

if(strPath[strPath.GetLength() - 1] != _T('\\'))
strPath += _T('\\');
strPath2 = strPath;
strPath += "*.*";

h = FindFirstFile(strPath, &wfd);
if(h != INVALID_HANDLE_VALUE)
{
nEndPos = nStartPos;
do
{
if((wfd.dwFileAttributes & (FILE_ATTRIBUTE_DIRECTORY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM))==0)
{
str = wfd.cFileName;
if(str.Right(4) == _T(".url"))
{ ::GetPrivateProfileString(_T("InternetShortcut"), _T("URL"),
_T(""), buf, INTERNET_MAX_PATH_LENGTH,
strPath2 + str);
str = str.Left(str.GetLength() - 4);

// scan through the array and perform an insertion sort
// to make sure the menu ends up in alphabetic order
for(nPos = nStartPos ; nPos < nEndPos ; ++nPos)
{
if(str.CompareNoCase(astrFavorites[nPos]) < 0)
break;
}
astrFavorites.InsertAt(nPos, str);
m_astrFavoriteURLs.InsertAt(nPos, buf);
++nEndPos;
}
}
} while(FindNextFile(h, &wfd));
FindClose(h);
// Now add these items to the menu
for(nPos = nStartPos ; nPos < nEndPos ; ++nPos)
{
pMenu->AppendMenu(MF_STRING | MF_ENABLED, 0xe00 + nPos, astrFavorites[nPos]);
}
nLastDir = 0;
h = FindFirstFile(strPath, &wfd);
ASSERT(h != INVALID_HANDLE_VALUE);
do
{
if(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if(lstrcmp(wfd.cFileName, _T(".")) == 0 || lstrcmp(wfd.cFileName, _T("..")) == 0)
continue;

for(nPos = 0 ; nPos < nLastDir ; ++nPos)
{
if(astrDirs[nPos].CompareNoCase(wfd.cFileName) > 0)
break;
}
pSubMenu = new CMenu;
pSubMenu->CreatePopupMenu();

// call this function recursively.
nNewEndPos = BuildFavoritesMenu(strPath2 + wfd.cFileName, nEndPos, pSubMenu);
if(nNewEndPos != nEndPos)
{
// only intert a submenu if there are in fact .URL files in the subdirectory
nEndPos = nNewEndPos;
pMenu->InsertMenu(nPos, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT)pSubMenu->m_hMenu, wfd.cFileName);
pSubMenu->Detach();
astrDirs.InsertAt(nPos, wfd.cFileName);
++nLastDir;
}
delete pSubMenu;
}
} while(FindNextFile(h, &wfd));
FindClose(h);
}
return nEndPos;
}
void CMainFrame::OnNewAddress()
{
CString str;
m_wndAddress.GetLBText(m_wndAddress.GetCurSel(), str);
((CSampleBrowerView*)GetActiveView())->Navigate2(str, 0, NULL);
}
展开
 我来答
kg33optsp
2011-06-07 · TA获得超过243个赞
知道答主
回答量:507
采纳率:0%
帮助的人:0
展开全部

这是MFC里面定义的消息映射,斜杠部分不做解释了,本来就是注释
BEGIN_MESSAGE_MAP(CPApp, CWinApp) //消息映射起始
ON_COMMAND(ID_APP_ABOUT, OnAppAbout) //名字为ID_APP_ABOUT的按钮按下去之后响应OnAppAbout函数
ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew) //名字为ID_FILE_NEW的按钮按下去之后响应CWinApp::OnFileNew函数
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)//名字为ID_FILE_OPEN的按钮按下去之后响应CWinApp::OnFileOpen函数
ON_COMMAND(ID_FILE_PRINT_SETUP,CWinApp::OnFilePrintSetup) //名字为ID_FILE_PRINT_SETUP的按钮按下去之后响应CWinApp::OnFilePrintSetup函数
END_MESSAGE_MAP() //消息映射定义结束
匿名用户
2011-06-07
展开全部
你在
astrFavorites.InsertAt(nPos, str);
前边加上
AfxMessageBox(str);


pMenu->InsertMenu(nPos, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT)pSubMenu->m_hMenu, wfd.cFileName);
前边加上
AfxMessageBox(wfd.cFileName);

然后编译运行就知了
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式