MainFrm.cpp
资源名称:GGBT.rar [点击查看]
上传用户:lds876
上传日期:2013-05-25
资源大小:567k
文件大小:22k
源码类别:
P2P编程
开发平台:
Visual C++
- // MainFrm.cpp : implementation of the CMainFrame class
- //
- #include "stdafx.h"
- #include "testBT.h"
- #include "MainFrm.h"
- #include "testBTDoc.h"
- #include "testBTView.h"
- #include "FileDB.h"
- #include "DlgOptions.h"
- #include "DlgSetup.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- #define WM_SYSTEM_TRAY WM_USER+5300
- const string strOptionsSection = "Options";
- const string strOptionsHotkey = "hotkey";
- const string strOptionsHideTray = "HideTray";
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame
- IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
- BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
- //{{AFX_MSG_MAP(CMainFrame)
- ON_WM_CREATE()
- ON_WM_DROPFILES()
- ON_COMMAND(ID_MENUITEM_SHOWCATEGORY, OnMenuitemShowcategory)
- ON_COMMAND(ID_MENUITEM_SHOW_DETAIL, OnMenuitemShowDetail)
- ON_UPDATE_COMMAND_UI(ID_MENUITEM_SHOW_DETAIL, OnUpdateMenuitemShowDetail)
- ON_UPDATE_COMMAND_UI(ID_MENUITEM_SHOWCATEGORY, OnUpdateMenuitemShowcategory)
- ON_COMMAND(ID_MENUITEM_OPTIONS, OnMenuitemSetup)
- ON_WM_SHOWWINDOW()
- ON_WM_ACTIVATE()
- ON_COMMAND(ID_MENUITEM_SHOW_MAIN, OnMenuitemShowMain)
- ON_UPDATE_COMMAND_UI(ID_MENUITEM_SHOW_MAIN, OnUpdateMenuitemShowMain)
- ON_COMMAND(ID_MENUITEM_SHOW_DRAG_WND, OnMenuitemShowDragWnd)
- ON_UPDATE_COMMAND_UI(ID_MENUITEM_SHOW_DRAG_WND, OnUpdateMenuitemShowDragWnd)
- ON_COMMAND(ID_MENUITEM_DRAG_WND_STANDARD_SIZE, OnMenuitemDragWndStandardSize)
- ON_UPDATE_COMMAND_UI(ID_MENUITEM_SHOW_FONT, OnUpdateMenuitemShowFont)
- ON_COMMAND(ID_MENUITEM_SHOW_FONT, OnMenuitemShowFont)
- ON_WM_DESTROY()
- ON_WM_DRAWITEM()
- ON_WM_MEASUREITEM()
- ON_WM_INITMENU()
- ON_WM_INITMENUPOPUP()
- ON_COMMAND(ID_MENUITEM_CUSTOM_TOOLBAR, OnMenuitemCustomToolbar)
- ON_WM_SYSCOLORCHANGE()
- //}}AFX_MSG_MAP
- ON_MESSAGE(WM_SYSCOMMAND, OnSysCommand)
- ON_COMMAND(ID_MENUITEM_RESTORE, OnRestore)
- ON_MESSAGE(WM_HOTKEY,OnHotkey)
- ON_MESSAGE(WM_DRAGWND_NOTIFY, OnDragWndNotify)
- ON_COMMAND_RANGE(ID_MENUITEM_DRAGWND_TRANSPREANT_PERCENT_1, ID_MENUITEM_DRAGWND_TRANSPREANT_PERCENT_9, OnDragWndTransparent)
- ON_UPDATE_COMMAND_UI_RANGE(ID_MENUITEM_DRAGWND_TRANSPREANT_PERCENT_1, ID_MENUITEM_DRAGWND_TRANSPREANT_PERCENT_9, OnDragWndTransparentUI)
- END_MESSAGE_MAP()
- CToolBarInfo CMainFrame::mainToolBar[] =
- {
- {{0, ID_MENUITEM_DOWNLOAD , TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0}, "开始下载" },
- {{1, ID_MENUITEM_PAUSE , TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 1}, "暂停下载" },
- {{2, ID_MENUITEM_STOP , TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 2}, "停止下载" },
- {{0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0}, "停止下载" },
- {{3, ID_FILE_OPEN , TBSTATE_ENABLED, TBSTYLE_BUTTON , 0, 3}, "添加Torrent文件" },
- {{4, ID_MENUITEM_DEL , TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 4}, "删除" },
- {{0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0}, "停止下载" },
- {{5, ID_MENUITEM_FILE_PROPERTY , TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 5}, "属性" },
- {{6, ID_MENUITEM_OPEN_DOWNLOADED_FILE, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 6}, "打开文件" },
- {{7, ID_MENUITEM_OPEN_DOWNLOADED_DIRECTORY , TBSTATE_ENABLED, TBSTYLE_BUTTON , 0, 7}, "打开下载目录" },
- {{8, ID_MENUITEM_FIND_FILE, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 8}, "查找" },
- {{9, ID_MENUITEM_FIND_NEXT , TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 9}, "查找下一个"},
- {{0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0}, "停止下载" },
- {{10, ID_MENUITEM_OPTIONS, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 10}, "选项设置" },
- {{11, ID_APP_ABOUT, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 11}, "关于" },
- {{12, ID_APP_EXIT, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 12}, "退出" }
- };
- static UINT indicators[] =
- {
- ID_SEPARATOR, // status line indicator
- /*
- ID_INDICATOR_CAPS,
- ID_INDICATOR_NUM,
- ID_INDICATOR_SCRL,
- //*/
- };
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame construction/destruction
- CMainFrame::CMainFrame() : m_menuspawnPopup(true)
- {
- m_bNoHotkey = false;
- ((CTestBTApp*)AfxGetApp())->m_pMainFrame = this;
- }
- CMainFrame::~CMainFrame()
- {
- }
- BOOL CMainFrame::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
- {
- return CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
- }
- int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
- return -1;
- //
- // bitmap menu.
- //
- OnMenuCreate();
- // File open mode.
- DragAcceptFiles(true);
- //////////////////////////////////////////////////////////////////////////////////
- // toolbar
- //
- /*
- if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT|TBSTYLE_TRANSPARENT, WS_CHILD | WS_VISIBLE | CBRS_TOP
- | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
- !m_wndToolBar.LoadToolBar(IDR_MAINFRAME_BT))
- //*/
- if (!m_wndToolBar.Create(this, TBSTYLE_FLAT, // | TBSTYLE_TRANSPARENT,
- WS_CHILD | WS_VISIBLE | CBRS_TOP| CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC,
- AFX_IDW_TOOLBAR, mainToolBar,
- "Software\Shunfa BT\共工BT\ToolbarEx",
- "ToolBar Settings") || !m_wndToolBar.LoadToolBar(IDR_MAINFRAME_BT, TRUE))
- {
- TRACE0("Failed to create toolbarn");
- return -1; // fail to create
- }
- // m_wndToolBar.GetToolBarCtrl().SetButtonSize(CSize(30, 30));
- // m_wndToolBar.GetToolBarCtrl().SetBitmapSize(CSize(30, 30));
- // Load toolbar image.
- HBITMAP hbm = (HBITMAP)::LoadImage(AfxGetInstanceHandle(),
- MAKEINTRESOURCE(IDB_MAINFRAME_BT),
- IMAGE_BITMAP,
- 0,0, // cx,cy
- LR_CREATEDIBSECTION); // | LR_LOADMAP3DCOLORS );
- CBitmap bm;
- bm.Attach(hbm);
- m_ctlImage.Create(25, 25, ILC_COLOR8|ILC_MASK, 12, 4);
- m_ctlImage.SetBkColor(RGB(255, 255,255));
- m_ctlImage.Add(&bm, (COLORREF)RGB(255,0,255));
- // Load toolbar disabled image.
- HBITMAP hbmdisabled = (HBITMAP)::LoadImage(AfxGetInstanceHandle(),
- MAKEINTRESOURCE(IDB_MAINFRAME_BT_DISIBLE),
- IMAGE_BITMAP,
- 0,0, // cx,cy
- LR_CREATEDIBSECTION); // | LR_LOADMAP3DCOLORS );
- CBitmap bmdisabled;
- bmdisabled.Attach(hbmdisabled);
- m_ctlImageDisabled.Create(25, 25, ILC_COLOR8|ILC_MASK, 12, 4);
- m_ctlImageDisabled.SetBkColor(RGB(255, 255,255));
- m_ctlImageDisabled.Add(&bmdisabled, (COLORREF)RGB(255,0,255));
- // Set toolbar image.
- m_wndToolBar.GetToolBarCtrl().SetImageList(&m_ctlImage);
- m_wndToolBar.GetToolBarCtrl().SetHotImageList(&m_ctlImage);
- m_wndToolBar.GetToolBarCtrl().SetDisabledImageList(&m_ctlImageDisabled);
- m_wndToolBar.EnableToolTips();
- //////////////////////////////////////////////////////////////////////////////////
- // Monitor Speed Wnd.
- //
- CRect rectToolBar;
- m_wndToolBar.GetItemRect(0, &rectToolBar);
- rectToolBar.bottom = rectToolBar.bottom + 2;
- CRect rcMonitor = rectToolBar;
- rcMonitor.right = rcMonitor.left + 100;
- m_MonitorSpeedWnd.CreateEx(this, rcMonitor, 36547, 0, &m_CategoryBar.m_CategoryBarWnd);
- //////////////////////////////////////////////////////////////////////////////////
- // rebar.
- //
- // m_wndToolBar.SetSizes(rectToolBar.Size(), rectToolBar.Size());
- if(!m_wndReBar.Create(this, 0))
- return -1;
- m_wndReBar.AddBar(&m_wndToolBar, 0, 0, 0, RBBS_NOGRIPPER);
- m_wndReBar.AddBar(&m_MonitorSpeedWnd, NULL, 0, RBBS_FIXEDSIZE );
- REBARBANDINFO rbbi;
- rbbi.cbSize = sizeof(rbbi); //这个是必须填
- rbbi.fMask = RBBIM_CHILDSIZE | RBBIM_IDEALSIZE | RBBIM_SIZE |RBBIM_BACKGROUND;
- rbbi.cxMinChild = rectToolBar.Width();
- rbbi.cyMinChild = rectToolBar.Height();
- rbbi.hbmBack = LoadBitmap(::AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP_REBAR_BK));
- rbbi.cx = rbbi.cxIdeal = rectToolBar.Width() * 2;
- m_wndReBar.GetReBarCtrl().SetBandInfo(0, &rbbi);
- //////////////////////////////////////////////////////////////////////////////////
- // status bar.
- //
- if (!m_wndStatusBar.Create(this) ||
- !m_wndStatusBar.SetIndicators(indicators,
- sizeof(indicators)/sizeof(UINT)))
- {
- TRACE0("Failed to create status barn");
- return -1; // fail to create
- }
- //////////////////////////////////////////////////////////////////////////////////
- // Dock toolBar and StatusBar.
- EnableDocking(CBRS_ALIGN_ANY);
- // m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
- // DockControlBar(&m_wndToolBar);
- //////////////////////////////////////////////////////////////////////////////////
- // controlBar
- // m_MonitorBar.Create("hello", this, CSize(80, 80), TRUE, 123126);
- m_MonitorBar.CreateEx(this, CSize(80, 80), 123126, &m_setupRegister);
- m_MonitorBar.SetBarStyle(m_MonitorBar.GetBarStyle() |
- CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
- // m_CategoryBar.Create("hello", this, CSize(80, 80), TRUE, 123112);
- m_CategoryBar.CreateEx(this, CSize(80, 80), 123112, &m_setupRegister);
- m_CategoryBar.SetBarStyle(m_MonitorBar.GetBarStyle() |
- CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
- // m_MonitorBar, m_CategoryBar
- m_MonitorBar.EnableDocking(CBRS_ALIGN_ANY);
- m_CategoryBar.EnableDocking(CBRS_ALIGN_ANY);
- DockControlBar(&m_MonitorBar, AFX_IDW_DOCKBAR_BOTTOM);
- DockControlBar(&m_CategoryBar, AFX_IDW_DOCKBAR_LEFT);
- CSizingControlBar::GlobalLoadState(_T("BarState1"));
- if (VerifyBarState(_T("BarState1")))
- LoadBarState(_T("BarState1"));
- //////////////////////////////////////////////////////////////////////////////////
- // system tray and hotKey.
- m_SystemTray.Create(this,
- WM_SYSTEM_TRAY,
- _T("共工BT!"),
- AfxGetApp()->LoadIcon(IDR_MAINFRAME),
- IDR_MENU_SYSTEM_TRAY);
- if (!(AfxGetApp()->m_nCmdShow & SW_MINIMIZE))
- m_SystemTray.HideIcon();
- // hot key.
- if (m_setupRegister.m_dwHotKey)
- {
- if (!::RegisterHotKey(GetSafeHwnd(), HOTKEY_ID, HIBYTE(m_setupRegister.m_dwHotKey), LOBYTE(m_setupRegister.m_dwHotKey)))
- {
- // m_setupRegister.m_dwHotKey = 0;
- AfxMessageBox("注册热健失败");
- }
- }
- //////////////////////////////////////////////////////////////////////////////////
- // drag wnd.
- m_DragWnd.CreateExtend(this, &m_CategoryBar.m_CategoryBarWnd);
- // Show title.
- // GetActiveDocument()->SetTitle(m_CategoryBar.m_CategoryBarWnd.GetDatabaseName().data());
- //*
- if (m_setupRegister.m_bStartMin)
- PostMessage(WM_SYSCOMMAND, SC_MINIMIZE, 0);
- //*/
- return 0;
- }
- BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
- {
- // Load setup parameters.
- m_setupRegister.Read();
- if (m_setupRegister.m_bStartMin)
- {
- AfxGetApp()->m_nCmdShow = SW_SHOWMINIMIZED;
- // cs.style |= WS_MINIMIZE;
- }
- if( !CFrameWnd::PreCreateWindow(cs) )
- return FALSE;
- 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
- BOOL CMainFrame::DestroyWindow()
- {
- m_DragWnd.DestroyWindow();
- CSizingControlBar::GlobalSaveState(_T("BarState1"));
- SaveBarState(_T("BarState1"));
- m_setupRegister.Save();
- return CFrameWnd::DestroyWindow();
- }
- void CMainFrame::OnDropFiles(HDROP hDropInfo)
- {
- CFrameWnd::OnDropFiles(hDropInfo);
- }
- ////////////////////////////////////////////////////////////////////////////////
- // View menu
- void CMainFrame::OnMenuitemShowcategory()
- {
- ShowControlBar(&m_CategoryBar, !m_CategoryBar.IsVisible(), false);
- m_CategoryBar.SetFocus();
- }
- void CMainFrame::OnMenuitemShowDetail()
- {
- ShowControlBar(&m_MonitorBar, !m_MonitorBar.IsVisible(), false);
- m_MonitorBar.m_MonitorWnd.SetFocusCategory();
- }
- void CMainFrame::OnUpdateMenuitemShowDetail(CCmdUI* pCmdUI)
- {
- pCmdUI->SetCheck(m_MonitorBar.IsWindowVisible());
- }
- void CMainFrame::OnUpdateMenuitemShowcategory(CCmdUI* pCmdUI)
- {
- pCmdUI->SetCheck(m_CategoryBar.IsWindowVisible());
- }
- ///////////////////////////////////////////////////////////////////////////////
- // System tray
- LRESULT CMainFrame::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
- {
- if (message == WM_SYSTEM_TRAY)
- return m_SystemTray.OnTrayNotification(wParam, lParam);
- return CFrameWnd::DefWindowProc(message, wParam, lParam);
- }
- void CMainFrame::OnSysCommand(UINT nID, LPARAM lParam)
- {
- if (nID == SC_CLOSE)
- {
- if (IsWindowVisible())
- SwitchShowMain();
- return;
- }
- CFrameWnd::OnSysCommand(nID, lParam);
- if (nID == SC_MINIMIZE)
- {
- if (!m_setupRegister.m_bHideTray)
- m_SystemTray.ShowIcon();
- if (IsWindowVisible())
- ShowWindow(false);
- }
- else if (nID == SC_RESTORE) // useless, unknown take for unconsidered condition.
- m_SystemTray.HideIcon();
- }
- void CMainFrame::OnRestore()
- {
- ShowWindow(SW_SHOWNOACTIVATE);
- m_SystemTray.HideIcon();
- }
- void CMainFrame::OnHotkey(WPARAM wParam,LPARAM lParam)
- {
- if (m_bNoHotkey)
- return;
- SwitchShowMain();
- }
- void CMainFrame::OnMenuitemSetup()
- {
- m_bNoHotkey = true;
- CDlgSetup dlgSetup(&m_setupRegister);
- if (dlgSetup.DoModal() == IDOK)
- {
- // temp apply setup register here.
- // m_CategoryBar.m_CategoryBarWnd.SetDBSavePath(&m_setupRegister);
- CTestBTView* pView = (CTestBTView*)GetActiveView();
- if (pView)
- pView->m_FilesList.SetSetupParameter();
- else
- assert(false);
- }
- m_bNoHotkey = false;
- return;
- }
- void CMainFrame::OnShowWindow(BOOL bShow, UINT nStatus)
- {
- CFrameWnd::OnShowWindow(bShow, nStatus);
- }
- void CMainFrame::ActivateFrame(int nCmdShow)
- {
- CFrameWnd::ActivateFrame(nCmdShow);
- }
- void CMainFrame::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
- {
- // return;
- if ((nState == WA_ACTIVE) && !bMinimized )
- {
- // TRACE("rn%d, %drn", nState, bMinimized);
- m_SystemTray.HideIcon();
- }
- m_CategoryBar.m_CategoryBarWnd.SetFocus();
- CFrameWnd::OnActivate(nState, pWndOther, bMinimized);
- }
- void CMainFrame::OnContextMenu(CWnd* pWnd, CPoint point)
- {
- UINT iHit = OnNcHitTest(point);
- if (iHit ) // & HTCAPTION )
- {
- CMenu menu;
- if (menu.CreatePopupMenu())
- {
- menu.AppendMenu(MF_SEPARATOR);
- menu.AppendMenu(MF_STRING, ID_MENUITEM_OPEN_DOWNLOADED_FILE, "打开下载文件(&O)");
- menu.TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, point.x,
- point.y, this);
- }
- return;
- }
- CFrameWnd::OnContextMenu(pWnd, point);
- }
- void CMainFrame::OnNcRButtonUp(UINT nHitTest, CPoint point )
- {
- CMenu menu;
- if (menu.CreatePopupMenu())
- {
- menu.AppendMenu(MF_SEPARATOR);
- menu.AppendMenu(MF_STRING, ID_MENUITEM_OPEN_DOWNLOADED_FILE, "打开下载文件(&O)");
- menu.TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, point.x,
- point.y, this);
- }
- int i = 0;
- }
- void CMainFrame::OnRButtonUp( UINT nFlags, CPoint point )
- {
- int i = 0;;
- }
- UINT CMainFrame::OnNcHitTest(CPoint point)
- {
- return CFrameWnd::OnNcHitTest(point);
- }
- ///////////////////////////////////////////////////////////////////////////////////////////////////
- // drag Wnd.
- void CMainFrame::OnDragWndNotify(long lParam, long wParam)
- {
- switch (lParam)
- {
- case WM_CONTEXTMENU:
- {
- CPoint point;
- GetCursorPos(&point);
- CMenu menu_bar;
- menu_bar.LoadMenu(IDR_MENU_CATEGORY);
- CMenu& file_menu = *menu_bar.GetSubMenu(6);
- CMenu& TranMenu = *file_menu.GetSubMenu(4)->GetSubMenu(1);
- if (m_DragWnd.CanSetTransparent())
- {
- }
- m_menuspawnPopup.RemapMenuEx(&file_menu);
- //*/
- file_menu.TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, point.x,
- point.y, this);
- }
- break;
- case WM_LBUTTONDBLCLK:
- {
- SwitchShowMain();
- }
- }
- }
- void CMainFrame::SwitchShowMain()
- {
- if (IsWindowVisible())
- {
- if (!m_setupRegister.m_bHideTray)
- m_SystemTray.ShowIcon();
- PostMessage(WM_SYSCOMMAND, SC_MINIMIZE, 0);
- }
- else
- {
- m_SystemTray.HideIcon();
- ShowWindow(SW_SHOWNOACTIVATE);
- SetForegroundWindow();
- }
- }
- void CMainFrame::OnMenuitemShowMain()
- {
- SwitchShowMain();
- }
- void CMainFrame::OnUpdateMenuitemShowMain(CCmdUI* pCmdUI)
- {
- pCmdUI->SetCheck(IsWindowVisible());
- }
- void CMainFrame::OnMenuitemShowDragWnd()
- {
- m_DragWnd.ShowWindow(!m_DragWnd.IsWindowVisible());
- }
- void CMainFrame::OnUpdateMenuitemShowDragWnd(CCmdUI* pCmdUI)
- {
- pCmdUI->SetCheck(m_DragWnd.IsWindowVisible());
- }
- void CMainFrame::OnDragWndTransparent(UINT uID)
- {
- int iD = uID - ID_MENUITEM_DRAGWND_TRANSPREANT_PERCENT_1 + 1;
- m_DragWnd.SetOpacity(iD * 255 /10);
- }
- void CMainFrame::OnUpdateMenuitemShowFont(CCmdUI* pCmdUI)
- {
- pCmdUI->SetCheck(m_DragWnd.IsShowText());
- }
- void CMainFrame::OnMenuitemShowFont()
- {
- m_DragWnd.ShowText(!m_DragWnd.IsShowText());
- }
- void CMainFrame::OnDragWndTransparentUI(CCmdUI* pCmdUI)
- {
- int iID = pCmdUI->m_nID - ID_MENUITEM_DRAGWND_TRANSPREANT_PERCENT_1 + 1;
- int iOpacity = m_DragWnd.GetOpacity();
- iOpacity = iOpacity * 10 / 255;
- if (iOpacity <= 0)
- iOpacity = 1;
- pCmdUI->Enable(m_DragWnd.CanSetTransparent());
- pCmdUI->SetCheck(iOpacity == iID);
- }
- void CMainFrame::OnMenuitemDragWndStandardSize()
- {
- m_DragWnd.SetStandardSize();
- }
- //////////////////////////////////////////////////////////////////////////
- // tab view.
- BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
- {
- if (pMsg->message == WM_KEYDOWN)
- {
- switch (pMsg->wParam)
- {
- case VK_TAB:
- {
- if (GetKeyState(VK_CONTROL) < 0)
- {
- m_MonitorBar.m_MonitorWnd.SwitchMonitorCategory(GetKeyState(VK_SHIFT) >= 0);
- }
- else
- {
- CWnd* pNewWnd = GetNextDlgTabItem(GetKeyState(VK_SHIFT) >= 0);
- if (pNewWnd)
- {
- pNewWnd->SetFocus();
- return true;
- }
- }
- }
- break;
- }
- }
- return CFrameWnd::PreTranslateMessage(pMsg);
- }
- CWnd* CMainFrame::GetNextDlgTabItem(bool bNext)
- {
- CTestBTView* pView = (CTestBTView*)GetActiveView();
- if (!pView) return 0;
- CWnd* pFileList = &pView->m_FilesList;
- CWnd* pFocus = GetFocus();
- if (!pFocus)
- {
- return &m_CategoryBar.m_CategoryBarWnd;
- }
- else if (pFocus == &m_CategoryBar.m_CategoryBarWnd)
- {
- if (bNext)
- return pFileList;
- else
- return &m_MonitorBar.m_MonitorWnd.m_treeCategory;
- }
- else if (pFocus == pFileList)
- {
- if (bNext)
- return &m_MonitorBar.m_MonitorWnd.m_treeCategory;
- else
- return &m_CategoryBar.m_CategoryBarWnd;
- }
- else if (pFocus == &m_MonitorBar.m_MonitorWnd.m_treeCategory)
- {
- if (bNext)
- return &m_CategoryBar.m_CategoryBarWnd;
- else
- return pFileList;
- // return &m_MonitorBar.m_MonitorWnd.m_MonitorDetailWnd;
- }
- else
- {
- return &m_CategoryBar.m_CategoryBarWnd;
- }
- /*
- else if (pFocus == &m_MonitorBar.m_MonitorWnd.m_MonitorDetailWnd)
- {
- return &m_CategoryBar.m_CategoryBarWnd;
- }
- //*/
- return 0;
- }
- void CMainFrame::OnDestroy()
- {
- m_SystemTray.HideIcon();
- CFrameWnd::OnDestroy();
- }
- void CMainFrame::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
- {
- if (!m_menuspawn.DrawItem(lpDrawItemStruct))
- CFrameWnd::OnDrawItem(nIDCtl, lpDrawItemStruct);
- return;
- if ((HMENU)lpDrawItemStruct->hwndItem == GetMenu()->GetSafeHmenu())
- {
- if (!m_menuspawn.DrawItem(lpDrawItemStruct))
- CFrameWnd::OnDrawItem(nIDCtl, lpDrawItemStruct);
- }
- else
- {
- if (!m_menuspawnPopup.DrawItem(lpDrawItemStruct))
- CFrameWnd::OnDrawItem(nIDCtl, lpDrawItemStruct);
- }
- }
- void CMainFrame::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct)
- {
- if (!m_menuspawn.MeasureItem(lpMeasureItemStruct))
- CFrameWnd::OnMeasureItem(nIDCtl, lpMeasureItemStruct);
- }
- void CMainFrame::OnMenuCreate()
- {
- if (!GetSafeHwnd())
- {
- ASSERT(FALSE);
- return;
- }
- CMenu* pMenu = GetMenu();
- ULONG ulCmdID[] = {ID_FILE_OPEN,
- ID_FILE_NEW_DATABASE,
- ID_MENUITEM_OPEN_DATABASE,
- ID_FILE_SAVE_DATABASE,
- ID_MENUITEM_DOWNLOAD,
- ID_MENUITEM_PAUSE,
- ID_MENUITEM_STOP,
- ID_MENUITEM_DEL,
- CMenuSpawn::eUnusedImgCmdID,
- CMenuSpawn::eUnusedImgCmdID,
- CMenuSpawn::eNormalImgCmdID,
- };
- m_menuspawn.Create(IDB_IMAGELIST_MENU, IDB_IMAGELIST_MENU_DISABLED, sizeof(ulCmdID)/sizeof(ULONG), ulCmdID);
- m_menuspawn.RemapMenuEx(pMenu);
- m_menuspawnPopup.Create(IDB_IMAGELIST_MENU, IDB_IMAGELIST_MENU_DISABLED, sizeof(ulCmdID)/sizeof(ULONG), ulCmdID);
- }
- void CMainFrame::OnInitMenu(CMenu* pMenu)
- {
- if (pMenu == GetMenu())
- m_menuspawn.RemapMenuEx(pMenu);
- CFrameWnd::OnInitMenu(pMenu);
- }
- void CMainFrame::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu)
- {
- CFrameWnd::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu);
- // m_menuspawnPopup.RemapMenuEx(pPopupMenu);
- }
- void CMainFrame::OnMenuitemCustomToolbar()
- {
- m_wndToolBar.GetToolBarCtrl().Customize();
- }
- void CMainFrame::OnSysColorChange()
- {
- CFrameWnd::OnSysColorChange();
- CMenuSpawn::OnSystemColorChange();
- }
- /*-------------------------------------------------------------------
- If you use CFrameWnd's LoadBarState()/SaveBarState() to remember
- the positions of the control bars, you may run into this while
- developing your app - if you change the bar IDs, or simply remove
- a bar (it is no longer created in CMainFrame::OnCreate()), your
- app will crash.
- -------------------------------------------------------------------*/
- BOOL CMainFrame::VerifyBarState(LPCTSTR lpszProfileName)
- {
- CDockState state;
- state.LoadState(lpszProfileName);
- for (int i = 0; i < state.m_arrBarInfo.GetSize(); i++)
- {
- CControlBarInfo* pInfo = (CControlBarInfo*)state.m_arrBarInfo[i];
- ASSERT(pInfo != NULL);
- if (!pInfo) return false;
- int nDockedCount = pInfo->m_arrBarID.GetSize();
- if (nDockedCount > 0)
- {
- // dockbar
- for (int j = 0; j < nDockedCount; j++)
- {
- UINT nID = (UINT) pInfo->m_arrBarID[j];
- if (nID == 0) continue; // row separator
- if (nID > 0xFFFF)
- nID &= 0xFFFF; // placeholder - get the ID
- if (GetControlBar(nID) == NULL)
- return FALSE;
- }
- }
- if (!pInfo->m_bFloating) // floating dockbars can be created later
- if (GetControlBar(pInfo->m_nBarID) == NULL)
- return FALSE; // invalid bar ID
- if (pInfo->m_bDocking)
- {
- if (!pInfo->m_bFloating)
- {
- CDockBar* pDockBar = (CDockBar*)GetControlBar(pInfo->m_nBarID);
- if (!pDockBar) return false;
- if (pDockBar->m_pDockContext == NULL) return false;
- }
- }
- }
- return TRUE;
- }