📄 mainfrm.cpp
字号:
else if(kbuf[VK_SHIFT]&128 )
str="www."+str+".com";
else if(kbuf[VK_CONTROL]&128 )
str="www."+str+".org";
}
NavigateToUrl(str,type,TRUE);
PlayAnimate();
}
if(m_AddressBar.FindStringExact(-1,str) == CB_ERR)
{
COMBOBOXEXITEM item;
item.mask = CBEIF_TEXT|CBEIF_IMAGE|CBEIF_SELECTEDIMAGE ;
item.iItem = 0;
item.pszText = (LPTSTR)(LPCTSTR)str;
item.iImage = 1;
item.iSelectedImage = 1;
m_AddressCom->InsertItem(&item);
}
}
catch(...)
{
}
}
void CMainFrame::DoNothing()
{
}
void CMainFrame::OnDropDown(NMHDR* pNotifyStruct, LRESULT* pResult)
{
try
{ // this function handles the dropdown menus from the toolbar
NMTOOLBAR* pNMToolBar = (NMTOOLBAR*)pNotifyStruct;
CRect rect;
// translate the current toolbar item rectangle into screen coordinates
// so that we'll know where to pop up the menu
::SendMessage( pNMToolBar->hdr.hwndFrom,
TB_GETRECT, pNMToolBar->iItem, ( LPARAM )&rect );
rect.top = rect.bottom;
::ClientToScreen( pNMToolBar->hdr.hwndFrom, &rect.TopLeft() );
if(pNMToolBar->iItem == ID_FONT_DROPDOWN)
{
CMenu *menu;
CMenu* pPopup;
menu=CMenu::FromHandle( m_wndMenuBar.GetMenu())->GetSubMenu(2);
pPopup=menu->GetSubMenu(11);
// the font popup is stored in a resource
if(pPopup)
pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON, rect.left, rect.top + 1, AfxGetMainWnd());
//pPopup->DestroyMenu();
}
else if(pNMToolBar->iItem == ID_FAVORITES_DROPDOWN)
{
CMenu* pPopup;
// for the favorties popup, just steal the menu from the main window
pPopup = CMenu::FromHandle( m_wndMenuBar.GetMenu())->GetSubMenu(3);
if(pPopup)
pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON, rect.left, rect.top + 1, AfxGetMainWnd());
}
else if(pNMToolBar->iItem == ID_GO_BACK||pNMToolBar->iItem == ID_GO_FORWARD)
{
//CChildFrame *childfrm=(CChildFrame *)GetActiveFrame();
CBenbenBrowserView* pView = (CBenbenBrowserView*)GetbenActiveView();
ASSERT_VALID (pView);
CMenu pSubMenu;
pSubMenu.CreatePopupMenu();
if(GetIEHistory(&pSubMenu,pNMToolBar->iItem))
{
UINT nID = pSubMenu.TrackPopupMenu( TPM_LEFTALIGN | TPM_RIGHTBUTTON|TPM_RETURNCMD|TPM_NONOTIFY,
rect.left, rect.top + 1,AfxGetApp()->m_pMainWnd);
while(nID)
{
if(pNMToolBar->iItem == ID_GO_BACK)
pView->GoBack();
else
pView->GoForward();
nID--;
}
}
else
{
CBenbenBrowserDoc* pDoc = pView->GetDocument();
ASSERT_VALID(pDoc);
_T_HistotyList lst;
if (pNMToolBar->iItem == ID_GO_BACK)
{
pDoc->GetBackList (lst);
}
else
{
pDoc->GetFrwdList (lst);
}
if (!lst.IsEmpty ())
{
// CMenu pSubMenu;
// pSubMenu.CreatePopupMenu();
for (POSITION pos = lst.GetHeadPosition (); pos != NULL;)
{
CHistoryObj* pObj = lst.GetNext (pos);
ASSERT (pObj != NULL);
pSubMenu.AppendMenu(MF_STRING | MF_ENABLED,pObj->GetCommand (), pObj->GetTitle ());
}
pSubMenu.TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON, rect.left, rect.top + 1, AfxGetMainWnd());
//pSubMenu.DestroyMenu();
lst.RemoveAll();
}
}
pSubMenu.DestroyMenu();
}
else if(pNMToolBar->iItem == ID_GO_SEARCH_THE_WEB)
{
if(m_searchpages.GetCount()>0)
{
CMenu pSubMenu;
pSubMenu.CreatePopupMenu();
CString name,URL;
int j=0;
for (int i=0;i<m_searchpages.GetCount();i++)
{
name=m_searchpages.GetAt(m_searchpages.FindIndex(i));
name=name.Left(name.Find("="));
if(name=="-")
pSubMenu.AppendMenu(MF_SEPARATOR);
else
{
pSubMenu.AppendMenu(MF_STRING | MF_ENABLED,j+1,name);
j++;
}
}
UINT nID = pSubMenu.TrackPopupMenu( TPM_LEFTALIGN | TPM_RIGHTBUTTON|TPM_RETURNCMD|TPM_NONOTIFY,
rect.left, rect.top + 1,AfxGetApp()->m_pMainWnd);
if(nID>0 && nID<=(UINT)m_searchpages.GetCount())
{
URL=m_searchpages.GetAt(m_searchpages.FindIndex(nID-1));
URL=URL.Mid(URL.Find("=")+1);
NavigateToUrl(URL,1);
}
pSubMenu.DestroyMenu();
}
}
else if(pNMToolBar->iItem == ID_SETPROXY_TOOL)
{
if(m_proxylist.GetCount()>0)
{
CMenu pSubMenu;
pSubMenu.CreatePopupMenu();
CString name,URL,proxyname;
//pSubMenu.AppendMenu(MF_STRING | MF_ENABLED,0,"Not Use Proxy");
//pSubMenu.AppendMenu(MF_SEPARATOR);
for (int i=0;i<m_proxylist.GetCount();i++)
{
name=m_proxylist.GetAt(m_proxylist.FindIndex(i));
proxyname=name.Mid(name.Find("=")+1);
name=name.Left(name.Find("="));
pSubMenu.AppendMenu(MF_STRING | MF_ENABLED,i+1,name);
if(m_CurrentProxy==proxyname)
pSubMenu.CheckMenuItem(i+1,MF_BYCOMMAND|MF_CHECKED);
}
UINT nID = pSubMenu.TrackPopupMenu( TPM_LEFTALIGN | TPM_RIGHTBUTTON|TPM_RETURNCMD|TPM_NONOTIFY,
rect.left, rect.top + 1,AfxGetApp()->m_pMainWnd);
INTERNET_PROXY_INFO ipi;
if(nID>0&&nID<(UINT)m_proxylist.GetCount()+1)
{
URL=m_proxylist.GetAt(m_proxylist.FindIndex(nID-1));
URL=URL.Mid(URL.Find("=")+1);
DWORD dwSize = sizeof(ipi);
if(m_CurrentProxy==URL)
{
ipi.dwAccessType = INTERNET_OPEN_TYPE_DIRECT ;
m_CurrentProxy="";
}
else
{
ipi.dwAccessType = INTERNET_OPEN_TYPE_PROXY ;
ipi.lpszProxy = URL;
ipi.lpszProxyBypass = m_local_pass?"<local>":"";
m_CurrentProxy=URL;
}
if(!InternetSetOption(NULL, INTERNET_OPTION_PROXY, &ipi, dwSize))
MessageBox("set proxy failed");
}
pSubMenu.DestroyMenu();
}
}
else if(pNMToolBar->iItem == ID_FILE_NEW_BLANK)
{
CMenu *menu;
CMenu* pPopup;
menu=CMenu::FromHandle( m_wndMenuBar.GetMenu())->GetSubMenu(0);
pPopup=menu->GetSubMenu(0);
// the font popup is stored in a resource
if(pPopup)
pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON, rect.left, rect.top + 1, AfxGetMainWnd());
//pPopup->DestroyMenu();
}
else if(pNMToolBar->iItem == ID_WINDOW_CLOSE_ALL_BEN)
{
CMenu *menu;
CMenu* pPopup;
menu=CMenu::FromHandle( m_wndMenuBar.GetMenu())->GetSubMenu(0);
pPopup=menu->GetSubMenu(5);
// the font popup is stored in a resource
if(pPopup)
pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON, rect.left, rect.top + 1, AfxGetMainWnd());
//pPopup->DestroyMenu();
}
else if(pNMToolBar->iItem == ID_READMAIL_TOOL)
{
CMenu *menu;
CMenu* pPopup;
menu=CMenu::FromHandle( m_wndMenuBar.GetMenu())->GetSubMenu(4);
pPopup=menu->GetSubMenu(1);
// the font popup is stored in a resource
if(pPopup)
pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON, rect.left, rect.top + 1, AfxGetMainWnd());
//pPopup->DestroyMenu();
}
else if(pNMToolBar->iItem == ID_SOURCECODE_VIEW)
{
CMenu pPopup;
pPopup.CreatePopupMenu();
static TCHAR sz[MAX_PATH+1];
HKEY hKey, hKey2;
TCHAR szPath[MAX_PATH];
DWORD dwSize = MAX_PATH+1;
int i = 0, l = 1;
CString key;
CStringList 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.AddTail(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(editors.FindIndex(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);
ExpandEnvironmentStrings(sz, szPath, MAX_PATH);
OpenWithEditor(szPath);
}
}
}
}
else if(pNMToolBar->iItem == ID_DOWNLOAD_CONTROL)
{
CMenu* pPopup;
// for the download control popup, just steal the menu from the main window
pPopup = CMenu::FromHandle( m_wndMenuBar.GetMenu())->GetSubMenu(4)->GetSubMenu(2);
if(pPopup)
pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON, rect.left, rect.top + 1, AfxGetMainWnd());
}
else if(pNMToolBar->iItem == IDOK)
{
CString dirname ,filename;
TCHAR sz[MAX_PATH];
GetModuleFileName(NULL,sz,sizeof(sz));
dirname=sz;
dirname=dirname.Left(dirname.ReverseFind('\\'));
dirname=dirname.Left(dirname.ReverseFind('\\'));
CStdioFile file;
filename=dirname+"\\DefData\\addrtool.dat";
if(file.Open(filename,CFile::modeRead))
{
CMenu pSubMenu;
pSubMenu.CreatePopupMenu();
CString name,URL,addtoolitem;
CStringList addtoollist;
while(file.ReadString(addtoolitem))
{
if(addtoolitem.Find('=')>=0)
{
addtoollist.AddTail(addtoolitem);
}
}
file.Close();
for(int i=0;i<addtoollist.GetCount();i++)
{
addtoolitem=addtoollist.GetAt(addtoollist.FindIndex(i));
name=addtoolitem.Left(addtoolitem.Find('='));
name.TrimLeft();
name.TrimRight();
if(name=="-")
pSubMenu.AppendMenu(MF_SEPARATOR);
else
pSubMenu.AppendMenu(MF_STRING | MF_ENABLED,i+1,name);
}
UINT nID = pSubMenu.TrackPopupMenu( TPM_LEFTALIGN | TPM_RIGHTBUTTON|TPM_RETURNCMD|TPM_NONOTIFY,
rect.left, rect.top + 1,AfxGetApp()->m_pMainWnd);
if(nID>0&&nID<=(UINT)addtoollist.GetCount())
{
addtoolitem=addtoollist.GetAt(addtoollist.FindIndex(nID-1));
URL=addtoolitem.Mid(addtoolitem.Find('=')+1);
URL.TrimLeft();
URL.TrimRight();
CBenbenBrowserView *pview=(CBenbenBrowserView *)GetbenActiveView();
CString temp=pview->GetLocationURL();
//get the domine name
if(temp.Find("http://")>=0)
temp=temp.Mid(temp.Find("http://")+7);
if(temp.Find("www.")>=0)
temp=temp.Mid(temp.Find("www.")+4);
temp=temp.Left(temp.Find('/'));
CString temp2;
temp.MakeLower();
if(temp.Find(".com"))//get the domian name.remove the subdomain name
{
temp2=temp.Left(temp.Find(".com"));
temp=temp.Mid(temp.Find(".com"));
if(temp2.Find('.')>=0)
temp2=temp2.Mid(temp2.ReverseFind('.')+1);
temp=temp2+temp;
}
if(temp.Find(".net"))
{
temp2=temp.Left(temp.Find(".net"));
temp=temp.Mid(temp.Find(".net"));
if(temp2.Find('.')>=0)
temp2=temp2.Mid(temp2.ReverseFind('.')+1);
temp=temp2+temp;
}
if(temp.Find(".org"))
{
temp2=temp.Left(temp.Find(".org"));
temp=temp.Mid(temp.Find(".org"));
if(temp2.Find('.')>=0)
temp2=temp2.Mid(temp2.ReverseFind('.')+1);
temp=temp2+temp;
}
if(temp.Find(".edu"))
{
temp2=temp.Left(temp.Find(".edu"));
temp=temp.Mid(temp.Find(".eud"));
if(temp2.Find('.')>=0)
temp2=temp2.Mid(temp2.ReverseFind('.')+1);
temp=temp2+temp;
}
if(temp.Find(".gov"))
{
temp2=temp.Left(temp.Find(".gov"));
temp=temp.Mid(temp.Find(".gov"));
if(temp2.Find('.')>=0)
temp2=temp2.Mid(temp2.ReverseFind('.')+1);
temp=temp2+temp;
}
if(temp.Find(".mil"))
{
temp2=temp.Left(temp.Find(".mil"));
temp=temp.Mid(temp.Find(".mil"));
if(temp2.Find('.')>=0)
temp2=temp2.Mid(temp2.ReverseFind('.')+1);
temp=temp2+temp;
}
if(temp.Find(".int"))
{
temp2=temp.Left(temp.Find(".int"));
temp=temp.Mid(temp.Find(".int"));
if(temp2.Find('.')>=0)
temp2=temp2.Mid(temp2.ReverseFind('.')+1);
temp=temp2+temp;
}
URL.Replace("{domain}",temp);
temp=pview->GetLocationURL();
URL.Replace("{url}",temp);
NavigateToUrl(URL,2);
}
addtoollist.RemoveAll();
pSubMenu.DestroyMenu();
}
}
}
catch(...)
{
}
*pResult = TBDDRET_DEFAULT;
}
int CMainFrame::BuildFavoritesMenu(BuildFavStruct favstruct)//LPCTSTR pszPath, int nStartPos ,BCMenu* pMenu,CImageList *imaglist)
{
CString strPath(favstruct.pszPath);
CString strPath2;
CString str;
WIN32_FIND_DATA wfd;
HANDLE h;
int nPos;
int nEndPos=favstruct.nStartPos;
int nNewEndPos;
// int nLastDir;
TCHAR buf[INTERNET_MAX_PATH_LENGTH];
CStringArray astrFavorites;
CStringArray astrDirs;
BCMenu* pSubMenu;
int icon;
// make sure there's a trailing backslash
if(strPath[strPath.GetLength() - 1] != _T('\\'))
strPath += _T('\\');
strPath2 = strPath;
strPath += "*.*";
// now scan the directory, first for .URL files and then for subdirectories
// that may also contain .URL files
h = FindFirstFile(strPath, &wfd);
favstruct.pMenu->AppendMenu(MF_STRING | MF_ENABLED, 0xe00 + nEndPos,m_strFavDirOpen);
astrFavorites.InsertAt(nEndPos, m_strFavDirOpen);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -