📄 ie6mdi.cpp
字号:
}
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, 0xe05 + nPos, astrFavorites[nPos]);
}
// now that we've got all the .URL files, check the subdirectories for more
nLastDir = 0;
h = FindFirstFile(strPath, &wfd);
ASSERT(h != INVALID_HANDLE_VALUE);
do
{
if(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
// ignore the current and parent directory entries
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 insert 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;
}
/*
*******************************************************************************/
// FUNCTION : void CIE6mdiApp::OnFavorite(UINT)
//
// PURPOSE : called when the user click on a favorite
//
// PARAMETERS :
// nID - poisition of the favorite
//
// RETURN VALUE : void
//
//
// COMMENTS :
//
//
/*******************************************************************************
*/
void CIE6mdiApp::OnFavorite(UINT nID)
{
// Get the active view
CMainFrame *pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame();
CIE6mdiView *pView = (CIE6mdiView *) pChild->GetActiveView();
if (pView == NULL) {
AfxGetApp()->m_pMainWnd->SendMessage(WM_COMMAND,(WPARAM)ID_FILE_NEW,(LPARAM)NULL);
pChild = (CMDIChildWnd *) pFrame->GetActiveFrame();
pView = (CIE6mdiView *) pChild->GetActiveView();
pView->Navigate2(m_astrFavoriteURLs[nID-0xe05], 0, NULL);
return;
}
else
pView->Navigate2(m_astrFavoriteURLs[nID-0xe05], 0, NULL);
}
/*
*******************************************************************************/
// FUNCTION : void CIE6mdiApp::OnWindowRemindwindow()
//
// PURPOSE : update the state of the menue item "Remind Window"
//
// PARAMETERS : none
//
// RETURN VALUE : void
//
//
// COMMENTS : update m_iRemindWindow
//
//
/*******************************************************************************
*/
void CIE6mdiApp::OnWindowRemindwindow()
{
CMenu* pTopMenu = AfxGetMainWnd()->GetMenu();
CMenu* pMenu = pTopMenu->GetSubMenu(4);
int m_iRemindWindow = AfxGetApp()->GetProfileInt("Settings","RemindWindow",1);
if (m_iRemindWindow == 1) {
pMenu->CheckMenuItem(ID_WINDOW_REMINDCONFIGURATION,MF_BYCOMMAND | MF_UNCHECKED);
AfxGetApp()->WriteProfileInt("Settings","RemindWindow",0);
m_iRemindWindow = 0;
}
else {
pMenu->CheckMenuItem(ID_WINDOW_REMINDCONFIGURATION,MF_BYCOMMAND | MF_CHECKED);
AfxGetApp()->WriteProfileInt("Settings","RemindWindow",1);
m_iRemindWindow = 1;
}
}
/*
*******************************************************************************/
// FUNCTION : void CIE6mdiApp::OnFileNew2()
//
// PURPOSE : open a new window, located at the address of the active view
//
// PARAMETERS : none
//
// RETURN VALUE : void
//
//
// COMMENTS :
//
//
/*******************************************************************************
*/
void CIE6mdiApp::OnFileNew2()
{
CMainFrame *pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
CMDIChildWnd *pChild;
CIE6mdiView *pView;
pChild = (CMDIChildWnd *) pFrame->GetActiveFrame();
if (pChild == NULL)
goto normal;
pView = (CIE6mdiView *) pChild->GetActiveView();
if (pView == NULL)
goto normal;
else {
// open a new window at the current location !
int Popup = pView->m_iPopupWindow;
CString url = pView->GetLocationURL();
AfxGetApp()->m_pMainWnd->SendMessage(WM_COMMAND,(WPARAM)ID_FILE_NEW,(LPARAM)NULL);
pChild = (CMDIChildWnd *) pFrame->GetActiveFrame();
pView = (CIE6mdiView *) pChild->GetActiveView();
// Pview is the new window
pView->SetPopupType(Popup);
if (url.GetLength() != 0)
pView->Navigate2(url);
}
return;
normal: {
AfxGetApp()->m_pMainWnd->SendMessage(WM_COMMAND,(WPARAM)ID_FILE_NEW,(LPARAM)NULL);
return;
}
}
/*
*******************************************************************************/
// FUNCTION : int CIE6mdiApp::ExitInstance()
//
// PURPOSE :
//
// PARAMETERS : none
//
// RETURN VALUE : int
//
//
// COMMENTS :
//
//
/*******************************************************************************
*/
int CIE6mdiApp::ExitInstance()
{
return CWinApp::ExitInstance();
}
/*
*******************************************************************************/
// FUNCTION : BOOL CIE6mdiApp::OnDDECommand(LPTSTR)
//
// PURPOSE : not used
//
// PARAMETERS :
// lpszCommand -
//
// RETURN VALUE : BOOL
//
//
// COMMENTS :
//
//
/*******************************************************************************
*/
BOOL CIE6mdiApp::OnDDECommand(LPTSTR lpszCommand)
{
return CWinApp::OnDDECommand(lpszCommand);
}
/*
*******************************************************************************/
// FUNCTION : void CIE6mdiApp::OnAddFavorite()
//
// PURPOSE :
//
// PARAMETERS : none
//
// RETURN VALUE : void
//
//
// COMMENTS :
//
//
/*******************************************************************************
*/
void CIE6mdiApp::OnAddFavorite()
{
CMainFrame *pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
CMDIChildWnd *pChild;
CIE6mdiView *pView;
CDlgFavorites dlg;
pChild = (CMDIChildWnd *) pFrame->GetActiveFrame();
if (pChild == NULL)
goto normal;
pView = (CIE6mdiView *) pChild->GetActiveView();
if (pView == NULL)
goto normal;
dlg.m_Name = pView->GetDocument()->GetTitle();
dlg.m_Url = pView->GetLocationURL();
dlg.m_static_name = CString(LPCTSTR(IDS_FAV_DLG_NAME));
dlg.m_static_url = CString(LPCTSTR(IDS_FAV_DLG_URL));
if (dlg.DoModal() == IDOK) {
CString FullName(m_strFavoritesPath);
FullName += "\\" + dlg.m_Name + ".url";
CFile file;
if (!file.Open(FullName, CFile::modeCreate | CFile::modeWrite))
return;
CString Data("[InternetShortcut]\r\nURL=");
Data += dlg.m_Url;
char *buf;
buf = (char*)malloc((Data.GetLength()+1)*sizeof(char));
buf[0]='\0';
strcpy(buf,(LPCTSTR)(Data));
file.Write(buf,Data.GetLength());
free(buf);
file.Close();
CreateFavorites();
}
return;
normal: { // it should not be the case !!!
AfxMessageBox(CString(LPCTSTR(IDS_NO_BROWSER)));
return;
}
}
/*
*******************************************************************************/
// FUNCTION : void CIE6mdiApp::OnRemoveFavorite()
//
// PURPOSE : remove a file from the favorite. Allows the user to manage the favorites
//
// PARAMETERS : none
//
// RETURN VALUE : void
//
//
// COMMENTS : if Cancel is pushed, a refresh will be done anyway (the user maybe moved
// url's...
//
//
/*******************************************************************************
*/
void CIE6mdiApp::OnRemoveFavorite()
{
CFileDialog dlg(TRUE, "Favorites files","*.URL",OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
CString(LPCTSTR(IDS_FAVTYPE)));
OPENFILENAME op = dlg.m_ofn;
op.lpstrInitialDir = m_strFavoritesPath;
op.lpstrTitle = CString(LPCTSTR(IDS_REMOVE_FAVORITES));
dlg.m_ofn = op;
if (dlg.DoModal() == IDOK) {
CFile::Remove( dlg.GetPathName() );
}
CreateFavorites();
}
/*
*******************************************************************************/
// FUNCTION : void CIE6mdiApp::OnRefreshFavorite()
//
// PURPOSE : Refresh the favorite menu
//
// PARAMETERS : none
//
// RETURN VALUE : void
//
//
// COMMENTS :
//
//
/*******************************************************************************
*/
void CIE6mdiApp::OnRefreshFavorite()
{
CreateFavorites();
}
/*
*******************************************************************************/
// FUNCTION : void CIE6mdiApp::CreateFavorites()
//
// PURPOSE : create/refresh the favorites menu !
//
// PARAMETERS : none
//
// RETURN VALUE : void
//
//
// COMMENTS :
//
//
/*******************************************************************************
*/
int CIE6mdiApp::CreateFavorites()
{
// if its refresh, we have to clean m_astrFavoriteURLs
m_astrFavoriteURLs.RemoveAll();
////////////////////////
// set up Favorites menu
////////////////////////
TCHAR sz[MAX_PATH];
TCHAR szPath[MAX_PATH];
HKEY hKey;
DWORD dwSize;
CMenu* pMenu;
// first get rid of bogus submenu items.
pMenu = AfxGetMainWnd()->GetMenu()->GetSubMenu(3);
while(pMenu->DeleteMenu(0, MF_BYPOSITION));
pMenu->AppendMenu(MF_SEPARATOR, 0xe00 , "Separator");
pMenu->AppendMenu(MF_STRING | MF_ENABLED, 0xe01 , "Add");
pMenu->AppendMenu(MF_STRING | MF_ENABLED, 0xe02 , "Remove");
pMenu->AppendMenu(MF_STRING | MF_ENABLED, 0xe03 , "Refresh");
pMenu->AppendMenu(MF_SEPARATOR, 0xe04 , "Separator");
// find out from the registry where the favorites are located.
if(RegOpenKey(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders"), &hKey) != ERROR_SUCCESS)
{
TRACE0("Favorites folder not found\n");
return 0;
}
dwSize = sizeof(sz);
RegQueryValueEx(hKey, _T("Favorites"), NULL, NULL, (LPBYTE)sz, &dwSize);
ExpandEnvironmentStrings(sz, szPath, MAX_PATH);
RegCloseKey(hKey);
m_strFavoritesPath = szPath;
BuildFavoritesMenu(szPath, 0, pMenu);
return 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -