mainfrm.cpp
来自「myie2.4版本的源代码」· C++ 代码 · 共 2,175 行 · 第 1/5 页
CPP
2,175 行
pHistory->back(&v);
}
}
}
}
}catch(...)
{
}
try{
if(pHistory != NULL)
pHistory->Release();
if(pHTMLWnd != NULL)
pHTMLWnd->Release();
if(pHTMLDoc != NULL)
pHTMLDoc->Release();
if(pDisp != NULL)
pDisp->Release();
}
catch(...)
{
}
}*/
tcf->m_pView->m_nBackSteps = cmd;
}
}catch(...)
{
}
}
else if(pNMToolBar->iItem == ID_GO_FORWARD)
{
try{
CMenu pPopup;
CChildFrame* tcf = (CChildFrame*)MDIGetActive();
if (tcf!=NULL && tcf->m_pView!=NULL)
{
// the font popup is stored in a resource
pPopup.CreatePopupMenu();
int i=0, l=0;
for(i=tcf->m_pView->m_nCurHistory+1; i<tcf->m_pView->m_nHistoryLength && l<9; i++)
{
if(tcf->m_pView->m_astrHistory.GetAt(i).IsEmpty())
pPopup.AppendMenu(MF_STRING, l + 1, tcf->m_pView->m_astrHistoryURL.GetAt(i));
else
pPopup.AppendMenu(MF_STRING, l + 1, tcf->m_pView->m_astrHistory.GetAt(i));
l++;
}
int cmd = pPopup.TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RETURNCMD | TPM_NONOTIFY, rect.left, rect.top + 1, AfxGetMainWnd());
pPopup.DestroyMenu();
//for(i=0; i<cmd; i++)
//2.2
if(cmd>0)
tcf->m_pView->GoForward(cmd);
tcf->m_pView->m_nBackSteps = -cmd;
}
}catch(...)
{
}
}
else if(pNMToolBar->iItem == ID_TOOLS_EMAIL)
{
try{
CMenu pPopup;
pPopup.CreatePopupMenu();
//get all email clients from registry
static TCHAR sz[MAX_PATH+1];
HKEY hKey;
DWORD dwSize = MAX_PATH+1;
int i = 0;
// find out from the registry where the mail clients are located.
if(RegOpenKey(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Clients\\Mail"), &hKey) == ERROR_SUCCESS)
{
while(RegEnumKey(hKey, i, sz, dwSize) == ERROR_SUCCESS)
{
pPopup.AppendMenu(MF_STRING, i+1, sz);
i++;
}
int cmd = pPopup.TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RETURNCMD | TPM_NONOTIFY, rect.left, rect.top + 1, AfxGetMainWnd());
pPopup.DestroyMenu();
if(cmd>0 && RegEnumKey(hKey, cmd-1, sz, dwSize) == ERROR_SUCCESS)
{
LaunchEmail(sz);
}
RegCloseKey(hKey);
}
}catch(...)
{
}
}
else if(pNMToolBar->iItem == ID_EDIT_EDIT)
{
CMenu pPopup;
pPopup.CreatePopupMenu();
//get all email clients from registry
static TCHAR sz[MAX_PATH+1];
HKEY hKey, hKey2;
DWORD dwSize = MAX_PATH+1;
int i = 0, l = 1;
CString key;
CStringArray editors;
// find out from the registry where the editor clients are located.
if(RegOpenKey(HKEY_CLASSES_ROOT, _T(".htm\\OpenWithList"), &hKey) == ERROR_SUCCESS)
{
while(RegEnumKey(hKey, i, sz, dwSize) == ERROR_SUCCESS)
{
key = "Applications\\";
key += sz;
key += "\\shell";
if(RegOpenKey(HKEY_CLASSES_ROOT, key, &hKey2) == ERROR_SUCCESS)
{
RegQueryValueEx(hKey2, _T("FriendlyCache"), NULL, NULL, (LPBYTE)sz, &dwSize);
editors.Add(key);
pPopup.AppendMenu(MF_STRING, l, sz);
l++;
RegCloseKey(hKey2);
}
dwSize = MAX_PATH+1;
i++;
}
int cmd = pPopup.TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RETURNCMD | TPM_NONOTIFY, rect.left, rect.top + 1, AfxGetMainWnd());
pPopup.DestroyMenu();
RegCloseKey(hKey);
if(cmd>0)
{
key = editors.GetAt(cmd-1);
key += "\\edit\\command";
if(RegOpenKey(HKEY_CLASSES_ROOT, key, &hKey2) == ERROR_SUCCESS)
{
dwSize = MAX_PATH+1;
RegQueryValueEx(hKey2, _T(""), NULL, NULL, (LPBYTE)sz, &dwSize);
RegCloseKey(hKey2);
CChildFrame* tcf = (CChildFrame*)MDIGetActive();
if (tcf!=NULL && tcf->m_pView!=NULL)
{
LaunchEditor(sz, tcf->m_pView->m_lpszUrl);
}
}
}
}
}
}catch(...)
{
}
*pResult = TBDDRET_DEFAULT;
}
int CMainFrame::BuildFavoritesMenu(LPCTSTR pszPath, int nStartPos, CMenu* pMenu,int nFixMenu, int FirstLevel, int& nFavs, int& nMostFavs)
{
CString strPath;
CString strPath2;
CString str, str2;
WIN32_FIND_DATA wfd;
HANDLE h;
int nPos;
int nEndPos;
int nLastDir;
// TCHAR buf[INTERNET_MAX_PATH_LENGTH];
CStringArray astrFavorites;
CArray<int,int> anFavID;
CStringArray astrDirs;
// CMenu* pSubMenu;
BOOL isLink = FALSE;
static CString strOpenAll, strOpenMost;
int nSubFavs = 0, nSubMostFavs = 0;
try
{
strPath = pszPath;
nFavs = 0; nMostFavs = 0;
strOpenAll.LoadString(IDS_OPEN_ALL_FAV);
strOpenMost.LoadString(IDS_OPEN_ALL_MOSTFAV);
// make sure there's a trailing backslash
if(strPath[strPath.GetLength() - 1] != _T('\\'))
strPath += _T('\\');
if(strPath==m_strLinkFolder)
isLink = TRUE;
strPath2 = strPath;
strPath += "*.*";
nLastDir = 0;
// now scan the directory, first for .URL files and then for subdirectories
// that may also contain .URL files
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; str2= str;
str.MakeLower();
if(str.Right(4) == _T(".url"))
{
nPos = nEndPos;
astrFavorites.Add( str2);
anFavID.Add(nPos);
// m_astrFavoriteURLs.InsertAt(nPos, buf);
++nEndPos;
nFavs ++;
}
else if(str.Right(4) == _T(".lnk"))
{
//if(ResolveLink(strPath2 + str, buf))
{
// 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;
}*/
nPos = nEndPos;
//m_astrFavoriteURLs.InsertAt(nPos, buf);
// m_astrFavoriteURLs.InsertAt(nPos, strPath2 + str);
//str2 = str2.Left(str2.GetLength() - 4);
astrFavorites.Add(str2);
anFavID.Add(nPos);
++nEndPos;
nFavs ++;
}
}
}
else if(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
// ignore the current and parent directory entries
if(lstrcmp(wfd.cFileName, _T(".")) == 0 || lstrcmp(wfd.cFileName, _T("..")) == 0 )//|| lstrcmp(wfd.cFileName, strcha) == 0 || lstrcmp(wfd.cFileName, strcha2) == 0
continue;
astrDirs.Add(wfd.cFileName);
nLastDir++;
}
} while(FindNextFile(h, &wfd));
FindClose(h);
}
if(isLink)
{
//remove all link buttons
int b = m_LinkBar.GetToolBarCtrl().GetButtonCount();
for(int i = 1; i<b;i++)
m_LinkBar.GetToolBarCtrl().DeleteButton(1);
REBARBANDINFO rbbi;
rbbi.cbSize = sizeof(rbbi);
rbbi.fMask = RBBIM_CHILDSIZE | RBBIM_IDEALSIZE | RBBIM_SIZE |RBBIM_ID ;
rbbi.wID = ID_VIEW_LINKS;
rbbi.cxMinChild = 2;
rbbi.cyMinChild = 22;
/*rbbi.cx =*/ rbbi.cxIdeal = 2;
int bandid = m_wndReBar.GetReBarCtrl().IDToIndex(ID_VIEW_LINKS);
m_wndReBar.GetReBarCtrl().SetBandInfo(bandid, &rbbi);
}
if(FirstLevel)
{
//remove all Fav buttons
int b = m_FavBar.GetToolBarCtrl().GetButtonCount();
for(int i = 0; i<b;i++)
m_FavBar.GetToolBarCtrl().DeleteButton(0);
REBARBANDINFO rbbi;
rbbi.cbSize = sizeof(rbbi);
rbbi.fMask = RBBIM_CHILDSIZE | RBBIM_IDEALSIZE | RBBIM_SIZE |RBBIM_ID ;
rbbi.wID = ID_VIEW_FAVS;
rbbi.cxMinChild = 2;
rbbi.cyMinChild = 22;
/*rbbi.cx =*/ rbbi.cxIdeal = 2;
int bandid = m_wndReBar.GetReBarCtrl().IDToIndex(ID_VIEW_FAVS);
m_wndReBar.GetReBarCtrl().SetBandInfo(bandid, &rbbi);
}
//////////////////////////////// Now add these items to the menu
CMenuOrder mo;
BOOL found;
int j;
WORD type;
if(GetFavoriteFolder(strPath))
{
strPath = strPath2.Mid(strPath.GetLength()+1);
if(mo.LoadMenuOrder(strPath))
{
for(int i = 0; i<mo.len; i++)
{
str = mo.mois[mo.index[i]].longname;
type = mo.mois[mo.index[i]].filetype;
//find in url first
found = FALSE;
for(j = 0; j<astrFavorites.GetSize() && !found && (type==0x20 || type==0); j++)
{
if(astrFavorites[j].CompareNoCase(str)==0)
{
found = TRUE;
//add
FavMenuAddURL(astrFavorites[j], strPath2, isLink, pMenu, anFavID[j], nMostFavs);
astrFavorites[j].Empty();
}
}
for(j = 0; j<astrDirs.GetSize() && !found && (type==0x10 || type==0x14 || type==0); j++)
{
if(astrDirs[j].CompareNoCase(str)==0)
{
//add
FavMenuAddFolder(astrDirs[j], strPath2, FirstLevel, isLink, pMenu, nEndPos);
astrDirs[j].Empty();
}
}
}
}
}
//sort dirs and favs
CString tmp;
int n = astrDirs.GetSize();
int i, ch, m;
ch = n;
while(ch>0)
{
m = ch-1; ch = 0;
for(i=1; i<=m; i++)
{
if(lstrcmp(astrDirs[i-1], astrDirs[i])>0)
{
tmp = astrDirs[i-1];
astrDirs[i-1] = astrDirs[i];
astrDirs[i] = tmp;
ch = i;
}
}
}
n = astrFavorites.GetSize();
ch = n;
int ntmp;
while(ch>0)
{
m = ch-1; ch = 0;
for(i=1; i<=m; i++)
{
if(lstrcmpiA(astrFavorites[i-1], astrFavorites[i])>0)
{
tmp = astrFavorites[i-1];
astrFavorites[i-1] = astrFavorites[i];
astrFavorites[i] = tmp;
ntmp = anFavID[i-1];
anFavID[i-1] = anFavID[i];
anFavID[i] = ntmp;
ch = i;
}
}
}
for(i = 0; i<astrDirs.GetSize(); i++)
{
if(astrDirs[i].IsEmpty())
continue;
FavMenuAddFolder(astrDirs[i], strPath2, FirstLevel, isLink, pMenu, nEndPos);
}
for(i = 0 ; i < astrFavorites.GetSize() ; i++)
{
if(astrFavorites[i].IsEmpty())
continue;
FavMenuAddURL(astrFavorites[i], strPath2, isLink, pMenu, anFavID[i], nMostFavs);
}
/////////////////////////////////////////////////////////////////
//add a break if needed
if(!bSingleMenu)
AddMenuBreak(pMenu);
if(isLink)
{
CRect rectToolBar;
REBARBANDINFO rbbi;
m_LinkBar.GetItemRect(0, &rectToolBar);
//m_LinkBar.SetSizes(rectToolBar.Size(), CSize(16,100));
rbbi.cbSize = sizeof(rbbi);
rbbi.fMask = RBBIM_CHILDSIZE | RBBIM_IDEALSIZE | RBBIM_SIZE |RBBIM_ID ;
rbbi.wID = ID_VIEW_LINKS;
rbbi.cxMinChild = rectToolBar.Width()+2;
if(rectToolBar.Height()<22)
rbbi.cyMinChild = 22;
else
rbbi.cyMinChild = re
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?