CSDN博客

img fudegang

这个是怎么切分的窗口

发表于2008/10/1 8:32:00  1103人阅读

#include "MainFrm.h"
#include "newGSDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMainFrame

IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)

const int  iMaxUserToolbars  = 10;
const UINT uiFirstUserToolBarId = AFX_IDW_CONTROLBAR_FIRST + 40;
const UINT uiLastUserToolBarId = uiFirstUserToolBarId + iMaxUserToolbars - 1;

BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
 //{{AFX_MSG_MAP(CMainFrame)
 ON_WM_CREATE()
 //}}AFX_MSG_MAP
 ON_COMMAND(ID_VIEW_CUSTOMIZE, OnViewCustomize)
 ON_REGISTERED_MESSAGE(BCGM_RESETTOOLBAR, OnToolbarReset)
 ON_REGISTERED_MESSAGE(BCGM_TOOLBARMENU, OnToolbarContextMenu)
 ON_COMMAND_RANGE(ID_VIEW_USER_TOOLBAR1, ID_VIEW_USER_TOOLBAR10, OnToolsViewUserToolbar)
 ON_UPDATE_COMMAND_UI_RANGE(ID_VIEW_USER_TOOLBAR1, ID_VIEW_USER_TOOLBAR10, OnUpdateToolsViewUserToolbar)
 ON_COMMAND(ID_VIEW_WORKSPACE, OnViewWorkspace)
 ON_UPDATE_COMMAND_UI(ID_VIEW_WORKSPACE, OnUpdateViewWorkspace)
 ON_COMMAND(ID_VIEW_WORKSPACE2, OnViewWorkspace2)
 ON_UPDATE_COMMAND_UI(ID_VIEW_WORKSPACE2, OnUpdateViewWorkspace2)
 ON_COMMAND(ID_VIEW_OUTPUT, OnViewOutput)
 ON_UPDATE_COMMAND_UI(ID_VIEW_OUTPUT, OnUpdateViewOutput)
 ON_COMMAND(ID_VIEW_CAPTIONBAR, OnViewCaptionBar)
 ON_UPDATE_COMMAND_UI(ID_VIEW_CAPTIONBAR, OnUpdateViewCaptionBar)
END_MESSAGE_MAP()

static UINT indicators[] =
{
 ID_SEPARATOR,           // status line indicator
 ID_INDICATOR_CAPS,
 ID_INDICATOR_NUM,
 ID_INDICATOR_SCRL,
};

/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction

CMainFrame::CMainFrame()
{
 // TODO: add member initialization code here
 
}

CMainFrame::~CMainFrame()
{
}

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{//在此进行所有的初始化设置
 if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  return -1;

 // enable Windows XP look (in other OS Office XP look will be used):
 CBCGPVisualManager::SetDefaultManager (RUNTIME_CLASS (CBCGPWinXPVisualManager));
 // Load toolbar user images:

 CBCGPToolBar::EnableQuickCustomization ();


 // TODO: Define your own basic commands. Be sure, that each pulldown
 // menu have at least one basic command.

 CList<UINT, UINT> lstBasicCommands;

 lstBasicCommands.AddTail (ID_VIEW_TOOLBARS);
 lstBasicCommands.AddTail (ID_FILE_NEW);
 lstBasicCommands.AddTail (ID_FILE_OPEN);
 lstBasicCommands.AddTail (ID_FILE_SAVE);
 lstBasicCommands.AddTail (ID_FILE_PRINT);
 lstBasicCommands.AddTail (ID_APP_EXIT);
 lstBasicCommands.AddTail (ID_EDIT_CUT);
 lstBasicCommands.AddTail (ID_EDIT_PASTE);
 lstBasicCommands.AddTail (ID_EDIT_UNDO);
 lstBasicCommands.AddTail (ID_APP_ABOUT);
 lstBasicCommands.AddTail (ID_VIEW_TOOLBAR);
 lstBasicCommands.AddTail (ID_VIEW_CUSTOMIZE);

 CBCGPToolBar::SetBasicCommands (lstBasicCommands);

 if (!m_wndMenuBar.Create (this))
 {
  TRACE0("Failed to create menubar/n");
  return -1;      // fail to create
 }

 m_wndMenuBar.SetBarStyle(m_wndMenuBar.GetBarStyle() | CBRS_SIZE_DYNAMIC);

 // Detect color depth. 256 color toolbars can be used in the
 // high or true color modes only (bits per pixel is > 8):
 CClientDC dc (this);
 BOOL bIsHighColor = dc.GetDeviceCaps (BITSPIXEL) > 8;

 UINT uiToolbarHotID = bIsHighColor ? IDB_TOOLBAR256 : 0;
 UINT uiToolbarColdID = bIsHighColor ? IDB_TOOLBARCOLD256 : 0;

 if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
  | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
  !m_wndToolBar.LoadToolBar(IDR_MAINFRAME, uiToolbarColdID, 0, FALSE, 0, 0, uiToolbarHotID))
 {
  TRACE0("Failed to create toolbar/n");
  return -1;      // fail to create
 }
 if (!m_wndStatusBar.Create(this) ||
  !m_wndStatusBar.SetIndicators(indicators,
    sizeof(indicators)/sizeof(UINT)))
 {
  TRACE0("Failed to create status bar/n");
  return -1;      // fail to create
 }

 CImageList imagesWorkspace;
 imagesWorkspace.Create (IDB_WORKSPACE, 16, 0, RGB (255, 0, 255));
 
 //初始化执行模块列表
 if (!m_wndWorkSpace.Create (_T("执行模块库"), this, CRect (0, 0, 200, 200),
  TRUE, ID_VIEW_WORKSPACE,
  WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_LEFT | CBRS_FLOAT_MULTI,
  CBRS_BCGP_OUTLOOK_TABS))
 {
  TRACE0("Failed to create ToolBox1 bar/n");
  return FALSE;      // fail to create
 }

 m_wndWorkSpace.SetIcon (imagesWorkspace.ExtractIcon (0), FALSE);
 CString titles[] = {"前进","后退","左转","右转","输出","延时"};
 m_wndWorkSpace.Initialize(IDB_SHORTCUTS,titles,6,3);//载入各种图像
 
 //初始化控制模块列表
 if (!m_wndWorkSpace2.Create (_T("控制模块库"), this, CRect (0, 0, 200, 200),
  TRUE, ID_VIEW_WORKSPACE2,
  WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_LEFT | CBRS_FLOAT_MULTI,
  CBRS_BCGP_OUTLOOK_TABS))
 {
  TRACE0("Failed to create Workspace bar 2/n");
  return FALSE;      // fail to create
 }

 m_wndWorkSpace2.SetIcon (imagesWorkspace.ExtractIcon (1), FALSE);
 CString titles2[] = {"无限循环","条件判断","多次循环","跳出循环"};
 m_wndWorkSpace2.Initialize(IDB_SHORTCUTS2,titles2,4,21);
 
 //初始化控制模块列表
/* if (!m_wndWorkSpace3.Create (_T("控制模块库"), this, CRect (0, 0, 200, 200),
  TRUE, ID_VIEW_WORKSPACE3,
  WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_LEFT | CBRS_FLOAT_MULTI,
  CBRS_BCGP_OUTLOOK_TABS))
 {
  TRACE0("Failed to create Workspace bar 2/n");
  return FALSE;      // fail to create
 }

 m_wndWorkSpace3.SetIcon (imagesWorkspace.ExtractIcon (1), FALSE);
 CString titles3[] = {"无限循环","条件判断","多次循环","跳出循环"};
 m_wndWorkSpace3.Initialize(IDB_SHORTCUTS2,titles2,4,21);
*/
 if (!m_wndOutput.Create (_T("Robot C 语言"), this, CRect (0, 0, 150, 150),
  TRUE /* Has gripper */, ID_VIEW_OUTPUT,
  WS_CHILD | WS_VISIBLE | CBRS_RIGHT, CBRS_BCGP_OUTLOOK_TABS))
 {
  TRACE0("Failed to create output bar/n");
  return -1;      // fail to create
 }
 
 CString strMainToolbarTitle;
 strMainToolbarTitle.LoadString (IDS_MAIN_TOOLBAR);
 m_wndToolBar.SetWindowText (strMainToolbarTitle);
 // TODO: Delete these three lines if you don't want the toolbar to
 //  be dockable
 m_wndMenuBar.EnableDocking(CBRS_ALIGN_ANY);
 m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
 m_wndWorkSpace.EnableDocking(CBRS_ALIGN_ANY);
 m_wndWorkSpace2.EnableDocking(CBRS_ALIGN_ANY);
// m_wndWorkSpace3.EnableDocking(CBRS_ALIGN_ANY);
 m_wndOutput.EnableDocking(CBRS_ALIGN_ANY);
 EnableDocking(CBRS_ALIGN_ANY);
 
 if (!m_wndCaptionBar.Create (WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS, this,
  ID_VIEW_CAPTIONBAR, -1))
 {
  TRACE0("Failed to create caption bar/n");
  return -1;      // fail to create
 }

 m_wndCaptionBar.SetFlatBorder ();
 m_wndCaptionBar.SetText (_T("北京交通大学阳光公司教育机器人   服务在线:http://www.jiqiren.com          "),CBCGPCaptionBar::ALIGN_CENTER);
 m_bmpCaption.LoadBitmap (IDB_CAPTION);
 m_wndCaptionBar.SetBitmap (m_bmpCaption, RGB (0, 0, 255));
 m_wndCaptionBar.SetFlatBorder(false);
 m_wndCaptionBar.m_clrBarBackground = RGB(100,200,255);
 EnableAutoHideBars(CBRS_ALIGN_ANY);
 DockControlBar(&m_wndMenuBar);
 DockControlBar(&m_wndToolBar);
 DockControlBar (&m_wndWorkSpace);
 m_wndWorkSpace2.DockToWindow (&m_wndWorkSpace, CBRS_ALIGN_BOTTOM);
// m_wndWorkSpace3.DockToWindow (&m_wndWorkSpace2, CBRS_ALIGN_BOTTOM);
 //m_wndWorkSpace2.AttachToTabWnd (&m_wndWorkSpace, DM_STANDARD, FALSE, NULL);
 
 DockControlBar(&m_wndOutput);


 // Allow user-defined toolbars operations:
 InitUserToobars (NULL,
     uiFirstUserToolBarId,
     uiLastUserToolBarId);

 m_wndToolBar.EnableCustomizeButton (TRUE, ID_VIEW_CUSTOMIZE, _T("Customize..."));
 
 return 0;
}

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
 if( !CFrameWnd::PreCreateWindow(cs) )
  return FALSE;
 // TODO: Modify the Window class or styles here by modifying
 //  the CREATESTRUCT cs

 return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics

#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
 CFrameWnd::AssertValid();
}

void CMainFrame::Dump(CDumpContext& dc) const
{
 CFrameWnd::Dump(dc);
}

#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers


void CMainFrame::OnViewCustomize()
{
 //------------------------------------
 // Create a customize toolbars dialog:
 //------------------------------------
 CBCGPToolbarCustomize* pDlgCust = new CBCGPToolbarCustomize (this,
  TRUE /* Automatic menus scaning */
  );

 pDlgCust->EnableUserDefinedToolbars ();
 pDlgCust->Create ();
}

LRESULT CMainFrame::OnToolbarContextMenu(WPARAM,LPARAM lp)
{
 CPoint point (BCG_GET_X_LPARAM(lp), BCG_GET_Y_LPARAM(lp));

 CMenu menu;
 VERIFY(menu.LoadMenu (IDR_POPUP_TOOLBAR));

 CMenu* pPopup = menu.GetSubMenu(0);
 ASSERT(pPopup != NULL);

 SetupToolbarMenu (*pPopup, ID_VIEW_USER_TOOLBAR1, ID_VIEW_USER_TOOLBAR10);

 CBCGPPopupMenu* pPopupMenu = new CBCGPPopupMenu;
 pPopupMenu->Create (this, point.x, point.y, pPopup->Detach ());

 return 0;
}

void CMainFrame::OnToolsViewUserToolbar (UINT uiId)
{
 CBCGPToolBar* pUserToolBar = GetUserBarByIndex (uiId - ID_VIEW_USER_TOOLBAR1);
 if (pUserToolBar == NULL)
 {
  ASSERT (FALSE);
  return;
 }

 ShowControlBar (pUserToolBar, !(pUserToolBar->IsVisible ()), FALSE, TRUE);
 RecalcLayout ();
}

void CMainFrame::OnUpdateToolsViewUserToolbar (CCmdUI* pCmdUI)
{
 CBCGPToolBar* pUserToolBar = GetUserBarByIndex (pCmdUI->m_nID - ID_VIEW_USER_TOOLBAR1);
 if (pUserToolBar == NULL)
 {
  pCmdUI->Enable (FALSE);
  return;
 }

 pCmdUI->Enable ();
 pCmdUI->SetCheck (pUserToolBar->IsVisible ());
}

afx_msg LRESULT CMainFrame::OnToolbarReset(WPARAM /*wp*/,LPARAM)
{
 // TODO: reset toolbar with id = (UINT) wp to its initial state:
 //
 // UINT uiToolBarId = (UINT) wp;
 // if (uiToolBarId == IDR_MAINFRAME)
 // {
 //  do something with m_wndToolBar
 // }

 return 0;
}

BOOL CMainFrame::OnShowPopupMenu (CBCGPPopupMenu* pMenuPopup)
{
 //---------------------------------------------------------
 // Replace ID_VIEW_TOOLBARS menu item to the toolbars list:
 //---------------------------------------------------------
    CFrameWnd::OnShowPopupMenu (pMenuPopup);

    if (pMenuPopup != NULL &&
  pMenuPopup->GetMenuBar ()->CommandToIndex (ID_VIEW_TOOLBARS) >= 0)
    {
  if (CBCGPToolBar::IsCustomizeMode ())
  {
   //----------------------------------------------------
   // Don't show toolbars list in the cuztomization mode!
   //----------------------------------------------------
   return FALSE;
  }

  pMenuPopup->RemoveAllItems ();

  CMenu menu;
  VERIFY(menu.LoadMenu (IDR_POPUP_TOOLBAR));

  CMenu* pPopup = menu.GetSubMenu(0);
  ASSERT(pPopup != NULL);

  SetupToolbarMenu (*pPopup, ID_VIEW_USER_TOOLBAR1, ID_VIEW_USER_TOOLBAR10);
  pMenuPopup->GetMenuBar ()->ImportFromMenu (*pPopup, TRUE);
    }

 return TRUE;
}

void CMainFrame::OnViewWorkspace()
{
 ShowControlBar (&m_wndWorkSpace,
     !(m_wndWorkSpace.IsVisible ()),
     FALSE, TRUE);
 RecalcLayout ();
}

void CMainFrame::OnUpdateViewWorkspace(CCmdUI* pCmdUI)
{
 pCmdUI->SetCheck (m_wndWorkSpace.IsVisible ());
}

void CMainFrame::OnViewWorkspace2()
{
 ShowControlBar (&m_wndWorkSpace2,
     !(m_wndWorkSpace2.IsVisible ()),
     FALSE, TRUE);
 RecalcLayout ();
}

void CMainFrame::OnUpdateViewWorkspace2(CCmdUI* pCmdUI)
{
 pCmdUI->SetCheck (m_wndWorkSpace2.IsVisible ());
}

void CMainFrame::OnViewOutput()
{
 ShowControlBar (&m_wndOutput,
     !(m_wndOutput.IsVisible ()),
     FALSE, TRUE);
 RecalcLayout ();
}

void CMainFrame::OnUpdateViewOutput(CCmdUI* pCmdUI)
{
 pCmdUI->SetCheck (m_wndOutput.IsVisible ());
}

void CMainFrame::OnViewCaptionBar()
{
 ShowControlBar (&m_wndCaptionBar,
     !(m_wndCaptionBar.IsVisible ()),
     FALSE, TRUE);
 RecalcLayout ();
}

void CMainFrame::OnUpdateViewCaptionBar(CCmdUI* pCmdUI)
{
 pCmdUI->SetCheck (m_wndCaptionBar.IsVisible ());
}

/**
 得到模块列表区指针
*/
CToolBoxBar * CMainFrame::GetToolBoxBar(int catalog)
{
 switch(catalog)
 {
 case 1:
  return &m_wndWorkSpace;
 case 2:
  return &m_wndWorkSpace2;
 case 0:
  return NULL;
 }

 return NULL;
}

0 0

相关博文

我的热门文章

img
取 消
img