MainFrm.cpp
上传用户:lds876
上传日期:2013-05-25
资源大小:567k
文件大小:22k
源码类别:

P2P编程

开发平台:

Visual C++

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3. #include "stdafx.h"
  4. #include "testBT.h"
  5. #include "MainFrm.h"
  6. #include "testBTDoc.h"
  7. #include "testBTView.h"
  8. #include "FileDB.h"
  9. #include "DlgOptions.h"
  10. #include "DlgSetup.h"
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16. #define WM_SYSTEM_TRAY WM_USER+5300
  17. const string strOptionsSection = "Options";
  18. const string strOptionsHotkey = "hotkey";
  19. const string strOptionsHideTray = "HideTray";
  20. /////////////////////////////////////////////////////////////////////////////
  21. // CMainFrame
  22. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  23. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  24. //{{AFX_MSG_MAP(CMainFrame)
  25. ON_WM_CREATE()
  26. ON_WM_DROPFILES()
  27. ON_COMMAND(ID_MENUITEM_SHOWCATEGORY, OnMenuitemShowcategory)
  28. ON_COMMAND(ID_MENUITEM_SHOW_DETAIL, OnMenuitemShowDetail)
  29. ON_UPDATE_COMMAND_UI(ID_MENUITEM_SHOW_DETAIL, OnUpdateMenuitemShowDetail)
  30. ON_UPDATE_COMMAND_UI(ID_MENUITEM_SHOWCATEGORY, OnUpdateMenuitemShowcategory)
  31. ON_COMMAND(ID_MENUITEM_OPTIONS, OnMenuitemSetup)
  32. ON_WM_SHOWWINDOW()
  33. ON_WM_ACTIVATE()
  34. ON_COMMAND(ID_MENUITEM_SHOW_MAIN, OnMenuitemShowMain)
  35. ON_UPDATE_COMMAND_UI(ID_MENUITEM_SHOW_MAIN, OnUpdateMenuitemShowMain)
  36. ON_COMMAND(ID_MENUITEM_SHOW_DRAG_WND, OnMenuitemShowDragWnd)
  37. ON_UPDATE_COMMAND_UI(ID_MENUITEM_SHOW_DRAG_WND, OnUpdateMenuitemShowDragWnd)
  38. ON_COMMAND(ID_MENUITEM_DRAG_WND_STANDARD_SIZE, OnMenuitemDragWndStandardSize)
  39. ON_UPDATE_COMMAND_UI(ID_MENUITEM_SHOW_FONT, OnUpdateMenuitemShowFont)
  40. ON_COMMAND(ID_MENUITEM_SHOW_FONT, OnMenuitemShowFont)
  41. ON_WM_DESTROY()
  42. ON_WM_DRAWITEM()
  43. ON_WM_MEASUREITEM()
  44. ON_WM_INITMENU()
  45. ON_WM_INITMENUPOPUP()
  46. ON_COMMAND(ID_MENUITEM_CUSTOM_TOOLBAR, OnMenuitemCustomToolbar)
  47. ON_WM_SYSCOLORCHANGE()
  48. //}}AFX_MSG_MAP
  49. ON_MESSAGE(WM_SYSCOMMAND, OnSysCommand)
  50. ON_COMMAND(ID_MENUITEM_RESTORE, OnRestore)
  51. ON_MESSAGE(WM_HOTKEY,OnHotkey)
  52. ON_MESSAGE(WM_DRAGWND_NOTIFY, OnDragWndNotify)
  53. ON_COMMAND_RANGE(ID_MENUITEM_DRAGWND_TRANSPREANT_PERCENT_1, ID_MENUITEM_DRAGWND_TRANSPREANT_PERCENT_9, OnDragWndTransparent)
  54. ON_UPDATE_COMMAND_UI_RANGE(ID_MENUITEM_DRAGWND_TRANSPREANT_PERCENT_1, ID_MENUITEM_DRAGWND_TRANSPREANT_PERCENT_9, OnDragWndTransparentUI)
  55. END_MESSAGE_MAP()
  56. CToolBarInfo CMainFrame::mainToolBar[] =
  57. {
  58. {{0, ID_MENUITEM_DOWNLOAD  , TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0}, "开始下载"     },
  59. {{1, ID_MENUITEM_PAUSE , TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 1}, "暂停下载"    },
  60. {{2, ID_MENUITEM_STOP , TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 2}, "停止下载"    },
  61. {{0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0}, "停止下载"    },
  62. {{3, ID_FILE_OPEN , TBSTATE_ENABLED, TBSTYLE_BUTTON   , 0, 3}, "添加Torrent文件"        },
  63. {{4, ID_MENUITEM_DEL  , TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 4}, "删除"     },
  64. {{0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0}, "停止下载"    },
  65. {{5, ID_MENUITEM_FILE_PROPERTY , TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 5}, "属性"    },
  66. {{6, ID_MENUITEM_OPEN_DOWNLOADED_FILE, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 6}, "打开文件"   },
  67. {{7, ID_MENUITEM_OPEN_DOWNLOADED_DIRECTORY , TBSTATE_ENABLED, TBSTYLE_BUTTON   , 0, 7}, "打开下载目录"   },
  68. {{8, ID_MENUITEM_FIND_FILE, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 8}, "查找" },
  69. {{9, ID_MENUITEM_FIND_NEXT , TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 9}, "查找下一个"},
  70. {{0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0}, "停止下载"    },
  71. {{10, ID_MENUITEM_OPTIONS, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 10}, "选项设置"   },
  72. {{11, ID_APP_ABOUT, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 11}, "关于"   },
  73. {{12, ID_APP_EXIT, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 12}, "退出"   }
  74. };
  75. static UINT indicators[] =
  76. {
  77. ID_SEPARATOR,           // status line indicator
  78. /*
  79. ID_INDICATOR_CAPS,
  80. ID_INDICATOR_NUM,
  81. ID_INDICATOR_SCRL,
  82. //*/
  83. };
  84. /////////////////////////////////////////////////////////////////////////////
  85. // CMainFrame construction/destruction
  86. CMainFrame::CMainFrame() : m_menuspawnPopup(true)
  87. {
  88. m_bNoHotkey = false;
  89. ((CTestBTApp*)AfxGetApp())->m_pMainFrame = this;
  90. }
  91. CMainFrame::~CMainFrame()
  92. {
  93. }
  94. BOOL CMainFrame::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) 
  95. {
  96. return CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
  97. }
  98. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  99. {
  100. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  101. return -1;
  102. //
  103. // bitmap menu.
  104. //
  105. OnMenuCreate();
  106. // File open mode.
  107. DragAcceptFiles(true);
  108. //////////////////////////////////////////////////////////////////////////////////
  109. // toolbar
  110. //
  111. /*
  112. if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT|TBSTYLE_TRANSPARENT, WS_CHILD | WS_VISIBLE | CBRS_TOP
  113. | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
  114. !m_wndToolBar.LoadToolBar(IDR_MAINFRAME_BT))
  115. //*/
  116. if (!m_wndToolBar.Create(this, TBSTYLE_FLAT, // | TBSTYLE_TRANSPARENT,  
  117. WS_CHILD | WS_VISIBLE | CBRS_TOP| CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC,
  118. AFX_IDW_TOOLBAR, mainToolBar,
  119. "Software\Shunfa BT\共工BT\ToolbarEx",
  120. "ToolBar Settings") || !m_wndToolBar.LoadToolBar(IDR_MAINFRAME_BT, TRUE))
  121. {
  122. TRACE0("Failed to create toolbarn");
  123. return -1;      // fail to create
  124. }
  125. // m_wndToolBar.GetToolBarCtrl().SetButtonSize(CSize(30, 30));
  126. // m_wndToolBar.GetToolBarCtrl().SetBitmapSize(CSize(30, 30));
  127. // Load toolbar image.
  128. HBITMAP hbm = (HBITMAP)::LoadImage(AfxGetInstanceHandle(),
  129. MAKEINTRESOURCE(IDB_MAINFRAME_BT),
  130. IMAGE_BITMAP,
  131. 0,0, // cx,cy
  132. LR_CREATEDIBSECTION); // | LR_LOADMAP3DCOLORS );
  133. CBitmap bm;
  134. bm.Attach(hbm);
  135. m_ctlImage.Create(25, 25, ILC_COLOR8|ILC_MASK, 12, 4);
  136. m_ctlImage.SetBkColor(RGB(255, 255,255)); 
  137. m_ctlImage.Add(&bm, (COLORREF)RGB(255,0,255));
  138. // Load toolbar disabled image.
  139. HBITMAP hbmdisabled = (HBITMAP)::LoadImage(AfxGetInstanceHandle(),
  140. MAKEINTRESOURCE(IDB_MAINFRAME_BT_DISIBLE),
  141. IMAGE_BITMAP,
  142. 0,0, // cx,cy
  143. LR_CREATEDIBSECTION); // | LR_LOADMAP3DCOLORS );
  144. CBitmap bmdisabled;
  145. bmdisabled.Attach(hbmdisabled);
  146. m_ctlImageDisabled.Create(25, 25, ILC_COLOR8|ILC_MASK, 12, 4);
  147. m_ctlImageDisabled.SetBkColor(RGB(255, 255,255)); 
  148. m_ctlImageDisabled.Add(&bmdisabled, (COLORREF)RGB(255,0,255));
  149. // Set toolbar image.
  150. m_wndToolBar.GetToolBarCtrl().SetImageList(&m_ctlImage);
  151. m_wndToolBar.GetToolBarCtrl().SetHotImageList(&m_ctlImage);
  152. m_wndToolBar.GetToolBarCtrl().SetDisabledImageList(&m_ctlImageDisabled);
  153. m_wndToolBar.EnableToolTips();
  154. //////////////////////////////////////////////////////////////////////////////////
  155. // Monitor Speed Wnd.
  156. //
  157. CRect rectToolBar;
  158. m_wndToolBar.GetItemRect(0, &rectToolBar);
  159. rectToolBar.bottom = rectToolBar.bottom + 2;
  160. CRect rcMonitor = rectToolBar;
  161. rcMonitor.right = rcMonitor.left + 100;
  162. m_MonitorSpeedWnd.CreateEx(this, rcMonitor, 36547, 0, &m_CategoryBar.m_CategoryBarWnd);
  163. //////////////////////////////////////////////////////////////////////////////////
  164. // rebar.
  165. //
  166. // m_wndToolBar.SetSizes(rectToolBar.Size(), rectToolBar.Size());
  167. if(!m_wndReBar.Create(this, 0))
  168. return -1;
  169. m_wndReBar.AddBar(&m_wndToolBar, 0, 0, 0, RBBS_NOGRIPPER);
  170. m_wndReBar.AddBar(&m_MonitorSpeedWnd, NULL, 0, RBBS_FIXEDSIZE );
  171. REBARBANDINFO rbbi;
  172. rbbi.cbSize = sizeof(rbbi); //这个是必须填
  173. rbbi.fMask = RBBIM_CHILDSIZE | RBBIM_IDEALSIZE | RBBIM_SIZE |RBBIM_BACKGROUND;
  174. rbbi.cxMinChild = rectToolBar.Width();
  175. rbbi.cyMinChild = rectToolBar.Height();
  176. rbbi.hbmBack = LoadBitmap(::AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP_REBAR_BK));
  177. rbbi.cx = rbbi.cxIdeal = rectToolBar.Width() * 2;
  178. m_wndReBar.GetReBarCtrl().SetBandInfo(0, &rbbi);
  179. //////////////////////////////////////////////////////////////////////////////////
  180. // status bar.
  181. //
  182. if (!m_wndStatusBar.Create(this) ||
  183. !m_wndStatusBar.SetIndicators(indicators,
  184.   sizeof(indicators)/sizeof(UINT)))
  185. {
  186. TRACE0("Failed to create status barn");
  187. return -1;      // fail to create
  188. }
  189. //////////////////////////////////////////////////////////////////////////////////
  190. // Dock toolBar and StatusBar.
  191. EnableDocking(CBRS_ALIGN_ANY);
  192. // m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
  193. // DockControlBar(&m_wndToolBar);
  194. //////////////////////////////////////////////////////////////////////////////////
  195. // controlBar
  196. // m_MonitorBar.Create("hello", this, CSize(80, 80), TRUE, 123126);
  197. m_MonitorBar.CreateEx(this, CSize(80, 80), 123126, &m_setupRegister);
  198. m_MonitorBar.SetBarStyle(m_MonitorBar.GetBarStyle() |
  199.         CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
  200. // m_CategoryBar.Create("hello", this, CSize(80, 80), TRUE, 123112);
  201. m_CategoryBar.CreateEx(this, CSize(80, 80), 123112, &m_setupRegister);
  202. m_CategoryBar.SetBarStyle(m_MonitorBar.GetBarStyle() |
  203.         CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
  204. // m_MonitorBar, m_CategoryBar
  205. m_MonitorBar.EnableDocking(CBRS_ALIGN_ANY);
  206. m_CategoryBar.EnableDocking(CBRS_ALIGN_ANY);
  207.     DockControlBar(&m_MonitorBar, AFX_IDW_DOCKBAR_BOTTOM);
  208. DockControlBar(&m_CategoryBar, AFX_IDW_DOCKBAR_LEFT);
  209. CSizingControlBar::GlobalLoadState(_T("BarState1"));
  210. if (VerifyBarState(_T("BarState1")))
  211. LoadBarState(_T("BarState1"));
  212. //////////////////////////////////////////////////////////////////////////////////
  213. // system tray and hotKey.
  214. m_SystemTray.Create(this, 
  215. WM_SYSTEM_TRAY, 
  216. _T("共工BT!"),
  217. AfxGetApp()->LoadIcon(IDR_MAINFRAME),
  218. IDR_MENU_SYSTEM_TRAY);
  219. if (!(AfxGetApp()->m_nCmdShow & SW_MINIMIZE)) 
  220. m_SystemTray.HideIcon();
  221. // hot key.
  222. if (m_setupRegister.m_dwHotKey)
  223. {
  224. if (!::RegisterHotKey(GetSafeHwnd(), HOTKEY_ID, HIBYTE(m_setupRegister.m_dwHotKey), LOBYTE(m_setupRegister.m_dwHotKey)))
  225. {
  226. // m_setupRegister.m_dwHotKey = 0;
  227. AfxMessageBox("注册热健失败");
  228. }
  229. }
  230. //////////////////////////////////////////////////////////////////////////////////
  231. // drag wnd.
  232. m_DragWnd.CreateExtend(this, &m_CategoryBar.m_CategoryBarWnd);
  233. // Show title.
  234. // GetActiveDocument()->SetTitle(m_CategoryBar.m_CategoryBarWnd.GetDatabaseName().data());
  235. //*
  236. if (m_setupRegister.m_bStartMin)
  237. PostMessage(WM_SYSCOMMAND, SC_MINIMIZE, 0);
  238. //*/
  239. return 0;
  240. }
  241. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  242. {
  243. // Load setup parameters.
  244. m_setupRegister.Read();
  245. if (m_setupRegister.m_bStartMin)
  246. {
  247. AfxGetApp()->m_nCmdShow = SW_SHOWMINIMIZED;
  248. // cs.style  |=  WS_MINIMIZE;
  249. }
  250. if( !CFrameWnd::PreCreateWindow(cs) )
  251. return FALSE;
  252. return TRUE;
  253. }
  254. /////////////////////////////////////////////////////////////////////////////
  255. // CMainFrame diagnostics
  256. #ifdef _DEBUG
  257. void CMainFrame::AssertValid() const
  258. {
  259. CFrameWnd::AssertValid();
  260. }
  261. void CMainFrame::Dump(CDumpContext& dc) const
  262. {
  263. CFrameWnd::Dump(dc);
  264. }
  265. #endif //_DEBUG
  266. /////////////////////////////////////////////////////////////////////////////
  267. // CMainFrame message handlers
  268. BOOL CMainFrame::DestroyWindow() 
  269. {
  270. m_DragWnd.DestroyWindow();
  271. CSizingControlBar::GlobalSaveState(_T("BarState1"));
  272.     SaveBarState(_T("BarState1"));
  273. m_setupRegister.Save();
  274. return CFrameWnd::DestroyWindow();
  275. }
  276. void CMainFrame::OnDropFiles(HDROP hDropInfo) 
  277. {
  278. CFrameWnd::OnDropFiles(hDropInfo);
  279. }
  280. ////////////////////////////////////////////////////////////////////////////////
  281. // View menu
  282. void CMainFrame::OnMenuitemShowcategory() 
  283. {
  284. ShowControlBar(&m_CategoryBar, !m_CategoryBar.IsVisible(), false);
  285. m_CategoryBar.SetFocus();
  286. }
  287. void CMainFrame::OnMenuitemShowDetail() 
  288. {
  289. ShowControlBar(&m_MonitorBar, !m_MonitorBar.IsVisible(), false);
  290. m_MonitorBar.m_MonitorWnd.SetFocusCategory();
  291. }
  292. void CMainFrame::OnUpdateMenuitemShowDetail(CCmdUI* pCmdUI) 
  293. {
  294. pCmdUI->SetCheck(m_MonitorBar.IsWindowVisible());
  295. }
  296. void CMainFrame::OnUpdateMenuitemShowcategory(CCmdUI* pCmdUI) 
  297. {
  298. pCmdUI->SetCheck(m_CategoryBar.IsWindowVisible());
  299. }
  300. ///////////////////////////////////////////////////////////////////////////////
  301. // System tray
  302. LRESULT CMainFrame::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
  303. {
  304. if (message == WM_SYSTEM_TRAY)
  305.         return m_SystemTray.OnTrayNotification(wParam, lParam);
  306. return CFrameWnd::DefWindowProc(message, wParam, lParam);
  307. }
  308. void CMainFrame::OnSysCommand(UINT nID, LPARAM lParam)
  309. {
  310. if (nID == SC_CLOSE)
  311. {
  312. if (IsWindowVisible())
  313. SwitchShowMain();
  314. return;
  315. }
  316. CFrameWnd::OnSysCommand(nID, lParam);
  317. if (nID == SC_MINIMIZE)
  318. {
  319. if (!m_setupRegister.m_bHideTray)
  320. m_SystemTray.ShowIcon();
  321. if (IsWindowVisible())
  322. ShowWindow(false);
  323. }
  324. else if (nID == SC_RESTORE) // useless, unknown take for unconsidered condition.
  325. m_SystemTray.HideIcon();
  326. }
  327. void CMainFrame::OnRestore()
  328. {
  329. ShowWindow(SW_SHOWNOACTIVATE);
  330. m_SystemTray.HideIcon();
  331. }
  332. void CMainFrame::OnHotkey(WPARAM wParam,LPARAM lParam)
  333. {
  334. if (m_bNoHotkey)
  335. return;
  336. SwitchShowMain();
  337. }
  338. void CMainFrame::OnMenuitemSetup() 
  339. {
  340. m_bNoHotkey = true;
  341. CDlgSetup dlgSetup(&m_setupRegister);
  342. if (dlgSetup.DoModal() == IDOK)
  343. {
  344. // temp apply setup register here.
  345. // m_CategoryBar.m_CategoryBarWnd.SetDBSavePath(&m_setupRegister);
  346. CTestBTView* pView = (CTestBTView*)GetActiveView();
  347. if (pView)
  348. pView->m_FilesList.SetSetupParameter();
  349. else
  350. assert(false);
  351. }
  352. m_bNoHotkey = false;
  353. return;
  354. }
  355. void CMainFrame::OnShowWindow(BOOL bShow, UINT nStatus) 
  356. {
  357. CFrameWnd::OnShowWindow(bShow, nStatus);
  358. }
  359. void CMainFrame::ActivateFrame(int nCmdShow) 
  360. {
  361. CFrameWnd::ActivateFrame(nCmdShow);
  362. }
  363. void CMainFrame::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized) 
  364. {
  365. // return;
  366. if ((nState == WA_ACTIVE) && !bMinimized )
  367. {
  368. // TRACE("rn%d, %drn", nState, bMinimized);
  369. m_SystemTray.HideIcon();
  370. }
  371. m_CategoryBar.m_CategoryBarWnd.SetFocus();
  372. CFrameWnd::OnActivate(nState, pWndOther, bMinimized);
  373. }
  374. void CMainFrame::OnContextMenu(CWnd* pWnd, CPoint point) 
  375. {
  376. UINT iHit = OnNcHitTest(point);
  377. if (iHit ) // & HTCAPTION )
  378. {
  379. CMenu menu;
  380. if (menu.CreatePopupMenu())
  381. {
  382. menu.AppendMenu(MF_SEPARATOR);
  383. menu.AppendMenu(MF_STRING, ID_MENUITEM_OPEN_DOWNLOADED_FILE, "打开下载文件(&O)");
  384. menu.TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, point.x, 
  385. point.y, this);
  386. }
  387. return;
  388. }
  389. CFrameWnd::OnContextMenu(pWnd, point);
  390. }
  391. void CMainFrame::OnNcRButtonUp(UINT nHitTest, CPoint point )
  392. {
  393. CMenu menu;
  394. if (menu.CreatePopupMenu())
  395. {
  396. menu.AppendMenu(MF_SEPARATOR);
  397. menu.AppendMenu(MF_STRING, ID_MENUITEM_OPEN_DOWNLOADED_FILE, "打开下载文件(&O)");
  398. menu.TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, point.x, 
  399. point.y, this);
  400. }
  401. int i = 0;
  402. }
  403. void CMainFrame::OnRButtonUp( UINT nFlags, CPoint point )
  404. {
  405. int i = 0;;
  406. }
  407. UINT CMainFrame::OnNcHitTest(CPoint point) 
  408. {
  409. return CFrameWnd::OnNcHitTest(point);
  410. }
  411. ///////////////////////////////////////////////////////////////////////////////////////////////////
  412. // drag Wnd.
  413. void CMainFrame::OnDragWndNotify(long lParam, long wParam)
  414. {
  415. switch (lParam)
  416. {
  417. case WM_CONTEXTMENU:
  418. {
  419. CPoint point;
  420. GetCursorPos(&point);
  421. CMenu menu_bar;
  422. menu_bar.LoadMenu(IDR_MENU_CATEGORY);
  423. CMenu& file_menu = *menu_bar.GetSubMenu(6);
  424. CMenu& TranMenu = *file_menu.GetSubMenu(4)->GetSubMenu(1);
  425. if (m_DragWnd.CanSetTransparent())
  426. {
  427. }
  428. m_menuspawnPopup.RemapMenuEx(&file_menu);
  429. //*/
  430. file_menu.TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, point.x, 
  431. point.y, this);
  432. }
  433. break;
  434. case WM_LBUTTONDBLCLK:
  435. {
  436. SwitchShowMain();
  437. }
  438. }
  439. }
  440. void CMainFrame::SwitchShowMain() 
  441. {
  442. if (IsWindowVisible())
  443. {
  444. if (!m_setupRegister.m_bHideTray)
  445. m_SystemTray.ShowIcon();
  446. PostMessage(WM_SYSCOMMAND, SC_MINIMIZE, 0);
  447. }
  448. else
  449. {
  450. m_SystemTray.HideIcon();
  451. ShowWindow(SW_SHOWNOACTIVATE);
  452. SetForegroundWindow();
  453. }
  454. }
  455. void CMainFrame::OnMenuitemShowMain() 
  456. {
  457. SwitchShowMain();
  458. }
  459. void CMainFrame::OnUpdateMenuitemShowMain(CCmdUI* pCmdUI) 
  460. {
  461. pCmdUI->SetCheck(IsWindowVisible());
  462. }
  463. void CMainFrame::OnMenuitemShowDragWnd() 
  464. {
  465. m_DragWnd.ShowWindow(!m_DragWnd.IsWindowVisible());
  466. }
  467. void CMainFrame::OnUpdateMenuitemShowDragWnd(CCmdUI* pCmdUI) 
  468. {
  469. pCmdUI->SetCheck(m_DragWnd.IsWindowVisible());
  470. }
  471. void CMainFrame::OnDragWndTransparent(UINT uID)
  472. {
  473. int iD = uID - ID_MENUITEM_DRAGWND_TRANSPREANT_PERCENT_1 + 1;
  474. m_DragWnd.SetOpacity(iD * 255 /10);
  475. }
  476. void CMainFrame::OnUpdateMenuitemShowFont(CCmdUI* pCmdUI) 
  477. {
  478. pCmdUI->SetCheck(m_DragWnd.IsShowText());
  479. }
  480. void CMainFrame::OnMenuitemShowFont() 
  481. {
  482. m_DragWnd.ShowText(!m_DragWnd.IsShowText());
  483. }
  484. void CMainFrame::OnDragWndTransparentUI(CCmdUI* pCmdUI)
  485. {
  486. int iID = pCmdUI->m_nID - ID_MENUITEM_DRAGWND_TRANSPREANT_PERCENT_1 + 1;
  487. int iOpacity = m_DragWnd.GetOpacity();
  488. iOpacity = iOpacity * 10 / 255;
  489. if (iOpacity <= 0)
  490. iOpacity = 1;
  491. pCmdUI->Enable(m_DragWnd.CanSetTransparent());
  492. pCmdUI->SetCheck(iOpacity == iID);
  493. }
  494. void CMainFrame::OnMenuitemDragWndStandardSize() 
  495. {
  496. m_DragWnd.SetStandardSize();
  497. }
  498. //////////////////////////////////////////////////////////////////////////
  499. // tab view.
  500. BOOL CMainFrame::PreTranslateMessage(MSG* pMsg) 
  501. {
  502. if (pMsg->message == WM_KEYDOWN)
  503. {
  504. switch (pMsg->wParam)
  505. {
  506. case VK_TAB:
  507. {
  508. if (GetKeyState(VK_CONTROL) < 0)
  509. {
  510. m_MonitorBar.m_MonitorWnd.SwitchMonitorCategory(GetKeyState(VK_SHIFT) >= 0);
  511. }
  512. else
  513. {
  514. CWnd* pNewWnd = GetNextDlgTabItem(GetKeyState(VK_SHIFT) >= 0);
  515. if (pNewWnd)
  516. {
  517. pNewWnd->SetFocus();
  518. return true;
  519. }
  520. }
  521. }
  522. break;
  523. }
  524. }
  525. return CFrameWnd::PreTranslateMessage(pMsg);
  526. }
  527. CWnd* CMainFrame::GetNextDlgTabItem(bool bNext)
  528. {
  529. CTestBTView* pView = (CTestBTView*)GetActiveView();
  530. if (!pView) return 0;
  531. CWnd* pFileList = &pView->m_FilesList;
  532. CWnd* pFocus = GetFocus();
  533. if (!pFocus)
  534. {
  535. return &m_CategoryBar.m_CategoryBarWnd;
  536. }
  537. else if (pFocus == &m_CategoryBar.m_CategoryBarWnd)
  538. {
  539. if (bNext)
  540. return pFileList;
  541. else
  542. return &m_MonitorBar.m_MonitorWnd.m_treeCategory;
  543. }
  544. else if (pFocus == pFileList)
  545. {
  546. if (bNext)
  547. return &m_MonitorBar.m_MonitorWnd.m_treeCategory;
  548. else
  549. return &m_CategoryBar.m_CategoryBarWnd;
  550. }
  551. else if (pFocus == &m_MonitorBar.m_MonitorWnd.m_treeCategory)
  552. {
  553. if (bNext)
  554. return &m_CategoryBar.m_CategoryBarWnd;
  555. else
  556. return pFileList;
  557. // return &m_MonitorBar.m_MonitorWnd.m_MonitorDetailWnd;
  558. }
  559. else
  560. {
  561. return &m_CategoryBar.m_CategoryBarWnd;
  562. }
  563. /*
  564. else if (pFocus == &m_MonitorBar.m_MonitorWnd.m_MonitorDetailWnd)
  565. {
  566. return &m_CategoryBar.m_CategoryBarWnd;
  567. }
  568. //*/
  569. return 0;
  570. }
  571. void CMainFrame::OnDestroy() 
  572. {
  573. m_SystemTray.HideIcon();
  574. CFrameWnd::OnDestroy();
  575. }
  576. void CMainFrame::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct) 
  577. {
  578. if (!m_menuspawn.DrawItem(lpDrawItemStruct))
  579. CFrameWnd::OnDrawItem(nIDCtl, lpDrawItemStruct);
  580. return;
  581. if ((HMENU)lpDrawItemStruct->hwndItem == GetMenu()->GetSafeHmenu())
  582. {
  583. if (!m_menuspawn.DrawItem(lpDrawItemStruct))
  584. CFrameWnd::OnDrawItem(nIDCtl, lpDrawItemStruct);
  585. }
  586. else
  587. {
  588. if (!m_menuspawnPopup.DrawItem(lpDrawItemStruct))
  589. CFrameWnd::OnDrawItem(nIDCtl, lpDrawItemStruct);
  590. }
  591. }
  592. void CMainFrame::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct) 
  593. {
  594. if (!m_menuspawn.MeasureItem(lpMeasureItemStruct))
  595. CFrameWnd::OnMeasureItem(nIDCtl, lpMeasureItemStruct);
  596. }
  597. void CMainFrame::OnMenuCreate() 
  598. {
  599. if (!GetSafeHwnd())
  600. {
  601. ASSERT(FALSE);
  602. return;
  603. }
  604. CMenu* pMenu = GetMenu();
  605. ULONG ulCmdID[] = {ID_FILE_OPEN, 
  606. ID_FILE_NEW_DATABASE, 
  607. ID_MENUITEM_OPEN_DATABASE, 
  608. ID_FILE_SAVE_DATABASE,
  609. ID_MENUITEM_DOWNLOAD,
  610. ID_MENUITEM_PAUSE,
  611. ID_MENUITEM_STOP,
  612. ID_MENUITEM_DEL,
  613. CMenuSpawn::eUnusedImgCmdID,
  614. CMenuSpawn::eUnusedImgCmdID,
  615. CMenuSpawn::eNormalImgCmdID,
  616. };
  617. m_menuspawn.Create(IDB_IMAGELIST_MENU, IDB_IMAGELIST_MENU_DISABLED, sizeof(ulCmdID)/sizeof(ULONG), ulCmdID);
  618. m_menuspawn.RemapMenuEx(pMenu);
  619. m_menuspawnPopup.Create(IDB_IMAGELIST_MENU, IDB_IMAGELIST_MENU_DISABLED, sizeof(ulCmdID)/sizeof(ULONG), ulCmdID);
  620. }
  621. void CMainFrame::OnInitMenu(CMenu* pMenu) 
  622. {
  623. if (pMenu == GetMenu())
  624. m_menuspawn.RemapMenuEx(pMenu);
  625. CFrameWnd::OnInitMenu(pMenu);
  626. }
  627. void CMainFrame::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu) 
  628. {
  629. CFrameWnd::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu);
  630. // m_menuspawnPopup.RemapMenuEx(pPopupMenu);
  631. }
  632. void CMainFrame::OnMenuitemCustomToolbar() 
  633. {
  634. m_wndToolBar.GetToolBarCtrl().Customize();
  635. }
  636. void CMainFrame::OnSysColorChange() 
  637. {
  638. CFrameWnd::OnSysColorChange();
  639. CMenuSpawn::OnSystemColorChange();
  640. }
  641. /*-------------------------------------------------------------------
  642.   If you use CFrameWnd's LoadBarState()/SaveBarState() to remember 
  643.   the positions of the control bars, you may run into this while
  644.   developing your app - if you change the bar IDs, or simply remove
  645.   a bar (it is no longer created in CMainFrame::OnCreate()), your
  646.   app will crash.
  647. -------------------------------------------------------------------*/
  648. BOOL CMainFrame::VerifyBarState(LPCTSTR lpszProfileName)
  649. {
  650.     CDockState state;
  651.     state.LoadState(lpszProfileName);
  652.     for (int i = 0; i < state.m_arrBarInfo.GetSize(); i++)
  653.     {
  654.         CControlBarInfo* pInfo = (CControlBarInfo*)state.m_arrBarInfo[i];
  655.         ASSERT(pInfo != NULL);
  656. if (!pInfo) return false;
  657.         int nDockedCount = pInfo->m_arrBarID.GetSize();
  658.         if (nDockedCount > 0)
  659.         {
  660.             // dockbar
  661.             for (int j = 0; j < nDockedCount; j++)
  662.             {
  663.                 UINT nID = (UINT) pInfo->m_arrBarID[j];
  664.                 if (nID == 0) continue; // row separator
  665.                 if (nID > 0xFFFF)
  666.                     nID &= 0xFFFF; // placeholder - get the ID
  667.                 if (GetControlBar(nID) == NULL)
  668.                     return FALSE;
  669. }
  670. }
  671.         
  672.         if (!pInfo->m_bFloating) // floating dockbars can be created later
  673.             if (GetControlBar(pInfo->m_nBarID) == NULL)
  674.                 return FALSE; // invalid bar ID
  675. if (pInfo->m_bDocking)
  676. {
  677. if (!pInfo->m_bFloating)
  678. {
  679. CDockBar* pDockBar = (CDockBar*)GetControlBar(pInfo->m_nBarID);
  680. if (!pDockBar) return false;
  681. if (pDockBar->m_pDockContext == NULL) return false;
  682. }
  683. }
  684.     }
  685.     return TRUE;
  686. }