📄 mainfrm.cpp
字号:
m_astrFavoriteURLs.InsertAt(nEndPos, m_strFavDirOpen);
favstruct.pMenu->AppendMenu(MF_SEPARATOR);
FavDirItem *obj=new (FavDirItem);
obj->nID=0xe00 + nEndPos;
m_FavDirItem.Add(obj);
nEndPos++;
if(h != INVALID_HANDLE_VALUE)
{
// now that we've got all the .URL files, check the subdirectories for more
// nLastDir = 0;
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;
pSubMenu =favstruct.pMenu->AppendODPopupMenu(wfd.cFileName);
GetFileIcon(strPath2 + wfd.cFileName,icon);
favstruct.pMenu->ModifyODMenu(NULL,wfd.cFileName,favstruct.imaglist,icon);
// call this function recursively.
BuildFavStruct favstructSub;
favstructSub.imaglist=favstruct.imaglist;
favstructSub.nStartPos=nEndPos;
favstructSub.pMenu=pSubMenu;
favstructSub.pszPath=strPath2 + wfd.cFileName;
CString foldername;
GetLinkFolderName(foldername);
if(foldername==wfd.cFileName)
favstructSub.IsLinkFolder=TRUE;
else
favstructSub.IsLinkFolder=FALSE;
nNewEndPos = BuildFavoritesMenu(favstructSub);
if(nNewEndPos != nEndPos)
{
// only intert a submenu if there are in fact .URL files in the subdirectory
nEndPos = nNewEndPos;
//strDirs.InsertAt(nPos, wfd.cFileName);
// ++nLastDir;
}
}
} while(FindNextFile(h, &wfd));
FindClose(h);
astrDirs.RemoveAll();
h = FindFirstFile(strPath, &wfd);
ASSERT(h != INVALID_HANDLE_VALUE);
nPos=nEndPos;
do
{
if((wfd.dwFileAttributes & (FILE_ATTRIBUTE_DIRECTORY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM))==0)
{
str = wfd.cFileName;
if(str.Right(4) == _T(".url"))
{
// an .URL file is formatted just like an .INI file, so we can
// use GetPrivateProfileString() to get the information we want
::GetPrivateProfileString(_T("InternetShortcut"), _T("URL"),
_T(""), buf, INTERNET_MAX_PATH_LENGTH,
strPath2 + str);
GetFileIcon(strPath2 + str,icon);
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
if(str.GetLength()>50)
str=str.Left(50)+"...";
astrFavorites.InsertAt(nEndPos, str);
m_astrFavoriteURLs.InsertAt(nEndPos, buf);
favstruct.pMenu->AppendMenu(MF_STRING | MF_ENABLED, 0xe00 + nEndPos,astrFavorites[nEndPos]);
favstruct.pMenu->ModifyODMenu(NULL,0xe00+nEndPos,favstruct.imaglist,icon);
if(favstruct.IsLinkFolder)
{
BuildLinkStruct *linkstruct=new (BuildLinkStruct);
linkstruct->icon=icon;
linkstruct->nID=0xe00+nEndPos;
linkstruct->strName=astrFavorites[nEndPos];
m_linkbarItem.Add(linkstruct);
}
++nEndPos;
}
}
} while(FindNextFile(h, &wfd));
obj->m_StartPos=nPos; //the nID startPos of the pages in this folder
obj->m_EndPos=nEndPos-1;//the nID endPos of the pages in this folder
FindClose(h);
astrFavorites.RemoveAll();
}
return nEndPos;
}
void CMainFrame::OnFavorite(UINT nID)
{
try
{
CString str=m_astrFavoriteURLs[nID-0xe00];
if(str==m_strFavDirOpen)//click on the open all item
{
FavDirItem *obj;
for(int i=0;i<m_FavDirItem.GetSize();i++)
{
obj=m_FavDirItem[i];
if(obj&&nID==obj->nID)
{
for(UINT j=obj->m_StartPos;j<=obj->m_EndPos;j++)
{
if(j>=0&&j<(UINT)m_astrFavoriteURLs.GetSize())
NavigateToUrl(m_astrFavoriteURLs[j],0);
}
return;
}
}
}
NavigateToUrl(str,0);//click on the URL item
m_AddressCom->GetComboBoxCtrl()->AddString(m_astrFavoriteURLs[nID-0xe00]);
m_AddressCom->GetComboBoxCtrl()->SelectString(-1,m_astrFavoriteURLs[nID-0xe00]);
}
catch(...)
{
}
}
BOOL CMainFrame::LoadFrame(UINT nIDResource, DWORD dwDefaultStyle, CWnd* pParentWnd, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class
return CMDIFrameWndEx::LoadFrame(nIDResource, dwDefaultStyle, pParentWnd, pContext);
}
void CMainFrame::OnOfflineFile()
{
// TODO: Add your command handler code here
try
{
BOOL offline=IsGlobalOffline();
INTERNET_CONNECTED_INFO ci;
memset(&ci, 0, sizeof(ci));
if(!offline) {
ci.dwConnectedState = INTERNET_STATE_DISCONNECTED_BY_USER;
ci.dwFlags = ISO_FORCE_DISCONNECTED;
}
else {
ci.dwConnectedState = INTERNET_STATE_CONNECTED;
}
::InternetSetOption(NULL, INTERNET_OPTION_CONNECTED_STATE, &ci, sizeof(ci));
}
catch(...)
{
}
}
void CMainFrame::OnUpdateOfflineFile(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(IsGlobalOffline());
}
BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
// TODO: Add your specialized code here and/or call the base class
if (m_MDIClient.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
return TRUE;
return CMDIFrameWndEx::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}
HMENU CMainFrame::NewMenu()
{
TCHAR sz[MAX_PATH];
TCHAR szPath[MAX_PATH];
HKEY hKey;
DWORD dwSize;
BCMenu* pMenu;
// first get rid of bogus submenu items.
m_menu.LoadMenu(IDR_BENBENTYPE);
BCMenu *submenu=(BCMenu *)m_menu.GetSubMenu(2)->GetSubMenu(13);
if(submenu)
{
while(submenu->DeleteMenu(0, MF_BYPOSITION));
CString menu_name;
for(int i=0;i<m_language.GetCount()&&i<(0xff-0x20);i++)
{
menu_name=m_language.GetAt(m_language.FindIndex(i));
submenu->AppendMenu(MF_STRING | MF_ENABLED,0x1020+i,menu_name);
if(menu_name==m_languageName)
submenu->CheckMenuItem(0x1020+i,MF_BYCOMMAND|MF_CHECKED);
}
}
SetNewLanguage(&m_menu);
pMenu=(BCMenu *)m_menu.GetSubMenu(3);
if(!pMenu)
{
MessageBox("built favorites menu failed");
return NULL;
}
while(pMenu->DeleteMenu(3, MF_BYPOSITION));
// 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 NULL;
}
dwSize = sizeof(sz);
RegQueryValueEx(hKey, _T("Favorites"), NULL, NULL, (LPBYTE)sz, &dwSize);
ExpandEnvironmentStrings(sz, szPath, MAX_PATH);
RegCloseKey(hKey);
//get the imagelist of the OS
CImageList m_ImageListSmall;
HIMAGELIST hImageList;
SHFILEINFO shFi;
hImageList=(HIMAGELIST)SHGetFileInfo("C:\\",0,&shFi,sizeof(shFi),
SHGFI_SYSICONINDEX|SHGFI_SMALLICON);
m_ImageListSmall.m_hImageList=hImageList;
BuildFavStruct favstruct;
favstruct.imaglist=&m_ImageListSmall;
favstruct.nStartPos=0;
favstruct.pMenu=pMenu;
favstruct.pszPath=szPath;
favstruct.IsLinkFolder=FALSE;
BuildFavoritesMenu(favstruct);//szPath,0, pMenu,&m_ImageListSmall);
m_ImageListSmall.Detach();//detach the imagelist
m_linkbar.Init();// important: BuildFavoritesMenu must be taken before call this fu to init the linkbar
CMenu *menu_translation=m_menu.GetSubMenu(4)->GetSubMenu(7);
BuildTranslationMenu(menu_translation);
CMenu *menu_mail=m_menu.GetSubMenu(4)->GetSubMenu(1);
BuildMailMenu(menu_mail);
return(m_menu.Detach());
}
void CMainFrame::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct)
{
BOOL setflag=FALSE;
if(lpMeasureItemStruct->CtlType==ODT_MENU){
if(IsMenu((HMENU)lpMeasureItemStruct->itemID)&&BCMenu::IsMenu((HMENU)lpMeasureItemStruct->itemID)){
m_menu.MeasureItem(lpMeasureItemStruct);
setflag=TRUE;
}
}
if(!setflag)CMDIFrameWndEx::OnMeasureItem(nIDCtl, lpMeasureItemStruct);
}
LRESULT CMainFrame::OnMenuChar(UINT nChar, UINT nFlags, CMenu* pMenu)
{
LRESULT lresult;
if(BCMenu::IsMenu(pMenu))
lresult=BCMenu::FindKeyboardShortcut(nChar, nFlags, pMenu);
else
lresult=CMDIFrameWndEx::OnMenuChar(nChar, nFlags, pMenu);
return(lresult);
}
void CMainFrame::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu)
{
CMDIFrameWndEx::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu);
// TODO: Add your message handler code here
//if(!bSysMenu){
// if(BCMenu::IsMenu(pPopupMenu))
// BCMenu::UpdateMenu(pPopupMenu);
//}
}
void CMainFrame::OnOptionTool()
{
// ShellExecute(0, "open", "control.exe", "inetcpl.cpl", ".", SW_SHOW);
ExecCmdTarget(&CGID_IWebBrowser, 3);
}
HRESULT CMainFrame::ExecCmdTarget(const GUID *pguidCmdGroup, DWORD nCmdID)
{
LPDISPATCH lpDispatch = NULL;
LPOLECOMMANDTARGET lpOleCommandTarget = NULL;
HRESULT hr = E_FAIL;
try
{
CBenbenBrowserView *pview=(CBenbenBrowserView *)GetbenActiveView();
if(!pview)
return hr;
lpDispatch = pview->GetHtmlDocument();
ASSERT(lpDispatch);
if (lpDispatch)
{
// Get an pointer for the IOleCommandTarget interface.
hr = lpDispatch->QueryInterface(IID_IOleCommandTarget, (void**)&lpOleCommandTarget);
ASSERT(lpOleCommandTarget);
lpDispatch->Release();
if (SUCCEEDED(hr))
{
// Invoke the given command id for the WebBrowser control
hr = lpOleCommandTarget->Exec(pguidCmdGroup, nCmdID, 0, NULL, NULL);
lpOleCommandTarget->Release();
}
}
}
catch(...)
{
}
return hr;
}
void CMainFrame::OnSourcecodeView()
{
// TODO: Add your command handler code here
ExecCmdTarget(&CGID_IWebBrowser, 2);
//ShellExecute(NULL, _T("open"),"readmail", NULL,NULL, SW_SHOW);
}
void CMainFrame::OnFindEdit()
{
// TODO: Add your command handler code here
ExecCmdTarget(&CGID_IWebBrowser, 1);
}
CView * CMainFrame::NewHtmlView(int type,BOOL beVisible)//type=2-->new always ,1-->the active view,0-->get a correct view
{
try
{
CBenbenBrowserApp *app=(CBenbenBrowserApp *)AfxGetApp();
CChildFrame *childframe=(CChildFrame *)GetActiveFrame();
CBenbenBrowserView *view=(CBenbenBrowserView *)childframe->GetActiveView();
if(type==2)//new always
return app->OnNewBenFile(beVisible||m_beVisibleNewWin);
else if(type==1)//the current view
{
if(view)
{
if(beVisible)
MDIActivate(view->GetParent());
return view;
}
else
return app->OnNewBenFile(beVisible||m_beVisibleNewWin);
}
else if(type==0)//the proper view
{
while(TRUE)
{
if(!view)
return app->OnNewBenFile(beVisible|m_beVisibleNewWin);
else if(!view->GetbeInUse()&&(view->GetLocationURL()=="about:blank"))
{
view->SetbeInUse(TRUE);
if(beVisible)
MDIActivate(view->GetParent());
return view;
}
childframe=(CChildFrame *)childframe->GetNextWindow();
if(!childframe)
return app->OnNewBenFile(beVisible|m_beVisibleNewWin);
view=(CBenbenBrowserView *)childframe->GetActiveView();
}
}
}
catch(...)
{
}
return NULL;
}
void CMainFrame::SetAddressComText(CString URL)
{
try
{
if(URL.IsEmpty())
return;
m_AddressCom->GetEditCtrl()->SetWindowText(URL);
COMBOBOXEXITEM item;
item.mask = CBEIF_IMAGE|CBEIF_SELECTEDIMAGE ;
item.iItem = -1;
item.iImage = 1;
item.iSelectedImage = 1;
m_AddressCom->SetItem(&item);
}
catch(...)
{
}
}
void CMainFrame::OnAddtolocklistTool()
{
// TODO: Add your command handler code here
CBenbenBrowserView *view=(CBenbenBrowserView *)GetbenActiveView();
if(!view)
return;
if(!m_lockURLlist.Find(view->GetLocationURL())&&view->GetLocationURL()!="about:blank"&&view->GetLocationURL()!="")
{
m_lockURLlist.AddTail(view->GetLocationURL());
view->SignAsPopup();
}
}
CView * CMainFrame::GetbenActiveView()
{
try
{
CChildFrame *childframe=(CChildFrame *)GetActiveFrame();
if( !childframe)
return NULL;
CView *view=childframe->GetActiveView();
return view;
}
catch(...)
{
}
return NULL;
}
///////////////////////////////////////////////////////
IMPLEMENT_DYNAMIC( CMainToolBar, CToolBarEx )
CMainToolBar::CMainToolBar()
{
}
void CMainToolBar::Init()
{
static TBBUTTONEX tbButtons[] =
{
{ { 0, ID_FILE_NEW_BLANK, TBSTATE_ENABLED, TBSTYLE_BUTTON |TBSTYLE_DROPDOWN, 0, 0 }, true},
{ { 1, ID_GO_BACK, TBSTATE_ENABLED, TBSTYLE_BUTTON |TBSTYLE_DROPDOWN, 0, 0 }, true},
{ { 2, ID_GO_FORWARD, TBSTATE_ENABLED, TBSTYLE_BUTTON |TBSTYLE_DROPDOWN, 0, 0 }, true},
{ { 3, ID_VIEW_STOP, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0 }, true },
{ { 0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0 }, true },
{ { 4, ID_VIEW_REFRESH, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0 }, true},
{ { 5, ID_GO_START_PAGE, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0 }, true},
{ { 0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0 }, true},
{ { 6, ID_GO_SEARCH_THE_WEB, TBSTATE_ENABLED, TBSTYLE_BUTTON |TBSTYLE_DROPDOWN, 0, 0 }, true},
{ { 7, ID_FAVORITES_DROPDOWN,TBSTATE_ENABLED, TBSTYLE_BUTTON |TBSTYLE_DROPDOWN, 0, 0 },true },
{ { 12, ID_FILE_PRINT, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0 }, true },
{ { 11, ID_FONT_DROPDOWN, TBSTATE_ENABLED, TBSTYLE_BUTTON |TBSTYLE_DROPDOWN, 0, 0 }, true},
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -