www.gusucode.com > VC++编写的SQL服务端和客户端源码程序 > VC++编写的SQL服务端和客户端源码程序\code\Server\MainFrm.cpp
// MainFrm.cpp : implementation of the CMainFrame class // Download by http://www.NewXing.com #include "stdafx.h" #include "miniSQL.h" #include "MainFrm.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif extern CMiniSQLApp theApp; ///////////////////////////////////////////////////////////////////////////// // CMainFrame IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd) BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd) ON_COMMAND_EX(ID_FILEBAR, OnBarCheck) ON_UPDATE_COMMAND_UI(ID_FILEBAR, OnUpdateControlBarMenu) ON_COMMAND_EX(ID_TABBAR, OnBarCheck) ON_UPDATE_COMMAND_UI(ID_TABBAR, OnUpdateControlBarMenu) //{{AFX_MSG_MAP(CMainFrame) ON_WM_CREATE() ON_COMMAND(ID_ADD_FILES, OnAddFiles) ON_COMMAND(ID_PROPERTY, OnProperty) ON_COMMAND(ID_VIEW_DB, OnViewDb) ON_COMMAND(ID_EXPANDING, OnExpanding) ON_COMMAND(ID_RICH_CLEAR, OnRichClear) // ON_WM_DROPFILES() //}}AFX_MSG_MAP 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 (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1) return -1; 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)) { 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 } // TODO: Delete these three lines if you don't want the toolbar to // be dockable m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY); EnableDocking(CBRS_ALIGN_ANY); DockControlBar(&m_wndToolBar); // allow files to be dropped on main window or any child window // DragAcceptFiles(); // Install cool menus. InstallCoolMenus(this, IDR_MAINFRAME); //////////////////////////////////////////////////////////////////////// //Install image for the left file bar m_ImageList.Create( IDB_IMAGELIST, 13, 1, RGB(0,255,0) ); //////////////////////////////////////////////////////////////////////// //Create the file bar m_FileBar.SetBtnImageList( &m_ImageList ); // Initialize m_FileBar if (!m_FileBar.Create( this, ID_FILEBAR , _T("FileBar"), CSize(240,200) ) ) { TRACE0("Failed to create file bar\n"); return -1; // fail to create } // allow the file bar to be resized when floating m_FileBar.SetBarStyle(m_FileBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC); m_FileBar.EnableDocking(CBRS_ALIGN_ANY); EnableDocking(CBRS_ALIGN_ANY); DockControlBar(&m_FileBar, AFX_IDW_DOCKBAR_LEFT); ///////////////////////////////////////////////////////////////////////// //Create tab bar m_TabBar.SetBtnImageList( &m_ImageList ); // Initialize Tab bar if (!m_TabBar.Create(this, ID_TABBAR, _T("TabBar"), CSize(220,100))) { TRACE0("Failed to create tab bar\n"); return -1; // fail to create } // Add views to the tab control. // allow bar to be resized when floating m_TabBar.SetBarStyle(m_TabBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC); m_TabBar.EnableDocking(CBRS_ALIGN_ANY); EnableDocking(CBRS_ALIGN_ANY); DockControlBar(&m_TabBar, AFX_IDW_DOCKBAR_BOTTOM); return 0; } BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) { cs.cy = ::GetSystemMetrics(SM_CYSCREEN) - 40; cs.cx = ::GetSystemMetrics(SM_CXSCREEN) - 20; cs.y = 10; cs.x = 10; return CMDIFrameWnd::PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// // CMainFrame diagnostics #ifdef _DEBUG void CMainFrame::AssertValid() const { CMDIFrameWnd::AssertValid(); } void CMainFrame::Dump(CDumpContext& dc) const { CMDIFrameWnd::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CMainFrame message handlers void CMainFrame::OnAddFiles() { // TODO: Add your command handler code here BOOL bOpenFileDialog = TRUE; CFileDialog *pDlg = new CFileDialog(bOpenFileDialog, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_ALLOWMULTISELECT, "miniSQL数据库 (*.msl)|*.msl||"); Item temp; pDlg->m_ofn.lpstrTitle = "添加miniSQL数据库"; if( (pDlg->DoModal()==IDOK) ){ POSITION pos = pDlg->GetStartPosition(); while(pos){ Item temp; temp.path = pDlg->GetNextPathName(pos); char ch[100]; ::GetFileTitle(temp.path, ch, 100); temp.name = ch; m_FileBar.insert_tree(temp, m_FileBar.hitem0); } m_FileBar.ExpandTree(); } } void CMainFrame::OnProperty() { m_FileBar.Property(); } void CMainFrame::OnViewDb() { m_FileBar.ViewDb(); } void CMainFrame::OnExpanding() { m_FileBar.Expanding(); } void CMainFrame::OnRichClear() { m_TabBar.Clear(); } /* void CMainFrame::OnDropFiles(HDROP hDropInfo) { // get file stored in hDropInfo and use app to open it TCHAR szFileName[ 1024 ]; ::DragQueryFile( hDropInfo, 0, szFileName, 1024 ); ::DragFinish( hDropInfo ); theApp.OpenDocumentFile( szFileName ); CMDIFrameWnd::OnDropFiles(hDropInfo); } */