MainFrm.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. // Download by http://www.codefans.net
  3. #include "stdafx.h"
  4. #include "HDraw.h"
  5. #include "MainFrm.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CMainFrame
  13. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  14. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  15. //{{AFX_MSG_MAP(CMainFrame)
  16. ON_WM_CREATE()
  17. ON_COMMAND(ID_VIEW_PICS, OnViewPics)
  18. ON_UPDATE_COMMAND_UI(ID_VIEW_PICS, OnUpdateViewPics)
  19. ON_COMMAND(ID_VIEW_COLOR, OnViewColor)
  20. ON_UPDATE_COMMAND_UI(ID_VIEW_COLOR, OnUpdateViewColor)
  21. ON_WM_TIMER()
  22. //}}AFX_MSG_MAP
  23. ON_MESSAGE(WM_USER_ACTIVE, OnOtherViewActive)
  24. END_MESSAGE_MAP()
  25. static UINT indicators[] =
  26. {
  27. ID_SEPARATOR, // status line indicator
  28. ID_INDICATOR_CAPS,
  29. ID_INDICATOR_NUM,
  30. ID_INDICATOR_SCRL,
  31. };
  32. /////////////////////////////////////////////////////////////////////////////
  33. // CMainFrame construction/destruction
  34. CMainFrame::CMainFrame()
  35. {
  36. // TODO: add member initialization code here
  37. m_icons[0] = LoadIcon(AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDI_ICON1));
  38. m_icons[1] = LoadIcon(AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDI_ICON2));
  39. m_icons[2] = LoadIcon(AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDI_ICON3));
  40. m_icons[3] = LoadIcon(AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDI_ICON4));
  41. m_icons[4] = LoadIcon(AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDI_ICON5));
  42. }
  43. CMainFrame::~CMainFrame()
  44. {
  45. if(m_colorBar != NULL)
  46. delete m_colorBar;
  47. }
  48. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  49. {
  50. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  51. return -1;
  52. if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
  53. | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
  54. !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
  55. {
  56. TRACE0("Failed to create toolbar\n");
  57. return -1; // fail to create
  58. }
  59. if (!m_wndStatusBar.Create(this) ||
  60. !m_wndStatusBar.SetIndicators(indicators,
  61. sizeof(indicators)/sizeof(UINT)))
  62. {
  63. TRACE0("Failed to create status bar\n");
  64. return -1; // fail to create
  65. }
  66. //my picture bar
  67. if (!m_picBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_LEFT
  68. | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_FIXED) ||
  69. !m_picBar.LoadToolBar(IDR_TOOLBAR_PIC))
  70. {
  71. TRACE0("Failed to create toolbar\n");
  72. return -1; // fail to create
  73. }
  74. int nCount = m_picBar.GetToolBarCtrl().GetButtonCount();
  75. for(int i=0;i<nCount;i++)
  76. {
  77. UINT nStyle=m_picBar.GetButtonStyle(i);
  78. nStyle|=TBBS_WRAPPED;
  79. m_picBar.SetButtonStyle(i,nStyle);
  80. }
  81. m_colorBar = new HColorBar();
  82. //my color bar
  83. if (!m_colorBar->CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_BOTTOM
  84. | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
  85. !m_colorBar->LoadToolBar(IDR_TOOLBAR_COLOR))
  86. {
  87. TRACE0("Failed to create toolbar\n");
  88. return -1; // fail to create
  89. }
  90. // TODO: Delete these three lines if you don't want the toolbar to
  91. // be dockable
  92. m_wndToolBar.EnableDocking(CBRS_ALIGN_TOP);
  93. m_picBar.EnableDocking(CBRS_ALIGN_LEFT);
  94. m_colorBar->EnableDocking(CBRS_ALIGN_TOP|CBRS_ALIGN_RIGHT);
  95. EnableDocking(CBRS_ALIGN_ANY);
  96. DockControlBar(&m_picBar);
  97. DockControlBar(&m_wndToolBar);
  98. DockControlBar(m_colorBar);
  99. SetClassLong(m_hWnd, GCL_HICON, (LONG)m_icons[0]);
  100. SetTimer(WM_ICONALT, 1000, NULL);
  101. return 0;
  102. }
  103. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  104. {
  105. if( !CFrameWnd::PreCreateWindow(cs) )
  106. return FALSE;
  107. // TODO: Modify the Window class or styles here by modifying
  108. // the CREATESTRUCT cs
  109. return TRUE;
  110. }
  111. /////////////////////////////////////////////////////////////////////////////
  112. // CMainFrame diagnostics
  113. #ifdef _DEBUG
  114. void CMainFrame::AssertValid() const
  115. {
  116. CFrameWnd::AssertValid();
  117. }
  118. void CMainFrame::Dump(CDumpContext& dc) const
  119. {
  120. CFrameWnd::Dump(dc);
  121. }
  122. #endif //_DEBUG
  123. /////////////////////////////////////////////////////////////////////////////
  124. // CMainFrame message handlers
  125. LRESULT CMainFrame::OnOtherViewActive(WPARAM wParam,LPARAM lParam)
  126. {
  127. m_pViewActive = (CView *)wParam;
  128. return 0;
  129. }
  130. void CMainFrame::OnViewPics()
  131. {
  132. // TODO: Add your command handler code here
  133. ShowControlBar(&m_picBar, !m_picBar.IsWindowVisible(), FALSE);
  134. //must use this to make the toolbar disappear
  135. //if not this command, the toolbar still locate there while components hide
  136. RecalcLayout();
  137. //the toolbar goes forever if closed and no the command below
  138. DockControlBar(&m_picBar);
  139. }
  140. void CMainFrame::OnViewColor()
  141. {
  142. // TODO: Add your command handler code here
  143. //alternate show/hide
  144. ShowControlBar(m_colorBar, !m_colorBar->IsWindowVisible(), FALSE);
  145. //must use this to make the toolbar disappear
  146. //if not this command, the toolbar still locate there while components hide
  147. RecalcLayout();
  148. DockControlBar(m_colorBar);
  149. }
  150. void CMainFrame::OnUpdateViewColor(CCmdUI* pCmdUI)
  151. {
  152. // TODO: Add your command update UI handler code here
  153. pCmdUI->SetCheck(m_colorBar->IsWindowVisible());
  154. }
  155. void CMainFrame::OnUpdateViewPics(CCmdUI* pCmdUI)
  156. {
  157. // TODO: Add your command update UI handler code here
  158. pCmdUI->SetCheck(m_picBar.IsWindowVisible());
  159. }
  160. void CMainFrame::OnTimer(UINT nIDEvent)
  161. {
  162. // TODO: Add your message handler code here and/or call default
  163. static int iconIndex = 1;
  164. if(nIDEvent == WM_ICONALT){
  165. SetClassLong(m_hWnd, GCL_HICON, (LONG)m_icons[iconIndex]);
  166. iconIndex = (++iconIndex) % 5;
  167. }
  168. CFrameWnd::OnTimer(nIDEvent);
  169. }