📄 chmframe.cpp
字号:
//Update once just to get rid of any old progress state
m_wndDlgBar.EnableAnimationCtrl( false );
m_boolInProgress = false;
}
SetMessageText( TEXT( "" ) );
CRect rtProgress;
m_wndStatusBar.GetItemRect( CH_STATUS_PROGRESS_PANE, &rtProgress );
rtProgress.InflateRect( -1, -1 ); // Leave room for the 3d borders
CDC* pBarDC;
pBarDC = m_wndStatusBar.GetDC();
pBarDC->FillRect( &rtProgress, &m_brClearProgress );
m_wndStatusBar.ReleaseDC( pBarDC );
}
void ChMainFrame::LoadURL( const string& strURL )
{
GetHTMLWnd()->LoadURL( strURL, 0 );
}
void ChMainFrame::UpdateLocationBar( const string& strURL )
{
m_wndDlgBar.UpdateLocationBar( strURL );
}
void ChMainFrame::SetFrameName( const string& strName )
{
webTrackerMgr.AddToFrameList( strName, this );
m_strFrameName = strName;
}
/*----------------------------------------------------------------------------
ChMainFrame message handlers
----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------
FUNCTION || ChMainFrame::OnCreate
lpCreateStruct || Pointer to the structure containing information
about the object being created.
------------------------------------------------------------------------------
This function is called during processing of the WM_CREATE message,
after the window is created but before it is shown.
----------------------------------------------------------------------------*/
int ChMainFrame::OnCreate( LPCREATESTRUCT lpCreateStruct )
{
if (CFrameWnd::OnCreate( lpCreateStruct ) == -1)
{
return -1;
}
if (!m_wndToolBar.Create( this ) ||
!m_wndToolBar.LoadBitmap( IDR_MAINFRAME ) ||
!m_wndToolBar.SetButtons( buttons, sizeof( buttons )/sizeof( UINT ) ))
{
TRACE0( "Failed to create toolbar\n" );
return( -1 ); // Failed to create the toolbar
}
if (!m_wndStatusBar.Create( this ) ||
!m_wndStatusBar.SetIndicators( indicators,
sizeof( indicators ) / sizeof( UINT ) ))
{
TRACE0( "Failed to create status bar\n" );
return( -1 ); // Failed to create the status
}
else
{
InitStatusBar();
}
m_wndToolBar.EnableDocking( CBRS_ALIGN_TOP );
//EnableDocking( CBRS_ALIGN_TOP );
//DockControlBar( &m_wndToolBar, AFX_IDW_DOCKBAR_TOP );
if (!m_wndDlgBar.Create(this, IDD_LOCBAR,
CBRS_TOP |CBRS_TOOLTIPS |CBRS_FLYBY, IDD_LOCBAR))
{
TRACE0("Failed to create DlgBar\n");
return -1; // fail to create
}
m_wndDlgBar.UpdateData( false );
m_wndDlgBar.InitLocationBar();
m_wndToolBar.SetBarStyle( m_wndToolBar.GetBarStyle() |
CBRS_TOOLTIPS | CBRS_FLYBY );
ChRegistry reg( CH_COMPANY_NAME, CH_HTML_PRODUCT_NAME, APP_STATE );
bool boolTool, boolStatus;
reg.ReadBool( APP_TOOLBAR, boolTool, true );
reg.ReadBool( APP_STATUSBAR, boolStatus, true );
// Are toolbar and status bar visible
if( !(boolTool))
{ // Hide the button bar
m_wndToolBar.ShowWindow( SW_HIDE );
}
if( !(boolStatus) )
{ // Hide the status bar
m_wndStatusBar.ShowWindow( SW_HIDE );
}
RecalcLayout();
return( 0 );
}
/*----------------------------------------------------------------------------
FUNCTION || ChMainFrame::OnClose
------------------------------------------------------------------------------
This function will prompt to discover whether or not it is safe to
terminate the application.
When the Pueblo client is logged in, it terminates by sending a request
to the server. The server then controls the termination sequence.
If the Pueblo client is offline, termination proceeds normally.
----------------------------------------------------------------------------*/
void ChMainFrame::OnClose()
{
webTrackerMgr.RemoveFromFrameList( m_strFrameName, this );
if ( m_hResourceOld )
{
AfxSetResourceHandle( m_hResourceOld );
m_hResourceOld = 0;
}
CRect rtFrame;
UINT uVisible = 0;
WINDOWPLACEMENT wndPl;
// size and location of the frame
wndPl.length = sizeof( wndPl );
GetWindowPlacement( &wndPl );
rtFrame = wndPl.rcNormalPosition;
ChRegistry reg( CH_COMPANY_NAME, CH_HTML_PRODUCT_NAME, APP_STATE );
reg.WriteBool( APP_SHOWSTATEICON, wndPl.showCmd == SW_SHOWMINIMIZED );
reg.WriteBool( APP_SHOWSTATEMAX, wndPl.showCmd == SW_SHOWMAXIMIZED );
// is toolbar and status bar visible
reg.WriteBool( APP_TOOLBAR, (m_wndToolBar.GetStyle() & WS_VISIBLE) != 0L );
reg.WriteBool( APP_STATUSBAR, (m_wndStatusBar.GetStyle() & WS_VISIBLE) != 0L );
// Write the information to the ini file
// Position and size
char strBuffer[100];
wsprintf( strBuffer, "%d,%d,%d,%d",rtFrame.left, rtFrame.top,
rtFrame.Width(), rtFrame.Height() );
reg.Write( APP_POS, string( strBuffer ) );
CFrameWnd::OnClose();
}
void ChMainFrame::OnPaletteChanged(CWnd* pFocusWnd)
{
SendMessageToDescendants( WM_PALETTECHANGED,
(WPARAM)(pFocusWnd->GetSafeHwnd() ) );
}
BOOL ChMainFrame::OnQueryNewPalette()
{
// TODO: Add your message handler code here and/or call default
CPalette * pPal = ChImgUtil::GetStdPalette();
bool boolChanged = false;
if ( pPal )
{
CDC* pDC = GetDC();
CPalette * pOldPal = pDC->SelectPalette( pPal, false );
boolChanged = (BOOL)pDC->RealizePalette();
pDC->SelectPalette( pOldPal, true );
pDC->RealizePalette();
ReleaseDC( pDC );
}
return boolChanged;
}
void ChMainFrame::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
DrawProgressBar(); // Update the progress bar
CFrameWnd ::OnTimer(nIDEvent);
}
BOOL ChMainFrame::OnCommand(WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
if ( wParam == IDOK )
{
string strURL;
m_wndDlgBar.GetLocBarText( strURL );
if ( !strURL.IsEmpty()
&& strURL != GetHTMLWnd()->GetPendingRequest() )
{
GetHTMLWnd()->LoadURL( strURL, ChHTTPConn::ReloadURL );
}
}
else
{
return CFrameWnd ::OnCommand(wParam, lParam);
}
return 1;
}
void ChMainFrame::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
{
CFrameWnd ::OnActivate(nState, pWndOther, bMinimized);
if ( WA_INACTIVE == nState )
{
if ( m_idTimer )
{
KillTimer( m_idTimer );
m_idTimer = 0;
// Cleanup the status bar on deactivation
ClearStatus();
}
if ( m_hResourceOld )
{
AfxSetResourceHandle( m_hResourceOld );
m_hResourceOld = 0;
}
}
else
{
if ( WTrackerDLL.hModule != AfxGetResourceHandle() )
{
m_hResourceOld = AfxGetResourceHandle( );
AfxSetResourceHandle( WTrackerDLL.hModule );
}
if ( 0 == m_idTimer )
{
// TODO: Add your message handler code here
m_idTimer = SetTimer( ID_PROGRESS_UPDATE_TIMER,
HALF_SECOND_TIMER_DURATION, NULL );
}
}
}
void ChMainFrame::OnUpdateEditCopy(CCmdUI* pCmdUI)
{
chint32 lStart, lEnd;
GetHTMLWnd()->GetSel( lStart, lEnd );
pCmdUI->Enable( lStart != lEnd );
}
void ChMainFrame::OnEditCopy()
{
GetHTMLWnd()->CopyToClipboard();
}
void ChMainFrame::OnFileOpenLoc()
{
// TODO: Add your command handler code here
COpenLoc openLoc( GetHTMLWnd(), this );
if ( IDOK == openLoc.DoModal() )
{
GetHTMLWnd()->LoadURL( openLoc.GetLocation() );
}
}
void ChMainFrame::OnGoBack()
{
// TODO: Add your command handler code here
GetHTMLWnd()->GoBackward( );
}
void ChMainFrame::OnUpdateGoBack(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable( GetHTMLWnd()->CanGoBackward( ) );
}
void ChMainFrame::OnGoForward()
{
GetHTMLWnd()->GoForward( );
}
void ChMainFrame::OnUpdateGoForward(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable( GetHTMLWnd()->CanGoForward( ) );
}
void ChMainFrame::OnGoHome()
{
// TODO: Add your command handler code here
GetHTMLWnd()->LoadURL( GetHTMLWnd()->GetHomePage() );
}
void ChMainFrame::OnUpdateGoHome(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable( !GetHTMLWnd()->GetHomePage( ).IsEmpty() );
}
void ChMainFrame::OnGoStopLoading()
{
// TODO: Add your command handler code here
GetHTTPConn()->AbortRequests();
}
void ChMainFrame::OnViewRefresh()
{
GetHTMLWnd()->Invalidate();
}
void ChMainFrame::OnUpdateViewRefresh(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable( !GetHTMLWnd()->GetDocURL().IsEmpty() );
}
void ChMainFrame::OnViewReload()
{
// TODO: Add your command handler code here
GetHTMLWnd()->LoadURL( GetHTMLWnd()->GetDocURL(), ChHTTPConn::ReloadURL );
}
void ChMainFrame::OnUpdateViewReload(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable( !GetHTMLWnd()->GetDocURL().IsEmpty() );
}
void ChMainFrame::OnUpdateGoStopLoading(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable( GetHTTPConn()->IsActive() );
}
/*----------------------------------------------------------------------------
FUNCTION || ChApp::OnAppAbout
------------------------------------------------------------------------------
This function will execute the 'About Pueblo' dialog.
----------------------------------------------------------------------------*/
void ChMainFrame::OnAppAbout()
{
ChAbout aboutDlg( IDS_ABOUT_TITLE, this );
aboutDlg.DoModal();
}
/*----------------------------------------------------------------------------
FUNCTION || ChApp::OnEditPreferences
------------------------------------------------------------------------------
This function will execute the preferences property sheet.
----------------------------------------------------------------------------*/
void ChMainFrame::OnEditPreferences()
{
ChPrefs prefsDlg( IDS_TITLE_PREFS_DLG, this );
ChPrFont prefsFonts;
ChCachePrefsPage prefsCache;
ChNetworkPage prefsNetwork;
ChPrefsColorPage prefColor;
/* Add the property pages for this
property sheet */
prefsDlg.AddPage( &prefsFonts );
prefsDlg.AddPage( &prefColor );
prefsDlg.AddPage( &prefsCache );
prefsDlg.AddPage( &prefsNetwork );
/* Execute the property sheet
modally */
prefsDlg.DoModal();
}
void ChMainFrame::OnFileOpen()
{
// TODO: Add your command handler code here
string strFilter;
ChWebTrackerManager::WTrackerLoadString( IDS_OPEN_WEB_TRACKER_FILTER, strFilter );
CFileDialog fileOpen( true, NULL, NULL,
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
strFilter, this );
if ( fileOpen.DoModal() == IDOK )
{
string strURL;
ChURLParts::MapHostFileToURL( fileOpen.GetPathName( ), strURL );
GetHTMLWnd()->LoadURL( strURL );
}
}
void ChMainFrame::OnFrameClose()
{
// TODO: Add your command handler code here
if ( AfxGetMainWnd() != this )
{
OnClose();
}
else
{
::PostQuitMessage( 0 );
OnClose();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -