📄 mainfrm.cpp
字号:
m_wndAddress.SetWindowText(lpszUrl);
}
/*
*******************************************************************************/
// FUNCTION : void CMainFrame::OnFileOpenurllist()
//
// PURPOSE : open a list of URLs
//
// PARAMETERS : none
//
// RETURN VALUE : void
//
//
// COMMENTS :
//
//
/*******************************************************************************
*/
void CMainFrame::OnFileOpenurllist()
{
CMainFrame *pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;;
CMDIChildWnd *pChild;
CIE6mdiView *pView;
CWinApp* pApp = AfxGetApp();
CFileDialog dlg(TRUE, "LHTM files","*.lhtm",
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,(CString(LPCTSTR(IDS_LISTETYPE))));
// set the default directory
OPENFILENAME op = dlg.m_ofn;
op.lpstrInitialDir = pApp->GetProfileString("Settings","LHTM default path",NULL);
dlg.m_ofn = op;
if (dlg.DoModal() == IDOK) {
CFile file;
if (!file.Open(dlg.GetPathName(), CFile::modeRead))
{
// an error occured
AfxMessageBox(CString(LPCTSTR(IDS_FILEERROR)));
return;
}
////////////////////////////////////
// Save the current directory
////////////////////////////////////
CString pn = dlg.GetPathName();
CString fn = dlg.GetFileName();
pn = pn.Left(pn.GetLength()-fn.GetLength());
pApp->WriteProfileString("Settings","LHTM default path",pn);
char *buf = (char*)malloc((file.GetLength()+1)*sizeof(char));
buf[0]='\0';
file.Read(buf,file.GetLength());
file.Close();
COMBOBOXEXITEM item;
item.mask = CBEIF_TEXT;
item.iItem = -1;
CString s(buf);
free(buf);
int p = s.Find("\r\n");
while ( (p != -1)&&(s.IsEmpty() == FALSE)) {
// s.Left(p): a valid URL
// create a new window and go to the URL
AfxGetApp()->m_pMainWnd->SendMessage(WM_COMMAND,(WPARAM)ID_FILE_NEW,(LPARAM)NULL);
pChild = (CMDIChildWnd *) pFrame->GetActiveFrame();
pView = (CIE6mdiView *) pChild->GetActiveView();
pView->Navigate2(s.Left(p));
// add to the combo list
if (s.Left(p).GetLength() != 0) {
item.pszText = (LPTSTR)(LPCTSTR)s.Left(p);
m_wndAddress.InsertItem(&item);
}
// prepare the remain of the file
CString stmp;
stmp = s.Mid(p+2); // discard \r\n
s = stmp;
p = s.Find("\r\n");
}
// we have to add the last URL
/* if (s.Left(p).GetLength() != 0) {
item.pszText = (LPTSTR)(LPCTSTR)s;
m_wndAddress.InsertItem(&item);
}*/
}
}
/*
*******************************************************************************/
// FUNCTION : void CMainFrame::OnFileSaveurllist()
//
// PURPOSE : save the list of URLs (and create a bonus HTM file)
//
// PARAMETERS : none
//
// RETURN VALUE : void
//
//
// COMMENTS :
//
//
/*******************************************************************************
*/
void CMainFrame::OnFileSaveurllist()
{
if (m_lUrl.IsEmpty()) {
AfxMessageBox(CString(LPCTSTR(IDS_NOLIST)));
return;
}
CWinApp* pApp = AfxGetApp();
CFileDialog dlg(FALSE, "LHTM files","*.lhtm",
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,(CString(LPCTSTR(IDS_LISTETYPE))));
// set the default directory
OPENFILENAME op = dlg.m_ofn;
op.lpstrInitialDir = pApp->GetProfileString("Settings","LHTM default path",NULL);
dlg.m_ofn = op;
if (dlg.DoModal() == IDOK) {
CFile file;
// we will create an HTM file containing the links to these URL's
if (!file.Open(dlg.GetPathName(), CFile::modeCreate | CFile::modeWrite))
{
// an error occured
AfxMessageBox(CString(LPCTSTR(IDS_FILEERROR)));
return;
}
////////////////////////////////////
// Save the current directory
////////////////////////////////////
CString pn = dlg.GetPathName();
CString fn = dlg.GetFileName();
pn = pn.Left(pn.GetLength()-fn.GetLength());
pApp->WriteProfileString("Settings","LHTM default path",pn);
CString liste;
char *buf;
POSITION p;
p=m_lUrl.GetHeadPosition();
CString NewFileName = dlg.GetPathName();
NewFileName = NewFileName.Left(NewFileName.GetLength()-5); // 5: .lthm
NewFileName += ".htm";
CFile file2;
file2.Open(NewFileName, CFile::modeCreate | CFile::modeWrite);
CString NewFileData;
NewFileData = "<html><head><title>URL's list for " + NewFileName
+ "</title></head><body>";
while (p!=NULL) {
CString s = m_lUrl.GetNext(p);
if (s.GetLength() != 0) {
liste += s;
liste += "\r\n";
// update the htm file
NewFileData += "<a href=" + s + " target=a>" + s + "</a><br>";
}
}
NewFileData += "</body></html>";
// save the htm file
buf = (char*)malloc((NewFileData.GetLength()+1)*sizeof(char));
buf[0]='\0';
strcpy(buf,(LPCTSTR)(NewFileData));
file2.Write(buf,NewFileData.GetLength());
free(buf);
file2.Close();
// we have the list in 'liste'
buf = (char*)malloc((liste.GetLength()+1)*sizeof(char));
buf[0]='\0';
strcpy(buf,(LPCTSTR)(liste));
file.Write(buf,liste.GetLength());
free(buf);
file.Close();
}
}
/*
*******************************************************************************/
// FUNCTION : void CMainFrame::OnFileOpenadocument()
//
// PURPOSE : open a document in a NEW WINDOW
//
// PARAMETERS : none
//
// RETURN VALUE : void
//
//
// COMMENTS :
//
//
/*******************************************************************************
*/
void CMainFrame::OnFileOpenadocument()
{
CMainFrame *pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;;
CMDIChildWnd *pChild;
CIE6mdiView *pView;
CWinApp* pApp = AfxGetApp();
CFileDialog dlg(TRUE, "HTML file","*.htm; *.html",OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
(CString(LPCTSTR(IDS_FILETYPES))));
// set the default directory
OPENFILENAME op = dlg.m_ofn;
op.lpstrInitialDir = pApp->GetProfileString("Settings","Documents default path",NULL);
dlg.m_ofn = op;
if (dlg.DoModal() == IDOK) {
////////////////////////////////////
// Save the current directory
////////////////////////////////////
CString pn = dlg.GetPathName();
CString fn = dlg.GetFileName();
pn = pn.Left(pn.GetLength()-fn.GetLength());
pApp->WriteProfileString("Settings","Documents default path",pn);
// in any case :
// we need to create a new window
AfxGetApp()->m_pMainWnd->SendMessage(WM_COMMAND,(WPARAM)ID_FILE_NEW,(LPARAM)NULL);
pChild = (CMDIChildWnd *) pFrame->GetActiveFrame();
pView = (CIE6mdiView *) pChild->GetActiveView();
pView->Navigate2(dlg.GetPathName());
return;
}
}
BOOL CMainFrame::DestroyWindow()
{
CIE6mdiApp* mdiApp = (CIE6mdiApp*)AfxGetApp();
if (mdiApp->m_iRemindWindow == 1) {
CWnd* m_pWnd = AfxGetApp()->m_pMainWnd;
CWinApp* pApp = AfxGetApp();
CRect rect;
m_pWnd->GetWindowRect(&rect);
int Width,Height,Left,Top;
rect.NormalizeRect();
Width = rect.Width();
Height = rect.Height();
Top = rect.top;
Left = rect.left;
int IsZoomed = (m_pWnd->IsZoomed() == TRUE);
pApp->WriteProfileInt("Settings","Window Width",Width);
pApp->WriteProfileInt("Settings","Window Height",Height);
pApp->WriteProfileInt("Settings","Window Top",Top);
pApp->WriteProfileInt("Settings","Window Left",Left);
pApp->WriteProfileInt("Settings","Window IsZoomed",IsZoomed);
}
return CMDIFrameWnd::DestroyWindow();
}
void CMainFrame::OnFileChangethelogo()
{
CMainFrame *pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;;
CWinApp* pApp = AfxGetApp();
CFileDialog dlg(TRUE, "AVI file","*.avi",OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
(CString(LPCTSTR(IDS_FILESLOGO))));
// set the default directory
OPENFILENAME op = dlg.m_ofn;
op.lpstrInitialDir = pApp->GetProfileString("Settings","AVI default path",NULL);
dlg.m_ofn = op;
if (dlg.DoModal() == IDOK) {
////////////////////////////////////
// Save the current directory
////////////////////////////////////
CString pn = dlg.GetPathName();
CString fn = dlg.GetFileName();
pn = pn.Left(pn.GetLength()-fn.GetLength());
pApp->WriteProfileString("Settings","AVI default path",pn);
pFrame->m_wndAnimate.Close();
if (!pFrame->m_wndAnimate.Open(dlg.GetPathName())) {
AfxMessageBox(CString(LPCTSTR(IDS_FILEERROR)));
pFrame->m_wndAnimate.Open(IDR_MFCAVI); // default animation
}
else {
pApp->WriteProfileString("Settings","AVI default file",dlg.GetPathName());
}
// is the logo running ?
if (IsLogoPlayed == 1)
pFrame->StartAnimation();
return;
}
}
void CMainFrame::OnFileDefaultlogo()
{
CMainFrame *pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
CWinApp* pApp = AfxGetApp();
pApp->WriteProfileString("Settings","AVI default file",""); // delete the current
pFrame->m_wndAnimate.Close();
pFrame->m_wndAnimate.Open(IDR_MFCAVI);
if (IsLogoPlayed == 1)
pFrame->StartAnimation();
}
/*
*******************************************************************************/
// FUNCTION : POSITION CMainFrame::GetFreePos()
//
// PURPOSE : return the first free position of NULL if AddTail !!!
//
// PARAMETERS : none
//
// RETURN VALUE : POSITION
//
//
// COMMENTS : beware, two views can call that in the same time !!! Use mutex !
//
//
/*******************************************************************************
*/
POSITION CMainFrame::GetFreePos()
{
static CMutex mutex(FALSE);
POSITION p;
mutex.Lock();
//////// critical section ! //////////////
if (m_lUrl.IsEmpty()) {
mutex.Unlock();
return NULL; // AddTail
}
else {
int i,n=m_lUrl.GetCount();
p = m_lUrl.GetHeadPosition();
for(i=1;i<=n;i++) {
if ( (p==NULL) || (m_lUrl.GetAt(p) == "") ) {
mutex.Unlock();
return p;
}
m_lUrl.GetNext(p);
}
mutex.Unlock();
return NULL; // AddTail
}
}
/*
*******************************************************************************/
// FUNCTION : CString CMainFrame::CheckUrl(CString)
//
// PURPOSE : add a '/' at the end of a website adress if necessary
//
// PARAMETERS :
// URL - current address
//
// RETURN VALUE : CString
//
//
// COMMENTS : if we don not do that, we can have and error with an url like that:
// http://www.chez.com/bcristiano
// this URL will be corrected with http://www.chez.com/bcristiano/
// An url like http://www.truc.com/file.ext will not be corrected (good)
//
//
/*******************************************************************************
*/
CString CMainFrame::CheckUrl(CString URL)
{
CString s(URL);
if (s[s.GetLength()-1] == '/')
return s;
int pos = s.ReverseFind('/');
if (pos == -1)
return s;
CString tmp = s.Right(s.GetLength() -1 - pos);
// check if a file is requested ?
if (tmp.Find('.') == -1) {
s += "/";
}
return s;
}
/*
*******************************************************************************/
// FUNCTION : void CMainFrame::OnClose()
//
// PURPOSE :
//
// PARAMETERS : none
//
// RETURN VALUE : void
//
//
// COMMENTS :
//
//
/*******************************************************************************
*/
void CMainFrame::OnClose()
{
theViewManager.RemoveAll();
theViewManager.bClosing = true;
CMDIFrameWnd::OnClose();
}
/*
*******************************************************************************/
// FUNCTION : void CMainFrame::OnSize(UINT,int,int)
//
// PURPOSE :
//
// PARAMETERS :
// nType -
// cx -
// cy -
//
// RETURN VALUE : void
//
//
// COMMENTS :
//
//
/*******************************************************************************
*/
void CMainFrame::OnSize(UINT nType, int cx, int cy)
{
CMDIFrameWnd::OnSize(nType, cx, cy);
if (m_wndStatusBar.GetSafeHwnd() && theWindowTab.GetSafeHwnd()) {
CRect rc;
m_wndStatusBar.GetItemRect(1, rc); //0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -