📄 mvdoctemplate.cpp
字号:
return true;
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Will return you the frame that is currently activated.
CFrame* CDocFrameMgr::GetActiveFrame( void )
{
// Validate the needed information.
if( !AfxGetMainWnd() )
{
// The main window is not valid, or the current active frame is the main window.
// This mean that no child frame are currently open. Must never happen.
ASSERT( AfxGetMainWnd() );
TRACE( "Invalid main window in CreateNewFrame.\n", THIS_FILE, __LINE__ );
return NULL;
}
else if ( !( ( CFrameWnd* ) AfxGetMainWnd() )->GetActiveFrame() )
{
// Must never happen.
ASSERT( ( ( CFrameWnd* ) AfxGetMainWnd() )->GetActiveFrame() );
TRACE( "Invalid active frame in CreateNewFrame.\n", THIS_FILE, __LINE__ );
return NULL;
}
else if ( ( ( ( CFrameWnd* ) AfxGetMainWnd() )->GetActiveFrame() == AfxGetMainWnd() ) )
{
ASSERT( ( ( CFrameWnd* ) AfxGetMainWnd() )->GetActiveFrame() == AfxGetMainWnd() );
TRACE( "Invalid main window in CreateNewFrame.\n", THIS_FILE, __LINE__ );
return NULL;
}
else if ( !( ( CFrameWnd* ) AfxGetMainWnd() )->GetActiveFrame()->GetActiveView() )
{
// Must never happen.
ASSERT( ( ( CFrameWnd* ) AfxGetMainWnd() )->GetActiveFrame()->GetActiveView() );
TRACE( "Invalid active view in CreateNewFrame.\n", THIS_FILE, __LINE__ );
return NULL;
}
// Find the correspondant template, and validate it.
CFrameWnd* pChosenFrame = ( ( CFrameWnd* ) AfxGetMainWnd() )->GetActiveFrame();
CView* pChosenView = pChosenFrame->GetActiveView();
return FindFrame( pChosenView, pChosenFrame );
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Will display the requested frame.
void CDocFrameMgr::ShowOrCreateFrame( UINT _nEventID )
{
// Verify if the window is already created. If not, create it.
CFrame* pFrame = FindFrame( _nEventID );
if ( pFrame )
{
pFrame->ShowOrCreateFrame();
}
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Search method based on different criteria.
CFrame* CDocFrameMgr::FindFrame( CString _ViewClassName, CString _FrameClassName )
{
// Try to find it directly.
CFrame* pFrame = FindFrameEx( _ViewClassName, _FrameClassName );
if ( pFrame )
{
// Found it.
return pFrame;
}
// Didn't find the frame.
// Probably a frame with more than one view.
// The focused view may not be the one registered.
// Search all view, and try to find the one that match the frame.
POSITION Position = m_pDocument->GetFirstViewPosition();
while ( Position != NULL )
{
// Retrieve the view at the given position.
CView* pView = m_pDocument->GetNextView( Position );
// Verify that the view is associated with our frames and
// make sure we do not check the given class name, since it
// was check before.
if ( GET_RTCNAME ( pView->GetParentFrame() ) == _FrameClassName &&
GET_RTCNAME ( pView ) != _ViewClassName )
{
// Try to find it.
pFrame = FindFrameEx( GET_RTCNAME ( pView ), _FrameClassName );
if ( pFrame )
{
// Got it.
return pFrame;
}
}
}
// Not found.
return NULL;
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// That method only call the other find frame method with the required param.
CFrame* CDocFrameMgr::FindFrame( CWnd* _pView, CWnd* _pFrame )
{
// Make sure the parameter are valid.
if ( !_pView || !_pFrame )
{
ASSERT( _pView );
ASSERT( _pFrame );
TRACE( "Invalid pointer pass if FindFrameTemplate \
in %s at %d.\n", THIS_FILE, __LINE__ );
}
// Call the other method using the appropriate parameter.
return FindFrame( GET_RTCNAME( _pView ), GET_RTCNAME( _pFrame ) );
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Scan the list of frame to find the one associate with that id.
CFrame* CDocFrameMgr::FindFrame( UINT _nEventId )
{
// Scan the entire list to find the associated frame.
POSITION Position = m_FrameList.GetHeadPosition();
while ( Position )
{
CFrame* pFrame = m_FrameList.GetNext( Position );
// Validate the frame template.
if ( !pFrame )
{
// Must never happen.
ASSERT ( pFrame );
TRACE ( "Invalid frame in FindFrameTemplate \
in %s at %d.\n", THIS_FILE, __LINE__ );
}
else if ( pFrame->GetEventID() == _nEventId )
{
// Found it.
return pFrame;
}
}
// Not found.
return NULL;
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Method to open the frame associated with the event id.
BOOL CDocFrameMgr::OnCmdMsg( UINT _nID, int _nCode, void* _pExtra )
{
CFrame* pChosenFrame = FindFrame( _nID );
if ( _nCode == CN_COMMAND && pChosenFrame )
{
// Try to create the frame.
return pChosenFrame->ShowOrCreateFrame( );
}
else if ( _nCode == CN_UPDATE_COMMAND_UI && pChosenFrame )
{
// This is an Update UI event and the id is a frame open id.
// Enable the menu item.
( ( CCmdUI* ) _pExtra )->Enable( TRUE );
// Find the currently selected window.
if ( ( ( CFrameWnd* ) AfxGetMainWnd() )->GetActiveFrame() != AfxGetMainWnd() )
{
CFrameWnd* pChosenFrameWnd = ( ( CFrameWnd* ) AfxGetMainWnd() )->GetActiveFrame();
CView* pChosenView = pChosenFrameWnd->GetActiveView();
CFrame* pChosenFrame = FindFrame( pChosenView, pChosenFrameWnd );
( ( CCmdUI* ) _pExtra )->SetCheck( pChosenFrame->GetEventID() == _nID );
}
else
{
( ( CCmdUI* ) _pExtra )->SetCheck( FALSE );
}
// Tell the framework that the message has been handle.
return TRUE;
}
return FALSE;
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
IMPLEMENT_DYNAMIC( CFrame, CMultiDocTemplate )
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Store the needed value.
CFrame::CFrame( CFrameTemplate* _pFrameTemplate, CDocument* _pDocument )
: CMultiDocTemplate( _pFrameTemplate->GetResourceID(), NULL,
_pFrameTemplate->GetFrameRTC(),
_pFrameTemplate->GetViewRTC() )
{
m_pFrameTemplate = _pFrameTemplate;
m_pDocument = _pDocument;
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
CFrame::~CFrame( void )
{
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Functions used by the framework to manage the window once created.
// Will create the frame window.
CFrameWnd* CFrame::CreateFrame( void )
{
// Create the window and validate it.
CMDIChildWnd* pNewFrameWnd = ( CMDIChildWnd* )( CreateNewFrame( m_pDocument, NULL ) );
if ( !pNewFrameWnd )
{
// Must never happen.
ASSERT( pNewFrameWnd );
TRACE( "Unable to create frame wnd in CFrameTemplate::CreateFrame.\n", THIS_FILE, __LINE__ );
return NULL;
}
// Make sure that the frame is a mdi child window.
ASSERT( pNewFrameWnd->IsKindOf( RUNTIME_CLASS( CMDIChildWnd ) ) );
// Initialize the newly created frame.
InitialUpdateFrame( pNewFrameWnd, m_pDocument, FALSE );
pNewFrameWnd->SendMessageToDescendants( WM_INITIALUPDATE, 0, 0, TRUE, TRUE );
// Return the new frame.
return pNewFrameWnd;
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Will destroy the associated window.
bool CFrame::DestroyFrame( void )
{
// Find the window and close it.
CFrameWnd* pWnd = FindFrameWnd( );
if ( pWnd )
{
pWnd->DestroyWindow();
}
return true;
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Will display the window.
bool CFrame::ShowOrCreateFrame( void )
{
CFrameWnd* pFrameWnd = FindFrameWnd();
if ( !pFrameWnd )
{
// Frame not open. Create it and validate it.
pFrameWnd = CreateFrame();
if ( !pFrameWnd )
{
// Must never happen.
ASSERT( pFrameWnd );
TRACE( "Unable to create frame in ShowOrCreateFrame in %s at %d.\n", THIS_FILE, __LINE__ );
return false;
}
}
// Retrieve the current window states.
int nStates = SW_RESTORE;
CWnd* pActWnd = ( ( CFrameWnd* ) AfxGetMainWnd() )->GetActiveFrame();
if ( pActWnd )
{
WINDOWPLACEMENT wp;
pActWnd->GetWindowPlacement( &wp );
if ( wp.showCmd != SW_SHOWMINIMIZED )
{
nStates = wp.showCmd;
}
}
// Activate the frame in the given states.
pFrameWnd->ActivateFrame( nStates );
return true;
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Will return you it's associated window.
CFrameWnd* CFrame::FindFrameWnd( void )
{
// Validate the needed information.
if ( !m_pDocument )
{
ASSERT ( m_pDocument );
TRACE( "Invalid document while searching for a window in FindFrame in %s at %d.\n", THIS_FILE, __LINE__ );
}
// Search the document to find the associted frame window.
POSITION Position = m_pDocument->GetFirstViewPosition();
while ( Position != NULL )
{
// Retrieve the view at the given position.
CView* pView = m_pDocument->GetNextView( Position );
// Verify to see if the view and the frame runtime class
// correspond to the frame template we are searching.
if ( pView->IsKindOf( m_pFrameTemplate->GetViewRTC() ) &&
pView->GetParentFrame()->IsKindOf( m_pFrameTemplate->GetFrameRTC() ) )
{
// Got it.
return pView->GetParentFrame();
}
}
// Not found.
return NULL;
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -