MAINFRM.CPP
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:17k
源码类别:

Windows编程

开发平台:

Visual C++

  1. // mainfrm.cpp : implementation of the CMainFrame class
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1998 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12. #include "stdafx.h"
  13. #include "docktool.h"
  14. #include "tooldlg.h"
  15. #include "mainfrm.h"
  16. #ifdef _DEBUG
  17. #undef THIS_FILE
  18. static char BASED_CODE THIS_FILE[] = __FILE__;
  19. #endif
  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_COMMAND(ID_TOOLS_TOOLBAR, OnToolsToolbar)
  27. ON_COMMAND(ID_BROWSE_CLASSGRAPH, OnMenuSelection)
  28. ON_WM_CLOSE()
  29. ON_COMMAND(ID_BROWSE_FILEOUTLINE, OnMenuSelection)
  30. ON_COMMAND(ID_BROWSE_GOTODEFINITION, OnMenuSelection)
  31. ON_COMMAND(ID_BROWSE_GOTOREFERENCE, OnMenuSelection)
  32. ON_COMMAND(ID_BROWSE_REVERSECLASSGRAPH, OnMenuSelection)
  33. ON_COMMAND(ID_DEBUG_CALLSTACK, OnMenuSelection)
  34. ON_COMMAND(ID_DEBUG_DISASSEMBLY, OnMenuSelection)
  35. ON_COMMAND(ID_DEBUG_LOCALS, OnMenuSelection)
  36. ON_COMMAND(ID_DEBUG_MEMORY, OnMenuSelection)
  37. ON_COMMAND(ID_DEBUG_QUICKWATCH, OnMenuSelection)
  38. ON_COMMAND(ID_DEBUG_REGISTERS, OnMenuSelection)
  39. ON_COMMAND(ID_DEBUG_RESTART, OnMenuSelection)
  40. ON_COMMAND(ID_DEBUG_RUNTOCURSOR, OnMenuSelection)
  41. ON_COMMAND(ID_DEBUG_STEPINTO, OnMenuSelection)
  42. ON_COMMAND(ID_DEBUG_STEPOUT, OnMenuSelection)
  43. ON_COMMAND(ID_DEBUG_STEPOVER, OnMenuSelection)
  44. ON_COMMAND(ID_DEBUG_STOPDEBUGGING, OnMenuSelection)
  45. ON_COMMAND(ID_DEBUG_WATCH, OnMenuSelection)
  46. ON_COMMAND(ID_EDIT_BM_CLEARALL, OnMenuSelection)
  47. ON_COMMAND(ID_EDIT_BM_NEXT, OnMenuSelection)
  48. ON_COMMAND(ID_EDIT_BM_PREV, OnMenuSelection)
  49. ON_COMMAND(ID_EDIT_BM_TOGGLE, OnMenuSelection)
  50. ON_COMMAND(ID_EDIT_COPY, OnMenuSelection)
  51. ON_COMMAND(ID_EDIT_CUT, OnMenuSelection)
  52. ON_COMMAND(ID_EDIT_FINDINFILES, OnMenuSelection)
  53. ON_COMMAND(ID_EDIT_INDENT, OnMenuSelection)
  54. ON_COMMAND(ID_EDIT_PASTE, OnMenuSelection)
  55. ON_COMMAND(ID_EDIT_UNDO, OnMenuSelection)
  56. ON_COMMAND(ID_EDIT_UNINDENT, OnMenuSelection)
  57. ON_COMMAND(ID_PALETTE_AIRBRUSH, OnMenuSelection)
  58. ON_COMMAND(ID_PALETTE_BRUSH, OnMenuSelection)
  59. ON_COMMAND(ID_PALETTE_ERASE, OnMenuSelection)
  60. ON_COMMAND(ID_PALETTE_EYEDROP, OnMenuSelection)
  61. ON_COMMAND(ID_PALETTE_FILL, OnMenuSelection)
  62. ON_COMMAND(ID_PALETTE_FRAME, OnMenuSelection)
  63. ON_COMMAND(ID_PALETTE_LINE, OnMenuSelection)
  64. ON_COMMAND(ID_PALETTE_OVAL, OnMenuSelection)
  65. ON_COMMAND(ID_PALETTE_PEN, OnMenuSelection)
  66. ON_COMMAND(ID_PALETTE_RECTANGLE, OnMenuSelection)
  67. ON_COMMAND(ID_PALETTE_SELECT, OnMenuSelection)
  68. ON_COMMAND(ID_PALETTE_ZOOM, OnMenuSelection)
  69. ON_COMMAND(ID_RESOURCE_NEWACCELERATORTABLE, OnMenuSelection)
  70. ON_COMMAND(ID_RESOURCE_NEWBITMAP, OnMenuSelection)
  71. ON_COMMAND(ID_RESOURCE_NEWCURSOR, OnMenuSelection)
  72. ON_COMMAND(ID_RESOURCE_NEWICON, OnMenuSelection)
  73. ON_COMMAND(ID_RESOURCE_NEWMENU, OnMenuSelection)
  74. ON_COMMAND(ID_RESOURCE_NEWSTRINGTABLE, OnMenuSelection)
  75. ON_COMMAND(ID_RESOURCE_NEWVERSION, OnMenuSelection)
  76. ON_COMMAND(ID_EDIT_FIND, OnMenuSelection)
  77. //}}AFX_MSG_MAP
  78. // By making the Menu IDs that same as the ToolBar IDs
  79. // we can leverage off of code that is already provided
  80. // in MFCs implementation of CFrameWnd to check, uncheck
  81. // show and hide toolbars.
  82. ON_UPDATE_COMMAND_UI(IDW_BROWSE_BAR, OnUpdateControlBarMenu)
  83. ON_COMMAND_EX(IDW_BROWSE_BAR, OnBarCheck)
  84. ON_UPDATE_COMMAND_UI(IDW_DEBUG_BAR, OnUpdateControlBarMenu)
  85. ON_COMMAND_EX(IDW_DEBUG_BAR, OnBarCheck)
  86. ON_UPDATE_COMMAND_UI(IDW_EDIT_BAR, OnUpdateControlBarMenu)
  87. ON_COMMAND_EX(IDW_EDIT_BAR, OnBarCheck)
  88. ON_UPDATE_COMMAND_UI(IDW_PALETTE_BAR, OnUpdateControlBarMenu)
  89. ON_COMMAND_EX(IDW_PALETTE_BAR, OnBarCheck)
  90. ON_UPDATE_COMMAND_UI(IDW_RESOURCE_BAR, OnUpdateControlBarMenu)
  91. ON_COMMAND_EX(IDW_RESOURCE_BAR, OnBarCheck)
  92. END_MESSAGE_MAP()
  93. /////////////////////////////////////////////////////////////////////////////
  94. // arrays of IDs used to initialize control bars
  95. // toolbar buttons - IDs are command buttons
  96. static UINT BASED_CODE MainButtons[] =
  97. {
  98. // same order as in the bitmap 'toolbar.bmp'
  99. ID_FILE_NEW,
  100. ID_FILE_OPEN,
  101. ID_FILE_SAVE,
  102. ID_SEPARATOR,
  103. ID_EDIT_CUT,
  104. ID_EDIT_COPY,
  105. ID_EDIT_PASTE,
  106. };
  107. static UINT BASED_CODE ResourceButtons[] =
  108. {
  109. // same order as in the bitmap 'toolbar.bmp'
  110. ID_RESOURCE_NEWMENU,
  111. ID_RESOURCE_NEWCURSOR,
  112. ID_RESOURCE_NEWICON,
  113. ID_RESOURCE_NEWBITMAP,
  114. ID_RESOURCE_NEWSTRINGTABLE,
  115. ID_RESOURCE_NEWACCELERATORTABLE,
  116. ID_RESOURCE_NEWVERSION,
  117. };
  118. static UINT BASED_CODE DebugButtons[] =
  119. {
  120. // same order as in the bitmap 'toolbar.bmp'
  121. ID_DEBUG_RESTART,
  122. ID_DEBUG_STOPDEBUGGING,
  123. ID_DEBUG_STEPINTO,
  124. ID_DEBUG_STEPOUT,
  125. ID_DEBUG_STEPOVER,
  126. ID_DEBUG_RUNTOCURSOR,
  127. ID_DEBUG_QUICKWATCH,
  128. ID_DEBUG_WATCH,
  129. ID_DEBUG_LOCALS,
  130. ID_DEBUG_REGISTERS,
  131. ID_DEBUG_MEMORY,
  132. ID_DEBUG_CALLSTACK,
  133. ID_DEBUG_DISASSEMBLY,
  134. };
  135. static UINT BASED_CODE BrowseButtons[] =
  136. {
  137. // same order as in the bitmap 'toolbar.bmp'
  138. ID_BROWSE_GOTODEFINITION,
  139. ID_BROWSE_GOTOREFERENCE,
  140. ID_BROWSE_FILEOUTLINE,
  141. ID_BROWSE_CLASSGRAPH,
  142. ID_BROWSE_REVERSECLASSGRAPH,
  143. };
  144. static UINT BASED_CODE PaletteButtons[] =
  145. {
  146. // same order as in the bitmap 'toolbar.bmp'
  147. ID_PALETTE_ERASE,
  148. ID_PALETTE_PEN,
  149. ID_PALETTE_SELECT,
  150. ID_PALETTE_BRUSH,
  151. ID_PALETTE_AIRBRUSH,
  152. ID_PALETTE_FILL,
  153. ID_PALETTE_LINE,
  154. ID_PALETTE_EYEDROP,
  155. ID_PALETTE_ZOOM,
  156. ID_PALETTE_RECTANGLE,
  157. ID_PALETTE_FRAME,
  158. ID_PALETTE_OVAL,
  159. };
  160. static UINT BASED_CODE indicators[] =
  161. {
  162. ID_SEPARATOR,           // status line indicator
  163. ID_INDICATOR_CAPS,
  164. ID_INDICATOR_NUM,
  165. ID_INDICATOR_SCRL,
  166. };
  167. /////////////////////////////////////////////////////////////////////////////
  168. // Helpers for saving/restoring window state
  169. static TCHAR BASED_CODE szSection[] = _T("Settings");
  170. static TCHAR BASED_CODE szWindowPos[] = _T("WindowPos");
  171. static TCHAR szFormat[] = _T("%u,%u,%d,%d,%d,%d,%d,%d,%d,%d");
  172. static BOOL PASCAL NEAR ReadWindowPlacement(LPWINDOWPLACEMENT pwp)
  173. {
  174. CString strBuffer = AfxGetApp()->GetProfileString(szSection, szWindowPos);
  175. if (strBuffer.IsEmpty())
  176. return FALSE;
  177. WINDOWPLACEMENT wp;
  178. int nRead = _stscanf(strBuffer, szFormat,
  179. &wp.flags, &wp.showCmd,
  180. &wp.ptMinPosition.x, &wp.ptMinPosition.y,
  181. &wp.ptMaxPosition.x, &wp.ptMaxPosition.y,
  182. &wp.rcNormalPosition.left, &wp.rcNormalPosition.top,
  183. &wp.rcNormalPosition.right, &wp.rcNormalPosition.bottom);
  184. if (nRead != 10)
  185. return FALSE;
  186. wp.length = sizeof wp;
  187. *pwp = wp;
  188. return TRUE;
  189. }
  190. static void PASCAL NEAR WriteWindowPlacement(LPWINDOWPLACEMENT pwp)
  191. // write a window placement to settings section of app's ini file
  192. {
  193. TCHAR szBuffer[sizeof("-32767")*8 + sizeof("65535")*2];
  194. wsprintf(szBuffer, szFormat,
  195. pwp->flags, pwp->showCmd,
  196. pwp->ptMinPosition.x, pwp->ptMinPosition.y,
  197. pwp->ptMaxPosition.x, pwp->ptMaxPosition.y,
  198. pwp->rcNormalPosition.left, pwp->rcNormalPosition.top,
  199. pwp->rcNormalPosition.right, pwp->rcNormalPosition.bottom);
  200. AfxGetApp()->WriteProfileString(szSection, szWindowPos, szBuffer);
  201. }
  202. /////////////////////////////////////////////////////////////////////////////
  203. // CMainFrame construction/destruction
  204. CMainFrame::CMainFrame()
  205. {
  206. }
  207. CMainFrame::~CMainFrame()
  208. {
  209. }
  210. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  211. {
  212. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  213. return -1;
  214. WINDOWPLACEMENT wp;
  215. if (ReadWindowPlacement(&wp))
  216. SetWindowPlacement(&wp);
  217. m_bColor = (AfxGetApp()->GetProfileInt(_T("General"),_T("Color"),1)!=0);
  218. m_bToolTips = (AfxGetApp()->GetProfileInt(_T("General"),_T("ToolTips"),1)!=0);
  219. if (!m_wndMainBar.Create(this, WS_CHILD | WS_VISIBLE | CBRS_SIZE_DYNAMIC |
  220. CBRS_TOP | ((m_bToolTips)?(CBRS_TOOLTIPS | CBRS_FLYBY):0), IDW_MAIN_BAR) ||
  221. !m_wndMainBar.LoadBitmap(
  222. (m_bColor)?IDR_COLOR_MAINBAR:IDR_MONO_MAINBAR) ||
  223. !m_wndMainBar.SetButtons(MainButtons, sizeof(MainButtons)/sizeof(UINT)))
  224. {
  225. TRACE0("Failed to create mainbarn");
  226. return -1;      // fail to create
  227. }
  228. if (!m_wndResourceBar.Create(this, WS_CHILD | WS_VISIBLE | CBRS_SIZE_DYNAMIC |
  229. CBRS_TOP | ((m_bToolTips)?(CBRS_TOOLTIPS | CBRS_FLYBY):0), IDW_RESOURCE_BAR) ||
  230. !m_wndResourceBar.LoadBitmap(
  231. (m_bColor)?IDR_COLOR_RESOURCEBAR:IDR_MONO_RESOURCEBAR) ||
  232. !m_wndResourceBar.SetButtons(ResourceButtons, sizeof(ResourceButtons)/sizeof(UINT)))
  233. {
  234. TRACE0("Failed to create resourcebarn");
  235. return -1;      // fail to create
  236. }
  237. if (!m_wndDebugBar.Create(this, WS_CHILD | WS_VISIBLE | CBRS_SIZE_DYNAMIC |
  238. CBRS_TOP | ((m_bToolTips)?(CBRS_TOOLTIPS | CBRS_FLYBY):0), IDW_DEBUG_BAR) ||
  239. !m_wndDebugBar.LoadBitmap(
  240. (m_bColor)?IDR_COLOR_DEBUGBAR:IDR_MONO_DEBUGBAR) ||
  241. !m_wndDebugBar.SetButtons(DebugButtons, sizeof(DebugButtons)/sizeof(UINT)))
  242. {
  243. TRACE0("Failed to create debugbarn");
  244. return -1;      // fail to create
  245. }
  246. if (!m_wndEditBar.Init(this,m_bColor,m_bToolTips))
  247. {
  248. TRACE0("Failed to create editbarn");
  249. return -1;      // fail to create
  250. }
  251. if (!m_wndBrowseBar.Create(this, WS_CHILD | WS_VISIBLE | CBRS_SIZE_DYNAMIC |
  252. CBRS_TOP | ((m_bToolTips)?(CBRS_TOOLTIPS | CBRS_FLYBY):0), IDW_BROWSE_BAR) ||
  253. !m_wndBrowseBar.LoadBitmap(
  254. (m_bColor)?IDR_COLOR_BROWSEBAR:IDR_MONO_BROWSEBAR) ||
  255. !m_wndBrowseBar.SetButtons(BrowseButtons, sizeof(BrowseButtons)/sizeof(UINT)))
  256. {
  257. TRACE0("Failed to create browsebarn");
  258. return -1;      // fail to create
  259. }
  260. if (!m_wndPaletteBar.Create(this, WS_CHILD | WS_VISIBLE | CBRS_SIZE_FIXED |
  261. CBRS_TOP | ((m_bToolTips)?(CBRS_TOOLTIPS | CBRS_FLYBY):0), IDW_PALETTE_BAR) ||
  262. !m_wndPaletteBar.LoadBitmap(
  263. (m_bColor)?IDR_COLOR_PALETTEBAR:IDR_MONO_PALETTEBAR) ||
  264. !m_wndPaletteBar.SetButtons(PaletteButtons, sizeof(PaletteButtons)/sizeof(UINT)))
  265. {
  266. TRACE0("Failed to create palettebarn");
  267. return -1;      // fail to create
  268. }
  269. if (!m_wndStatusBar.Create(this) ||
  270. !m_wndStatusBar.SetIndicators(indicators,
  271.   sizeof(indicators)/sizeof(UINT)))
  272. {
  273. TRACE0("Failed to create status barn");
  274. return -1;      // fail to create
  275. }
  276. m_wndMainBar.SetWindowText(_T("Standard"));
  277. m_wndMainBar.EnableDocking(CBRS_ALIGN_ANY);
  278. m_wndResourceBar.SetWindowText(_T("Resource"));
  279. m_wndResourceBar.EnableDocking(CBRS_ALIGN_ANY);
  280. m_wndDebugBar.SetWindowText(_T("Debug"));
  281. m_wndDebugBar.EnableDocking(CBRS_ALIGN_ANY);
  282. m_wndEditBar.SetWindowText(_T("Edit"));
  283. m_wndEditBar.EnableDocking(CBRS_ALIGN_ANY);
  284. m_wndBrowseBar.SetWindowText(_T("Browse"));
  285. m_wndBrowseBar.EnableDocking(CBRS_ALIGN_ANY);
  286. m_wndPaletteBar.SetWindowText(_T("Palette"));
  287. m_wndPaletteBar.EnableDocking(CBRS_ALIGN_ANY);
  288. EnableDocking(CBRS_ALIGN_ANY);
  289. DockControlBar(&m_wndMainBar,AFX_IDW_DOCKBAR_TOP);
  290. DockControlBarLeftOf(&m_wndEditBar,&m_wndMainBar);
  291. DockControlBarLeftOf(&m_wndBrowseBar,&m_wndEditBar);
  292. DockControlBar(&m_wndResourceBar,AFX_IDW_DOCKBAR_BOTTOM);
  293. DockControlBarLeftOf(&m_wndDebugBar,&m_wndResourceBar);
  294. DockControlBar(&m_wndPaletteBar,AFX_IDW_DOCKBAR_RIGHT);
  295. // LoadBarState loads everything but the number of Columns in the Palette
  296. // we need to do that ourseleves.
  297. m_wndPaletteBar.SetColumns(AfxGetApp()->GetProfileInt(_T("General"),_T("Columns"),3));
  298. LoadBarState(_T("General"));
  299. return 0;
  300. }
  301. void CMainFrame::DockControlBarLeftOf(CToolBar* Bar,CToolBar* LeftOf)
  302. {
  303. CRect rect;
  304. DWORD dw;
  305. UINT n;
  306. // get MFC to adjust the dimensions of all docked ToolBars
  307. // so that GetWindowRect will be accurate
  308. RecalcLayout();
  309. LeftOf->GetWindowRect(&rect);
  310. rect.OffsetRect(1,0);
  311. dw=LeftOf->GetBarStyle();
  312. n = 0;
  313. n = (dw&CBRS_ALIGN_TOP) ? AFX_IDW_DOCKBAR_TOP : n;
  314. n = (dw&CBRS_ALIGN_BOTTOM && n==0) ? AFX_IDW_DOCKBAR_BOTTOM : n;
  315. n = (dw&CBRS_ALIGN_LEFT && n==0) ? AFX_IDW_DOCKBAR_LEFT : n;
  316. n = (dw&CBRS_ALIGN_RIGHT && n==0) ? AFX_IDW_DOCKBAR_RIGHT : n;
  317. // When we take the default parameters on rect, DockControlBar will dock
  318. // each Toolbar on a seperate line.  By calculating a rectangle, we in effect
  319. // are simulating a Toolbar being dragged to that location and docked.
  320. DockControlBar(Bar,n,&rect);
  321. }
  322. /////////////////////////////////////////////////////////////////////////////
  323. // CMainFrame diagnostics
  324. #ifdef _DEBUG
  325. void CMainFrame::AssertValid() const
  326. {
  327. CFrameWnd::AssertValid();
  328. }
  329. void CMainFrame::Dump(CDumpContext& dc) const
  330. {
  331. CFrameWnd::Dump(dc);
  332. }
  333. #endif //_DEBUG
  334. /////////////////////////////////////////////////////////////////////////////
  335. // CMainFrame message handlers
  336. void CMainFrame::OnToolsToolbar()
  337. {
  338. CToolDlg ToolDlg;
  339. UINT nColumns = m_wndPaletteBar.GetColumns();
  340. nColumns = (nColumns < 4) ? nColumns - 2: 3;
  341. // If the style says the ToolBar is visible then it is visible.
  342. ToolDlg.m_bMain = ((m_wndMainBar.GetStyle() & WS_VISIBLE) != 0);
  343. ToolDlg.m_bResource = ((m_wndResourceBar.GetStyle() & WS_VISIBLE) != 0);
  344. ToolDlg.m_bDebug = ((m_wndDebugBar.GetStyle() & WS_VISIBLE) != 0);
  345. ToolDlg.m_bEdit = ((m_wndEditBar.GetStyle() & WS_VISIBLE) != 0);
  346. ToolDlg.m_bBrowse = ((m_wndBrowseBar.GetStyle() & WS_VISIBLE) != 0);
  347. ToolDlg.m_bPalette = ((m_wndPaletteBar.GetStyle() & WS_VISIBLE) != 0);
  348. ToolDlg.m_nColumns = nColumns;
  349. ToolDlg.m_nColor = (m_bColor) ? 0 : 1;
  350. ToolDlg.m_nToolTips = (m_bToolTips) ? 0 : 1;
  351. if (IDOK == ToolDlg.DoModal())
  352. {
  353. ShowControlBar(&m_wndMainBar, ToolDlg.m_bMain, FALSE);
  354. ShowControlBar(&m_wndResourceBar, ToolDlg.m_bResource, FALSE);
  355. ShowControlBar(&m_wndDebugBar, ToolDlg.m_bDebug, FALSE);
  356. ShowControlBar(&m_wndEditBar, ToolDlg.m_bEdit, FALSE);
  357. ShowControlBar(&m_wndBrowseBar, ToolDlg.m_bBrowse, FALSE);
  358. ShowControlBar(&m_wndPaletteBar, ToolDlg.m_bPalette, FALSE);
  359. m_bToolTips = (ToolDlg.m_nToolTips==0);
  360. if (m_bToolTips)
  361. {
  362. m_wndMainBar.SetBarStyle(m_wndMainBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY);
  363. m_wndResourceBar.SetBarStyle(m_wndResourceBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY);
  364. m_wndDebugBar.SetBarStyle(m_wndDebugBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY);
  365. m_wndEditBar.SetBarStyle(m_wndEditBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY);
  366. m_wndBrowseBar.SetBarStyle(m_wndBrowseBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY);
  367. m_wndPaletteBar.SetBarStyle(m_wndPaletteBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY);
  368. }
  369. else
  370. {
  371. m_wndMainBar.SetBarStyle(m_wndMainBar.GetBarStyle() & ~(CBRS_TOOLTIPS | CBRS_FLYBY));
  372. m_wndResourceBar.SetBarStyle(m_wndResourceBar.GetBarStyle() & ~( CBRS_TOOLTIPS | CBRS_FLYBY));
  373. m_wndDebugBar.SetBarStyle(m_wndDebugBar.GetBarStyle() & ~( CBRS_TOOLTIPS | CBRS_FLYBY));
  374. m_wndEditBar.SetBarStyle(m_wndEditBar.GetBarStyle() & ~( CBRS_TOOLTIPS | CBRS_FLYBY));
  375. m_wndBrowseBar.SetBarStyle(m_wndBrowseBar.GetBarStyle() & ~( CBRS_TOOLTIPS | CBRS_FLYBY));
  376. m_wndPaletteBar.SetBarStyle(m_wndPaletteBar.GetBarStyle() & ~( CBRS_TOOLTIPS | CBRS_FLYBY));
  377. }
  378. nColumns = (ToolDlg.m_nColumns < 3) ? ToolDlg.m_nColumns + 2 : 6;
  379. m_wndPaletteBar.SetColumns(nColumns);
  380. m_bColor = (ToolDlg.m_nColor==0);
  381. if (m_bColor)
  382. {
  383. m_wndMainBar.LoadBitmap(IDR_COLOR_MAINBAR);
  384. m_wndResourceBar.LoadBitmap(IDR_COLOR_RESOURCEBAR);
  385. m_wndDebugBar.LoadBitmap(IDR_COLOR_DEBUGBAR);
  386. m_wndBrowseBar.LoadBitmap(IDR_COLOR_BROWSEBAR);
  387. m_wndPaletteBar.LoadBitmap(IDR_COLOR_PALETTEBAR);
  388. }
  389. else
  390. {
  391. m_wndMainBar.LoadBitmap(IDR_MONO_MAINBAR);
  392. m_wndResourceBar.LoadBitmap(IDR_MONO_RESOURCEBAR);
  393. m_wndDebugBar.LoadBitmap(IDR_MONO_DEBUGBAR);
  394. m_wndBrowseBar.LoadBitmap(IDR_MONO_BROWSEBAR);
  395. m_wndPaletteBar.LoadBitmap(IDR_MONO_PALETTEBAR);
  396. }
  397. m_wndEditBar.SetColor(m_bColor);
  398. m_wndMainBar.Invalidate();
  399. m_wndResourceBar.Invalidate();
  400. m_wndDebugBar.Invalidate();
  401. m_wndBrowseBar.Invalidate();
  402. m_wndPaletteBar.Invalidate();
  403. m_wndEditBar.Invalidate();
  404. }
  405. }
  406. void CMainFrame::OnMenuSelection()
  407. {
  408. // This sample doesn't do anything with button presses but a command handler
  409. // needs to be present for MFC to enable the buttons
  410. }
  411. void CMainFrame::OnClose()
  412. {
  413. // SaveBarState saves everything but the number of Columns in the Palette
  414. // we need to do that ourseleves.
  415. SaveBarState(_T("General"));
  416. AfxGetApp()->WriteProfileInt(
  417. _T("General"),_T("Columns"),m_wndPaletteBar.GetColumns());
  418. AfxGetApp()->WriteProfileInt(
  419. _T("General"),_T("Color"),(m_bColor!=0));
  420. AfxGetApp()->WriteProfileInt(
  421. _T("General"),_T("ToolTips"),(m_bToolTips!=0));
  422. WINDOWPLACEMENT wp;
  423. wp.length = sizeof wp;
  424. if (GetWindowPlacement(&wp))
  425. {
  426. wp.flags = 0;
  427. if (IsZoomed())
  428. wp.flags |= WPF_RESTORETOMAXIMIZED;
  429. // and write it to the .INI file
  430. WriteWindowPlacement(&wp);
  431. }
  432. CFrameWnd::OnClose();
  433. }
  434. BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
  435. {
  436. if (pMsg->message == WM_RBUTTONDOWN)
  437. {
  438. CWnd* pWnd = CWnd::FromHandlePermanent(pMsg->hwnd);
  439. CControlBar* pBar = DYNAMIC_DOWNCAST(CControlBar, pWnd);
  440. if (pBar != NULL)
  441.  {
  442. CMenu Menu;
  443. CPoint pt;
  444. pt.x = LOWORD(pMsg->lParam);
  445. pt.y = HIWORD(pMsg->lParam);
  446. pBar->ClientToScreen(&pt);
  447. if (Menu.LoadMenu(IDR_TOOLBAR))
  448. {
  449. CMenu* pSubMenu = Menu.GetSubMenu(0);
  450. if (pSubMenu!=NULL)
  451. {
  452. pSubMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON,pt.x,pt.y,this);
  453. }
  454. }
  455. }
  456. }
  457. return CFrameWnd::PreTranslateMessage(pMsg);
  458. }