📄 mainfrm.cpp
字号:
return -1; // fail to create
}
//add tab
//multiline tab
m_bMultiLineTab = AfxGetApp()->GetProfileInt("Settings", "MultiLineTab", 0);
m_bAutoTab = AfxGetApp()->GetProfileInt("Settings", "AutoTab", 0);
//Tab bar
//Create Tab Bar
CRect rect(0,0,300,10);
if(m_bMultiLineTab)
{
if(!m_bAutoTab)
m_wndTab.Create(WS_VISIBLE|TCS_BUTTONS|TCS_FLATBUTTONS|TCS_FOCUSNEVER|TCS_FORCELABELLEFT|TCS_TOOLTIPS|TCS_RAGGEDRIGHT|TCS_MULTILINE, rect,this, AFX_IDW_TOOLBAR + 2);
else
m_wndTab.Create(WS_VISIBLE|TCS_BUTTONS|TCS_FLATBUTTONS|TCS_FOCUSNEVER|TCS_FORCELABELLEFT|TCS_TOOLTIPS|TCS_RAGGEDRIGHT|TCS_MULTILINE|TCS_FIXEDWIDTH, rect,this, AFX_IDW_TOOLBAR + 2);
GetMenu()->CheckMenuItem(ID_OPTION_MULTI_TAB, MF_CHECKED);
}
else if(!m_bAutoTab)
m_wndTab.Create(WS_VISIBLE|TCS_BUTTONS|TCS_FLATBUTTONS|TCS_FOCUSNEVER|TCS_FORCELABELLEFT|TCS_TOOLTIPS|TCS_RAGGEDRIGHT, rect,this, AFX_IDW_TOOLBAR + 2);
else
m_wndTab.Create(WS_VISIBLE|TCS_BUTTONS|TCS_FLATBUTTONS|TCS_FOCUSNEVER|TCS_FORCELABELLEFT|TCS_TOOLTIPS|TCS_RAGGEDRIGHT|TCS_FIXEDWIDTH , rect,this, AFX_IDW_TOOLBAR + 2);
DWORD dwExStyle= m_wndTab.GetExtendedStyle();
m_wndTab.SetExtendedStyle(dwExStyle | TCS_EX_FLATSEPARATORS);
img.Create(IDB_BITMAP5, 8, 0, RGB(255, 0, 255));
m_wndTab.SetImageList(&img);
img.Detach();
CSize size(3,2);
//m_wndTab.SetItemSize(size);
m_wndTab.SetFont(m_wndReBar.GetFont());
m_wndTab.SetPadding( size );
GetMenu()->CheckMenuItem(ID_VIEW_TASKBAR, MF_CHECKED);
// set up min/max sizes and ideal sizes for pieces of the rebar
rbbi.cbSize = sizeof(rbbi);
rbbi.fMask = RBBIM_CHILDSIZE | RBBIM_IDEALSIZE | RBBIM_SIZE |RBBIM_ID;
rbbi.wID = ID_VIEW_TASKBAR;
rbbi.cxMinChild = 0;
m_wndAddress->GetEditCtrl()->GetWindowRect(&rectAddress);
rbbi.cyMinChild = rectAddress.Height() + 2;
rbbi.cxIdeal = 200;
//add tab to top or bottom
if(m_bTopTab)
{
m_wndReBar.AddBar(&m_wndTab,NULL, NULL, RBBS_FIXEDBMP | RBBS_BREAK |RBBS_GRIPPERALWAYS );
m_wndReBar.GetReBarCtrl().SetBandInfo(7, &rbbi);
}
else
{
m_wndReBar2.AddBar(&m_wndTab);
m_wndReBar2.GetReBarCtrl().SetBandInfo(0, &rbbi);
}
//load band position
char temp[7]="band", rectstr[10]="bandrc";
RECT *pbandrect;
UINT bands;
UINT i=-1, len = 0;
DWORD pos;
BOOL show;
i=-1;
do
{
i++;
itoa(i, temp+4, 10);
bands = AfxGetApp()->GetProfileInt("Settings", temp, 0);
show = AfxGetApp()->GetProfileInt("Bands", temp, 1);
itoa(i, rectstr+6,10);
if(bands!=0 && show)
{
BOOL r = AfxGetApp()->GetProfileBinary("Settings", rectstr, (LPBYTE*)&pbandrect, &len);
if(r)
{
//if(bands!=ID_SYSMENU_BAR)
{
int index=m_wndReBar.GetReBarCtrl().IDToIndex(bands);
rbbi.fMask = RBBIM_SIZE;
rbbi.cx=pbandrect->right-pbandrect->left;
m_wndReBar.GetReBarCtrl().SetBandInfo(index, &rbbi);
index=m_wndReBar.GetReBarCtrl().IDToIndex(bands);
m_wndReBar.GetReBarCtrl().BeginDrag(index);
pos=((pbandrect->top+8)<<16)+pbandrect->left;
m_wndReBar.GetReBarCtrl().DragMove(pos);
m_wndReBar.GetReBarCtrl().EndDrag();
}
delete pbandrect;
}
}
else if(bands!=0)
{
int index=m_wndReBar.GetReBarCtrl().IDToIndex(bands);
m_wndReBar.GetReBarCtrl().ShowBand(index, FALSE);
GetMenu()->CheckMenuItem(bands, MF_UNCHECKED);
}
}while(bands!=0);
//bottom bar
if(AfxGetApp()->GetProfileInt("Bands", "bandb0", 1)==0)
{
m_wndReBar2.GetReBarCtrl().ShowBand(0, FALSE);
GetMenu()->CheckMenuItem(ID_VIEW_TASKBAR, MF_UNCHECKED);
}
//auto complete
HINSTANCE hIns = LoadLibrary("shlwapi.dll");
if(hIns != NULL)
{
LPFNDLLFUNC1 lpfnDllFunc1 = (LPFNDLLFUNC1)GetProcAddress(hIns, "SHAutoComplete");
if(lpfnDllFunc1!=NULL)
lpfnDllFunc1(m_wndAddress->GetEditCtrl()->m_hWnd, 0xe);
FreeLibrary(hIns);
}
hResInst = LoadLibrary("RSRC32.dll");
ShowBackground(TRUE);
return 0;
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CMDIFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CMDIFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
void CMainFrame::SetAddress(LPCTSTR lpszUrl)
{
// This is called when the browser has completely loaded the new location,
// so make sure the text in the address bar is up to date and stop the
m_wndAddress->SetWindowText(lpszUrl);
COMBOBOXEXITEM item;
item.mask = CBEIF_IMAGE|CBEIF_SELECTEDIMAGE ;
item.iItem = -1;
item.iImage = 1;
item.iSelectedImage = 1;
m_wndAddress->SetItem(&item);
}
void CMainFrame::OnNewAddress()
{
// gets called when an item in the Address combo box is selected
// just navigate to the newly selected location.
CString str;
int i = m_AddressBar.m_wndAddress.GetCurSel();
if(i<0)
return;
m_AddressBar.GetSelText(i, str);
CChildFrame* tcf = (CChildFrame*)MDIGetActive();
//decode the escape characters
DecodeEscap(str);
//create new if not exist
if(tcf==NULL || m_bAlwaysNewWindow)
tcf = NewChildWindow(0);
//web proxy
if (tcf!=NULL && tcf->m_pView!=NULL)
{
tcf->m_pView->ToNavigate(str, 0, NULL);
}
}
void CMainFrame::OnNewAddressEnter()
{
// gets called when an item is entered manually into the edit box portion
// of the Address combo box.
// navigate to the newly selected location and also add this address to the
// list of addresses in the combo box.
CString str, oldstr, url;
//focus
m_wndAddress->SetFocus();
m_wndAddress->GetEditCtrl()->GetWindowText(str);
CChildFrame* tcf = (CChildFrame*)MDIGetActive();
BOOL use3721 = FALSE;
if(m_bUseAlias)
if(m_mapAlias.Lookup(str, url))
str = url;
else
use3721=TRUE;
else
use3721=TRUE;
short ks=GetKeyState(VK_CONTROL), ss=GetKeyState(VK_SHIFT);
if(m_bUse3721 && use3721 && ks>=0 && ss>=0)
{
//use 3721
if(str.Find(':')<0 && str.Find('.')<0)
{
//not a url
str = "http://cns.3721.com/cns.dll?platform=pc&fl=1&fd=1&name="+str; // www.3721.com/***
}
else
use3721 = FALSE;
}
else
use3721 = FALSE;
oldstr = str;
COMBOBOXEXITEM item;
item.mask = CBEIF_TEXT|CBEIF_IMAGE|CBEIF_SELECTEDIMAGE ;
item.iItem = 0;
//format the URL string
if(!use3721)
{
str.MakeLower();
str.TrimLeft();
str.TrimRight();
}
int co = str.Find(':');
if(co > 1)
str.Replace('\\','/');
if(co < 0)
{
if(ks<0 && ss>=0)
str = m_strCE1+str+m_strCE2;
else if(ks>=0 && ss<0)
str = m_strSE1+str+m_strSE2;
else if(ks<0 && ss<0)
str = m_strCSE1 + str + m_strCSE2;
else
str = "http://"+str;
if(ks<0 || ss<0)
{
m_wndAddress->GetEditCtrl()->SetWindowText(str);
oldstr = str;
}
}
CString str2=str;
//create new if not exist and always new
if(tcf==NULL || m_bAlwaysNewWindow)
tcf = NewChildWindow(0);
//web proxy
if (tcf!=NULL && tcf->m_pView!=NULL)
{
tcf->m_pView->ToNavigate(oldstr, 0, NULL);
}
if(m_AddressBar.FindStringExact(-1,str2) == CB_ERR)
{
if (str2.Right(1)=='/')
str2 = str2.Left(str2.GetLength()-1);
else
str2 += '/';
if(m_AddressBar.FindStringExact(-1, str2) == CB_ERR)
{
//the URL is new
item.pszText = (LPTSTR)(LPCTSTR)str;
item.iImage = 1;
item.iSelectedImage = 1;
m_wndAddress->InsertItem(&item);
}
}
}
void CMainFrame::DoNothing()
{
// this is here only so that the toolbar buttons for the dropdown menus
// will have a callback, and thus will not be disabled.
}
void CMainFrame::OnDropDown(NMHDR* pNotifyStruct, LRESULT* pResult)
{
// 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
m_wndToolBar.GetToolBarCtrl().GetRect(pNMToolBar->iItem, &rect);
rect.top = rect.bottom;
::ClientToScreen(pNMToolBar->hdr.hwndFrom, &rect.TopLeft());
if(pNMToolBar->iItem == ID_FONT_DROPDOWN)
{
CMenu menu;
CMenu* pPopup;
// the font popup is stored in a resource
menu.LoadMenu(IDR_FONT_POPUP);
pPopup = menu.GetSubMenu(0);
pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON, rect.left, rect.top + 1, AfxGetMainWnd());
}
else if(pNMToolBar->iItem == ID_FILE_NEW_BLANK)
{
CMenu* pPopup;
pPopup = GetMenu()->GetSubMenu(0)->GetSubMenu(0);
pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON, rect.left, rect.top + 1, AfxGetMainWnd());
}
else if(pNMToolBar->iItem == ID_OPTIONS_USE_PROXY)
{
CMenu pPopup;
INTERNET_PROXY_INFO ipi;
DWORD dwSize=sizeof(ipi);
BOOL bUseProxy;
//This call determines the buffer size needed
InternetQueryOption(NULL,INTERNET_OPTION_PROXY,&ipi,&dwSize);
//Insert code to user the user agent string information
if (ipi.dwAccessType == INTERNET_OPEN_TYPE_DIRECT )
bUseProxy = FALSE;
else
bUseProxy = TRUE;
// the font popup is stored in a resource
pPopup.CreatePopupMenu();
POSITION pos1=m_aProxySpeed.GetHeadPosition(), pos = m_astrProxy.GetHeadPosition();
int i=0;
CString str, str1;
while(pos!=NULL)
{
str = m_astrProxy.GetAt(pos);
str = str.Left(50);
str1.LoadString(IDS_SP_INVALID + m_aProxySpeed.GetAt(pos1));
str1 = "(" + str1 + ")";
pPopup.AppendMenu(MF_STRING, 0x1100 + i, str+str1);
if(bUseProxy && m_strCurProxy == m_astrProxy.GetAt(pos))
pPopup.CheckMenuItem(0x1100 + i, MF_CHECKED | MF_BYCOMMAND );
m_astrProxy.GetNext(pos);
m_aProxySpeed.GetNext(pos1);
i++;
}
pPopup.TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON, rect.left, rect.top + 1, AfxGetMainWnd());
pPopup.DestroyMenu();
}
else if(pNMToolBar->iItem == ID_OPTIONS_USE_WEBP)
{
CMenu pPopup;
CString strCurWebProxy;
CChildFrame* tcf = (CChildFrame*)MDIGetActive();
if (tcf!=NULL && tcf->m_pView!=NULL)
{
if(((CMyIEView*)tcf->m_pView)->m_bEnWebProxy)
{
strCurWebProxy = ((CMyIEView*)tcf->m_pView)->m_strWebProxy;
}
}
// the font popup is stored in a resource
pPopup.CreatePopupMenu();
POSITION pos = m_astrWebProxy.GetHeadPosition(), pos1 = m_aWebProxySpeed.GetHeadPosition();
int i=0;
CString str, str1;
while(pos!=NULL)
{
str = m_astrWebProxy.GetAt(pos);
str1.LoadString(IDS_SP_INVALID + m_aWebProxySpeed.GetAt(pos1));
str1 = "(" + str1 + ")";
pPopup.AppendMenu(MF_STRING, 0x1200 + i, str+str1);
if(strCurWebProxy == m_astrWebProxy.GetAt(pos))
pPopup.CheckMenuItem(0x1200 + i, MF_CHECKED | MF_BYCOMMAND );
m_astrWebProxy.GetNext(pos);
m_aWebProxySpeed.GetNext(pos1);
i++;
}
pPopup.TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON, rect.left, rect.top + 1, AfxGetMainWnd());
pPopup.DestroyMenu();
}
else if(pNMToolBar->iItem == ID_ENCODE_DROPDOWN)
{
CMenu menu;
CMenu* pPopup;
// the font popup is stored in a resource
menu.LoadMenu(IDR_ENCODING);
pPopup = menu.GetSubMenu(0);
pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON, rect.left, rect.top + 1, AfxGetMainWnd());
}
else if(pNMToolBar->iItem == ID_BMODE_DROPDOWN)
{
CMenu* pPopup;
pPopup = GetMenu()->GetSubMenu(4)->GetSubMenu(11);
pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON, rect.left, rect.top + 1, AfxGetMainWnd());
}
else if(pNMToolBar->iItem == ID_TOOLS_AUTOSCROLL_USEAUTOSCROLLING)
{
CMenu* pPopup;
pPopup = GetMenu()->GetSubMenu(6)->GetSubMenu(14);
pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON, rect.left, rect.top + 1, AfxGetMainWnd());
}
*pResult = TBDDRET_DEFAULT;
}
int CMainFrame::BuildFavoritesMenu(LPCTSTR pszPath, int nStartPos, CMenu* pMenu,int nFixMenu, int FirstLevel, int& nFavs, int& nMostFavs)
{
CString strPath(pszPath);
CString strPath2;
CString str, str2;
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;
BOOL isLink = FALSE;
CString strOpenAll, strOpenMost;
int nSubFavs = 0, nSubMostFavs = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -