www.pudn.com > mu_explorer.rar > CJFrameWnd.cpp
// CJFrameWnd.cpp : implementation file
// Copyright © 1998-1999 CodeJock.com, All Rights Reserved.
// See ReadMe.txt for TERMS OF USE.
//
/////////////////////////////////////////////////////////////////////////////
/****************************************************************************
*
* $Date: 10/31/99 11:04p $
* $Revision: 16 $
* $Archive: /CodeJock/CJLibrary/CJFrameWnd.cpp $
*
* $History: CJFrameWnd.cpp $
*
* ***************** Version 16 *****************
* User: Kirk Stowell Date: 10/31/99 Time: 11:04p
* Updated in $/CodeJock/CJLibrary
* Minor update to PreCreateWindow(...) for flicker free drawing.
*
* ***************** Version 15 *****************
* User: Kirk Stowell Date: 10/29/99 Time: 12:43a
* Updated in $/CodeJock/CJLibrary
* Overloaded PreCreateWindow(...) for flicker free drawing.
*
* ***************** Version 14 *****************
* User: Kirk Stowell Date: 10/14/99 Time: 6:15p
* Updated in $/CodeJock/CJLibrary
* Fixed bug with a document becomes the active document when the user
* clicks inside a tab in the CCJTabControlBar to perform some operation.
* When closing the application, MFC decides in CFrameWnd::OnClose() to
* check if the 'active' document is modified before checking all other
* documuents. If the active document is not modified and can close its
* frame, it does not check other documents individually and shuts down
* without asking the important 'modified save' questions. To fix this,
* OnClose() was overriden to add a call to "SetActiveView(NULL)" just
* before the base class OnClose is called. This will check all documents
* asking the save question before closing the application. Thanks to
* Simon Clark [spc@otleda.com] for help with this.
*
* ***************** Version 13 *****************
* User: Kirk Stowell Date: 10/14/99 Time: 10:05a
* Updated in $/CodeJock/CJLibrary
* Overrode OnEraseBkgnd(...) to help to eliminate screen flicker.
*
* ***************** Version 12 *****************
* User: Kirk Stowell Date: 9/16/99 Time: 2:35p
* Updated in $/CodeJockey/CJLibrary
* Fixed bug with save / restore bar state, and with saved bar size
* changing whenever the application starts.
*
* ***************** Version 11 *****************
* User: Kirk Stowell Date: 8/31/99 Time: 1:11a
* Updated in $/CodeJockey/CJLibrary
* Updated copyright and contact information.
*
* ***************** Version 10 *****************
* User: Kirk Stowell Date: 7/25/99 Time: 12:30a
* Updated in $/CodeJockey/CJLibrary
*
* ***************** Version 9 *****************
* User: Kirk Stowell Date: 6/23/99 Time: 12:33a
* Updated in $/CodeJockey/CJLibrary
*
* ***************** Version 8 *****************
* User: Kirk Stowell Date: 6/11/99 Time: 8:25p
* Updated in $/CodeJockey/CJ60Lib
* Slight modification made to popup menu code.
*
* ***************** Version 7 *****************
* User: Kirk Stowell Date: 6/09/99 Time: 8:33p
* Updated in $/CodeJockey/CJ60Lib
* Ioannhs Stamatopoulos (Yiannhs) [ystamat@mail.datamedia.gr] - Extended
* docking windows, removed ::GetSysColor(...) calls and WM_SYSCOLORCHANGE
* message handler, this is now automatically handled by the base class.
* Added redraw flags to the create method and modified paint and layout
* handlers to reduce flicker and un-necessary command handling. Dragging
* rect now reflects actual control bar docked size. Added "flat" look to
* the control bars, the control bars can now use the classic DevStudio
* look, or use flat gradient gripper, borders and frame buttons. Overall,
* docking windows now handle dragging, docking and floating much better,
* and behave more like DevStudio.
*
* ***************** Version 6 *****************
* User: Kirk Stowell Date: 5/02/99 Time: 5:23p
* Updated in $/CodeJockey/CJ60Lib
* Further modifications for CCJMenu support.
*
* ***************** Version 5 *****************
* User: Kirk Stowell Date: 5/02/99 Time: 2:18a
* Updated in $/CodeJockey/CJ60Lib
*
* ***************** Version 4 *****************
* User: Kirk Stowell Date: 5/02/99 Time: 2:13a
* Updated in $/CodeJockey/CJ60Lib
* Re-wrote CCJMenu initialization routines with a more cleaner approach.
*
* ***************** Version 3 *****************
* User: Kirk Stowell Date: 4/03/99 Time: 4:47p
* Updated in $/CodeJockey/CJ60Lib
* Added comments and cleaned up code. Added support for Brent Corkum's
* BCMenu (CCJMenu), which is a replacement for the CCoolMenu class.
*
* ***************** Version 2 *****************
* User: Kirk Stowell Date: 1/12/99 Time: 4:46p
* Updated in $/CodeJockey/CJ60Lib
* Total re-write to add side-by-side docking support for CCJControlBar
* class.
*
* ***************** Version 1 *****************
* User: Kirk Stowell Date: 10/17/98 Time: 4:46p
* Created in $/CodeJockey/CJ60Lib
* Initial re-write and release.
*
***************************************************************************/
/////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "CJFrameWnd.h"
//#include "CJDockBar.h"
//#include "CJSizeDockBar.h"
//#include "CJControlBar.h"
//#include "CJMiniDockFrameWnd.h"
#include "CJToolBar.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCJFrameWnd
CCJFrameWnd::CCJFrameWnd()
{
}
CCJFrameWnd::~CCJFrameWnd()
{
}
IMPLEMENT_DYNCREATE(CCJFrameWnd, CFrameWnd)
BEGIN_MESSAGE_MAP(CCJFrameWnd, CFrameWnd)
//{{AFX_MSG_MAP(CCJFrameWnd)
ON_WM_MEASUREITEM()
ON_WM_MENUCHAR()
ON_WM_INITMENUPOPUP()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCJFrameWnd message handlers
// dwDockBarMap
DWORD CCJFrameWnd::dwDockBarMap[4][2] =
{
{ AFX_IDW_DOCKBAR_TOP, CBRS_TOP },
{ AFX_IDW_DOCKBAR_BOTTOM, CBRS_BOTTOM },
{ AFX_IDW_DOCKBAR_LEFT, CBRS_LEFT },
{ AFX_IDW_DOCKBAR_RIGHT, CBRS_RIGHT },
};
HMENU CCJFrameWnd::NewMenu(UINT nMenuID, UINT nToolbarID)
{
// Load the menu and toolbar resource.
m_menu.LoadMenu(nMenuID);
if (nToolbarID) {
m_menu.LoadToolbar(nToolbarID);
}
// Detach the menu.
return(m_menu.Detach());
}
HMENU CCJFrameWnd::NewMenu(UINT nMenuID, UINT* nToolbarIDs, int nSize)
{
// Load the menu and toolbar resources.
m_menu.LoadMenu(nMenuID);
if (nToolbarIDs) {
m_menu.LoadToolbars(nToolbarIDs, nSize);
}
// Detach the menu.
return(m_menu.Detach());
}
BOOL CCJFrameWnd::InitializeMenu(UINT nMenuID, UINT nToolBarID/*=NULL*/)
{
ASSERT(nMenuID); // must be valid.
// Get a pointer to the existing menu, and destroy it.
CMenu* pMenu = GetMenu();
ASSERT_VALID(pMenu);
pMenu->DestroyMenu();
// Set the default menu with the newly created Menu.
m_hMenuDefault = NewMenu(nMenuID, nToolBarID);
SetMenu(CMenu::FromHandle(m_hMenuDefault));
return TRUE;
}
BOOL CCJFrameWnd::InitializeMenu(UINT nMenuID, UINT* nToolbarIDs/*=NULL*/, int nSize/*=NULL*/)
{
ASSERT(nMenuID); // must be valid.
// Get a pointer to the existing menu, and destroy it.
CMenu* pMenu = GetMenu();
ASSERT_VALID(pMenu);
pMenu->DestroyMenu();
// Set the default menu with the newly created Menu.
m_hMenuDefault = NewMenu(nMenuID, nToolbarIDs, nSize);
SetMenu(CMenu::FromHandle(m_hMenuDefault));
return TRUE;
}
void CCJFrameWnd::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct)
{
if (lpMeasureItemStruct->CtlType == ODT_MENU)
{
if (IsMenu((HMENU)lpMeasureItemStruct->itemID)) {
CMenu* pMenu = CMenu::FromHandle((HMENU)lpMeasureItemStruct->itemID);
if(m_menu.IsMenu(pMenu)) {
m_menu.MeasureItem(lpMeasureItemStruct);
return;
}
}
}
CFrameWnd::OnMeasureItem(nIDCtl, lpMeasureItemStruct);
}
LRESULT CCJFrameWnd::OnMenuChar(UINT nChar, UINT nFlags, CMenu* pMenu)
{
if(m_menu.IsMenu(pMenu)) {
return CCJMenu::FindKeyboardShortcut(nChar, nFlags, pMenu);
}
return CFrameWnd::OnMenuChar(nChar, nFlags, pMenu);
}
void CCJFrameWnd::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu)
{
CFrameWnd::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu);
if(!bSysMenu)
{
if(m_menu.IsMenu(pPopupMenu)) {
CCJMenu::UpdateMenu(pPopupMenu);
}
}
}
BOOL CCJFrameWnd::PreTranslateMessage(MSG* pMsg)
{
if( m_wndMenuBar.GetSafeHwnd()) {
if( m_wndMenuBar.TranslateFrameMessage(pMsg)) {
return TRUE;
}
}
return CFrameWnd::PreTranslateMessage(pMsg);
}
// Default implementation.
BOOL CCJFrameWnd::PreCreateWindow(CREATESTRUCT& cs)
{
return CFrameWnd::PreCreateWindow(cs);
}
////////////////
// Overloaded for flicker-free drawing with no CS_VREDRAW and CS_HREDRAW.
// Override in CMainFrame and call this method, rather than the default. Pass
// in your apps icon resource usually IDR_MAINFRAME.
//
BOOL CCJFrameWnd::PreCreateWindow(CREATESTRUCT& cs, UINT nIconID)
{
// Register wnd class with no redraw, cursor (use default), background
// brush and load your apps icon resource.
cs.lpszClass = AfxRegisterWndClass( 0, NULL, NULL,
AfxGetApp()->LoadIcon(nIconID));
ASSERT(cs.lpszClass);
return CFrameWnd::PreCreateWindow(cs);
}