📄 childfrm.cpp
字号:
// ChildFrm.cpp : implementation of the CChildFrame class
//
#include "stdafx.h"
#include "MyIE.h"
#include "MainFrm.h"
#include "ChildFrm.h"
#include <..\src\afximpl.h>
#include "InputPassword.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CChildFrame * pPreWin = NULL;
/////////////////////////////////////////////////////////////////////////////
// CChildFrame
IMPLEMENT_DYNCREATE(CChildFrame, CMDIChildWnd)
BEGIN_MESSAGE_MAP(CChildFrame, CMDIChildWnd)
//{{AFX_MSG_MAP(CChildFrame)
ON_WM_CLOSE()
ON_WM_DESTROY()
ON_WM_MDIACTIVATE()
ON_WM_SYSCOMMAND()
ON_WM_SIZE()
ON_WM_NCACTIVATE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CChildFrame construction/destruction
CChildFrame::CChildFrame()
{
// TODO: add member initialization code here
bLock = FALSE;
bProtect = FALSE;
m_pView = NULL;
// m_bFirst = TRUE;
m_pBlankChild = NULL;
}
CChildFrame::~CChildFrame()
{
}
BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.lpszClass = AfxRegisterWndClass(
CS_DBLCLKS, // if you need double-clicks
NULL, // no cursor (use default)
NULL, // no background brush
AfxGetApp()->LoadIcon(IDR_MyIEYPE)); // app icon
ASSERT(cs.lpszClass);
cs.style = WS_CHILD | WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU
| FWS_ADDTOTITLE | WS_THICKFRAME | WS_MAXIMIZEBOX| WS_MINIMIZEBOX ;
cs.cx = 520;
cs.cy = 320;
if( !CMDIChildWnd::PreCreateWindow(cs) )
return FALSE;
BOOL bMax;
if( pMainFrame != NULL)
{
if(pMainFrame->MDIGetActive(&bMax)==NULL)
{
bMax = TRUE;
cs.style |= WS_VISIBLE;
}
}
else
bMax = TRUE;
if(bMax)
cs.style |= WS_MAXIMIZE;
if(bMax)
m_bMax = 1;
else
m_bMax = 0;
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CChildFrame diagnostics
#ifdef _DEBUG
void CChildFrame::AssertValid() const
{
CMDIChildWnd::AssertValid();
}
void CChildFrame::Dump(CDumpContext& dc) const
{
CMDIChildWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CChildFrame message handlers
/*int CChildFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIChildWnd::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
// ((CMainFrame*)GetParentFrame())->AddNewTab(this);
return 0;
}*/
void CChildFrame::OnClose()
{
// TODO: Add your message handler code here and/or call default
//clear the blank window
int nTabID = ((CMainFrame*)GetParentFrame())->FindTab(this, TRUE);
((CMainFrame*)GetParentFrame())->m_wndTab.DeleteItem(nTabID);
if(pMainFrame!=NULL)
{
if(bProtect)
((CMainFrame*)GetParentFrame())->m_nProtectNum--;
//pMainFrame->PostMessage(WM_UPDATE_TAB);
//pMainFrame->PostMessage(WM_UPDATE_TAB_TIP);
}
/* if(m_pView!=NULL)
{
m_pView->DestroyWindow();
delete m_pView;
m_pView = NULL;
}*/
if(((CMainFrame*)pMainFrame)->m_nSeq==1)
{
nNextTab = nTabID;
}
else if(((CMainFrame*)pMainFrame)->m_nSeq==2)
{
nNextTab = nTabID-1;
}
else
nNextTab = -2;
if(nNextTab>=0)
{
TCITEM TabCtrlItem;
TabCtrlItem.mask = TCIF_PARAM;
((CMainFrame*)pMainFrame)->m_wndTab.GetItem(nNextTab, &TabCtrlItem);
CChildFrame* tcf = (CChildFrame*)TabCtrlItem.lParam;
nTabID = nNextTab;
nNextTab = -2;
if(tcf!=NULL)
{
((CMainFrame*)pMainFrame)->MDIActivate(tcf);
((CMainFrame*)pMainFrame)->m_wndTab.SetCurSel(nTabID);
}
}
CMDIChildWnd::OnClose();
}
void CChildFrame::OnDestroy()
{
CMDIChildWnd::OnDestroy();
// TODO: Add your message handler code here
int nTabID = ((CMainFrame*)GetParentFrame())->FindTab(this);
((CMainFrame*)GetParentFrame())->m_wndTab.DeleteItem(nTabID);
//update address bar
if(((CMainFrame*)GetParentFrame())->m_wndTab.GetItemCount()==0)
((CMainFrame*)GetParentFrame())->m_wndAddress->SetWindowText("");
if(m_pView!=NULL)
m_pView->SendMessage(WM_CLOSE, 0, 0);
if(pMainFrame!=NULL)
{
pMainFrame->PostMessage(WM_UPDATE_TAB, TRUE);
pMainFrame->PostMessage(WM_UPDATE_TAB_TIP);
}
CChildFrame* tcf;
tcf=(CChildFrame*)((CMainFrame*)GetParentFrame())->MDIGetActive();
if(tcf && ((CMainFrame*)GetParentFrame())->m_nSeq==0)
{
nTabID = ((CMainFrame*)GetParentFrame())->FindTab(tcf);
((CMainFrame*)GetParentFrame())->m_wndTab.SetCurSel(nTabID);
}
}
BOOL CChildFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class
CMyIEView* pvw = NULL;
pvw = new CMyIEView;
if(pvw==NULL)
return FALSE;
int TotalTabs = 0;
if(pMainFrame!=NULL)
TotalTabs = ((CMainFrame*)pMainFrame)->m_wndTab.GetItemCount();
if(pMainFrame!=NULL && TotalTabs >0)
if(((CMainFrame*)pMainFrame)->m_bActiveNewWindow)
pvw->IsActive=TRUE;
else
{
pvw->IsActive=FALSE;
}
else
pvw->IsActive = TRUE;
CRect rect;
GetClientRect(&rect);
pvw->Create(NULL, "", WS_CHILD|WS_VISIBLE|WS_CLIPCHILDREN, rect, this, AFX_IDW_PANE_FIRST,NULL);
//
m_pView = pvw;
m_pView->m_wndBrowser.MoveWindow(-2,-2,2,2);
return TRUE; //CMDIChildWnd::OnCreateClient(lpcs, pContext);
}
BOOL CChildFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
// TODO: Add your specialized code here and/or call the base class
CPushRoutingFrame push(this);
// pump through current view FIRST
CWnd* pw = GetWindow(GW_CHILD);
if (pw != NULL && pw->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
return TRUE;
// then pump through frame
if (CWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
return TRUE;
// last but not least, pump through app
CWinApp* pApp = AfxGetApp();
if (pApp != NULL && pApp->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
return TRUE;
return FALSE;
}
void CChildFrame::OnMDIActivate(BOOL bActivate, CWnd* pActivateWnd, CWnd* pDeactivateWnd)
{
if(m_pView == NULL)
return;
if(bProtect && bActivate && !m_pView->IsActive && pPreWin!=this)
{
m_pView->ShowWindow(SW_HIDE);
CInputPassword dlg;
BOOL validate = FALSE;
if(dlg.DoModal()==IDOK)
{
if(dlg.m_strPassword == m_strPsw)
validate = TRUE;
else
AfxMessageBox(IDS_PASSWORD_ERROR);
}
if(!validate)
{
pPreWin = this;
//go back
if(((CMainFrame*)GetParentFrame())->m_wndTab.GetItemCount()==((CMainFrame*)GetParentFrame())->m_nProtectNum)
{
BOOL olda = ((CMainFrame*)GetParentFrame())->m_bActiveNewWindow;
((CMainFrame*)GetParentFrame())->m_bActiveNewWindow = TRUE;
CChildFrame* ncf = ((CMainFrame*)GetParentFrame())->NewChildWindow(2,0);
((CMainFrame*)GetParentFrame())->m_bActiveNewWindow = olda;
((CMainFrame*)GetParentFrame())->m_wndAddress->SetFocus();
}
else
((CMainFrame*)GetParentFrame())->MDINext();
m_pView->ShowWindow(SW_SHOW);
return;
}
else
m_pView->ShowWindow(SW_SHOW);
}
if(!bProtect && pPreWin == this && bActivate)
{
m_pView->IsActive = bActivate;
return;
}
CMDIChildWnd::OnMDIActivate(bActivate, pActivateWnd, pDeactivateWnd);
if(bActivate)
pPreWin = this;
// TODO: Add your message handler code here
//get the current tab
int nTabID;
if(m_bSkipSel)
nTabID = nCurTabID;
else
{
nTabID = ((CMainFrame*)(GetParentFrame()))->FindTab(this);
}
if(nNextTab>=0 && nNextTab!=nTabID)
{
m_bSkipSel = FALSE;
return;
}
SetWindowText(m_Title);
BOOL lastActive = m_pView->IsActive;
int lastper = percent;
// if(!m_bFirst)
m_pView->IsActive = bActivate;
// m_bFirst = FALSE;
percent = -1;
if(pMainFrame!=NULL && pMainFrame->GetForegroundWindow() != pMainFrame)
{
m_pView->IsActive = lastActive;
percent = lastper;
}
//set address bar
if(m_pView->IsActive)
{//7/17
// CString lpszUrl = m_pView->GetLocationURL();
// if(!lpszUrl.IsEmpty() && lpszUrl != "")
// ((CMainFrame*)GetParentFrame())->SetAddress(lpszUrl);
// else
((CMainFrame*)GetParentFrame())->SetAddress(m_pView->m_lpszUrl);
//select current tab
if(!m_bSkipSel)
((CMainFrame*)(GetParentFrame()))->m_wndTab.SetCurSel( nTabID );
if(m_pView->m_nProgress<0)
{
int oi = m_pView->oldIcon;
if(bLock)
m_pView->oldIcon = ((CMainFrame*)pMainFrame)->SetTabIcon( 4, nTabID );
else if(bProtect)
m_pView->oldIcon = ((CMainFrame*)pMainFrame)->SetTabIcon( 6, nTabID );
else
m_pView->oldIcon = ((CMainFrame*)pMainFrame)->SetTabIcon( -1, nTabID );
//update tab bar
if(oi*m_pView->oldIcon <=0)
pMainFrame->PostMessage(WM_UPDATE_TAB, FALSE);
}
}
if(m_pView->IsActive && !lastActive )
{
//set status bar
m_pView->OnStatusTextChange("");
percent = m_pView->m_nProgress;
}
m_bSkipSel = FALSE;
}
/*BOOL CChildFrame::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
return TRUE;
//return CMDIChildWnd::OnEraseBkgnd(pDC);
}*/
void CChildFrame::OnSysCommand(UINT nID, LPARAM lParam)
{
// TODO: Add your message handler code here and/or call default
if(nID ==SC_MAXIMIZE)
{
m_bMax = 1;
}
else if(nID ==SC_RESTORE || nID == SC_MINIMIZE)
{
m_bMax = 3;
}
CMDIChildWnd::OnSysCommand(nID, lParam);
}
void CChildFrame::OnSize(UINT nType, int cx, int cy)
{
CMDIChildWnd::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
if(m_pView!=NULL)
{
CRect rect;
GetClientRect(&rect);
CRect oldrect;
m_pView->m_wndBrowser.GetWindowRect(&oldrect);
if(oldrect.Width()!= rect.Width() || oldrect.Height()!=rect.Height())
m_pView->PostMessage(WM_SIZE, nType, (rect.Height()<<16)+rect.Width());
}
}
BOOL CChildFrame::OnNcActivate(BOOL bActive)
{
// TODO: Add your message handler code here and/or call default
if(!bActive)
{
//stop the timer;
if(m_pView->m_nScrollTimer)
m_pView->KillTimer(m_pView->m_nScrollTimer);
m_pView->m_nScrollTimer = 0;
}
else
{
//start to scroll
if(!m_pView->m_nScrollTimer && m_pView->m_bUseAutoScroll && m_pView->m_nSrSpeed!=0)
{
if(m_pView->m_nProgress==100 || m_pView->m_nProgress<0 || (!m_pView->m_bScrollAfterDL && m_pView->m_nProgress>=20))
{
m_pView->m_nScrollTimer = m_pView->SetTimer(2000, 1000*gSeed/m_pView->m_nSrSpeed, NULL);
}
}
}
return CMDIChildWnd::OnNcActivate(bActive);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -