MAINFRM.CPP
Upload User: nthssl
Upload Date: 2022-04-05
Package Size: 25357k
Code Size: 12k
Category:

OpenCV

Development Platform:

Visual C++

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3. #include "stdafx.h"
  4. #include "3DEditor.h"
  5. #include "MainFrm.h"
  6. #include "Splash.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. CStatusBar *statbar=0;
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CMainFrame
  15. IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
  16. BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
  17. //{{AFX_MSG_MAP(CMainFrame)
  18. ON_WM_CREATE()
  19. ON_COMMAND(ID_VIEW_TBIMPEXP, OnViewTbimpexp)
  20. ON_UPDATE_COMMAND_UI(ID_VIEW_TBIMPEXP, OnUpdateViewTbimpexp)
  21. ON_COMMAND(ID_VIEW_TBLIGHT, OnViewTblight)
  22. ON_UPDATE_COMMAND_UI(ID_VIEW_TBLIGHT, OnUpdateViewTblight)
  23. ON_COMMAND(ID_VIEW_TBSELECT, OnViewTbselect)
  24. ON_UPDATE_COMMAND_UI(ID_VIEW_TBSELECT, OnUpdateViewTbselect)
  25. ON_COMMAND(ID_VIEW_TBVIEW, OnViewTbview)
  26. ON_UPDATE_COMMAND_UI(ID_VIEW_TBVIEW, OnUpdateViewTbview)
  27. ON_WM_DESTROY()
  28. ON_COMMAND(ID_VIEW_FULL_SCREEN, OnViewFullScreen)
  29. ON_UPDATE_COMMAND_UI(ID_VIEW_FULL_SCREEN, OnUpdateViewFullScreen)
  30. ON_COMMAND(ID_VIEW_TBCAPTURE, OnViewTbcapture)
  31. ON_UPDATE_COMMAND_UI(ID_VIEW_TBCAPTURE, OnUpdateViewTbcapture)
  32. //}}AFX_MSG_MAP
  33. END_MESSAGE_MAP()
  34. static UINT indicators[] =
  35. {
  36. ID_SEPARATOR,           // status line indicator
  37. ID_INDICATOR_CAPS,
  38. ID_INDICATOR_NUM,
  39. ID_INDICATOR_SCRL,
  40. };
  41. /////////////////////////////////////////////////////////////////////////////
  42. // CMainFrame construction/destruction
  43. CMainFrame::CMainFrame()
  44. {
  45. // TODO: add member initialization code here
  46. m_pToolBar_impexp=0;
  47. m_pToolBar_light=0;
  48. m_pToolBar_selectmode=0;
  49. m_pToolBar_viewmode=0;
  50. m_pToolBar_capture=0;
  51. m_bFullScreenMode=false;
  52. }
  53. CMainFrame::~CMainFrame()
  54. {
  55. }
  56. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  57. {
  58. if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
  59. return -1;
  60. if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
  61. | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
  62. !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
  63. {
  64. TRACE0("Failed to create toolbarn");
  65. return -1;      // fail to create
  66. }
  67. if (!m_wndStatusBar.Create(this) ||
  68. !m_wndStatusBar.SetIndicators(indicators,
  69.   sizeof(indicators)/sizeof(UINT)))
  70. {
  71. TRACE0("Failed to create status barn");
  72. return -1;      // fail to create
  73. }
  74. statbar=&m_wndStatusBar;
  75. // TODO: Delete these three lines if you don't want the toolbar to
  76. //  be dockable
  77. m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
  78. EnableDocking(CBRS_ALIGN_ANY);
  79. DockControlBar(&m_wndToolBar);
  80. // CG: The following line was added by the Splash Screen component. CSplashWnd::ShowSplashScreen(this);
  81. return 0;
  82. }
  83. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  84. {
  85. if( !CMDIFrameWnd::PreCreateWindow(cs) )
  86. return FALSE;
  87. // TODO: Modify the Window class or styles here by modifying
  88. //  the CREATESTRUCT cs
  89. cs.cy = ::GetSystemMetrics(SM_CYSCREEN) ; 
  90.     cs.cx = ::GetSystemMetrics(SM_CXSCREEN) ;   
  91. return TRUE;
  92. }
  93. /////////////////////////////////////////////////////////////////////////////
  94. // CMainFrame diagnostics
  95. #ifdef _DEBUG
  96. void CMainFrame::AssertValid() const
  97. {
  98. CMDIFrameWnd::AssertValid();
  99. }
  100. void CMainFrame::Dump(CDumpContext& dc) const
  101. {
  102. CMDIFrameWnd::Dump(dc);
  103. }
  104. #endif //_DEBUG
  105. /////////////////////////////////////////////////////////////////////////////
  106. // CMainFrame message handlers
  107. void CMainFrame::OnViewTbimpexp() 
  108. {
  109. // TODO: Add your command handler code here
  110. if (0 == m_pToolBar_impexp)
  111. {
  112. m_pToolBar_impexp = new CToolBar;
  113. CString ErrMsg;
  114. if (0 == m_pToolBar_impexp->CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
  115. | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC))
  116. {
  117. ErrMsg.LoadString(IDS_TOOLBAR_CREATE);
  118. ::AfxMessageBox(ErrMsg);
  119. return;
  120. }
  121. if (0 == m_pToolBar_impexp->LoadToolBar(IDR_TOOLBAR_IMPEXP))
  122. {
  123. ErrMsg.LoadString(IDS_TOOLBAR_LOAD);
  124. ::AfxMessageBox(ErrMsg);
  125. return;
  126. }
  127. m_pToolBar_impexp->EnableDocking(CBRS_ALIGN_ANY);
  128. DockControlBar(m_pToolBar_impexp);
  129. m_pToolBar_impexp->SetWindowText(_T("输入/输出"));
  130. }
  131. else
  132. // If the window is visible, hide it.
  133. if(m_pToolBar_impexp->IsWindowVisible() == TRUE)
  134. ShowControlBar(m_pToolBar_impexp, FALSE, FALSE);
  135. else
  136. // Otherwise, show it.
  137. ShowControlBar(m_pToolBar_impexp, TRUE, FALSE);
  138. }
  139. void CMainFrame::OnUpdateViewTbimpexp(CCmdUI* pCmdUI) 
  140. {
  141. // TODO: Add your command update UI handler code here
  142. if (0 == m_pToolBar_impexp)
  143. pCmdUI->SetCheck(FALSE);
  144. else
  145. if(m_pToolBar_impexp->IsWindowVisible() == TRUE)
  146. pCmdUI->SetCheck(TRUE);
  147. else
  148. pCmdUI->SetCheck(FALSE);
  149. }
  150. void CMainFrame::OnViewTblight() 
  151. {
  152. // TODO: Add your command handler code here
  153. if (0 == m_pToolBar_light)
  154. {
  155. m_pToolBar_light = new CToolBar;
  156. CString ErrMsg;
  157. if (0 == m_pToolBar_light->CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
  158. | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC))
  159. {
  160. ErrMsg.LoadString(IDS_TOOLBAR_CREATE);
  161. ::AfxMessageBox(ErrMsg);
  162. return;
  163. }
  164. if (0 == m_pToolBar_light->LoadToolBar(IDR_TOOLBAR_LIGHT))
  165. {
  166. ErrMsg.LoadString(IDS_TOOLBAR_LOAD);
  167. ::AfxMessageBox(ErrMsg);
  168. return;
  169. }
  170. m_pToolBar_light->EnableDocking(CBRS_ALIGN_ANY);
  171. DockControlBar(m_pToolBar_light);
  172. m_pToolBar_light->SetWindowText(_T("光照"));
  173. }
  174. else
  175. // If the window is visible, hide it.
  176. if(m_pToolBar_light->IsWindowVisible() == TRUE)
  177. ShowControlBar(m_pToolBar_light, FALSE, FALSE);
  178. else
  179. // Otherwise, show it.
  180. ShowControlBar(m_pToolBar_light, TRUE, FALSE);
  181. }
  182. void CMainFrame::OnUpdateViewTblight(CCmdUI* pCmdUI) 
  183. {
  184. // TODO: Add your command update UI handler code here
  185. if (0 == m_pToolBar_light)
  186. pCmdUI->SetCheck(FALSE);
  187. else
  188. if(m_pToolBar_light->IsWindowVisible() == TRUE)
  189. pCmdUI->SetCheck(TRUE);
  190. else
  191. pCmdUI->SetCheck(FALSE);
  192. }
  193. void CMainFrame::OnViewTbselect() 
  194. {
  195. // TODO: Add your command handler code here
  196. if (0 == m_pToolBar_selectmode)
  197. {
  198. m_pToolBar_selectmode = new CToolBar;
  199. CString ErrMsg;
  200. if (0 == m_pToolBar_selectmode->CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
  201. | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC))
  202. {
  203. ErrMsg.LoadString(IDS_TOOLBAR_CREATE);
  204. ::AfxMessageBox(ErrMsg);
  205. return;
  206. }
  207. if (0 == m_pToolBar_selectmode->LoadToolBar(IDR_TOOLBAR_SELECTMODE))
  208. {
  209. ErrMsg.LoadString(IDS_TOOLBAR_LOAD);
  210. ::AfxMessageBox(ErrMsg);
  211. return;
  212. }
  213. m_pToolBar_selectmode->EnableDocking(CBRS_ALIGN_ANY);
  214. DockControlBar(m_pToolBar_selectmode);
  215. m_pToolBar_selectmode->SetWindowText(_T("选择"));
  216. }
  217. else
  218. // If the window is visible, hide it.
  219. if(m_pToolBar_selectmode->IsWindowVisible() == TRUE)
  220. ShowControlBar(m_pToolBar_selectmode, FALSE, FALSE);
  221. else
  222. // Otherwise, show it.
  223. ShowControlBar(m_pToolBar_selectmode, TRUE, FALSE);
  224. }
  225. void CMainFrame::OnUpdateViewTbselect(CCmdUI* pCmdUI) 
  226. {
  227. // TODO: Add your command update UI handler code here
  228. if (0 == m_pToolBar_selectmode)
  229. pCmdUI->SetCheck(FALSE);
  230. else
  231. if(m_pToolBar_selectmode->IsWindowVisible() == TRUE)
  232. pCmdUI->SetCheck(TRUE);
  233. else
  234. pCmdUI->SetCheck(FALSE);
  235. }
  236. void CMainFrame::OnViewTbview() 
  237. {
  238. // TODO: Add your command handler code here
  239. if (0 == m_pToolBar_viewmode)
  240. {
  241. m_pToolBar_viewmode = new CToolBar;
  242. CString ErrMsg;
  243. if (0 == m_pToolBar_viewmode->CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
  244. | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC))
  245. {
  246. ErrMsg.LoadString(IDS_TOOLBAR_CREATE);
  247. ::AfxMessageBox(ErrMsg);
  248. return;
  249. }
  250. if (0 == m_pToolBar_viewmode->LoadToolBar(IDR_TOOLBAR_VIEWMODE))
  251. {
  252. ErrMsg.LoadString(IDS_TOOLBAR_LOAD);
  253. ::AfxMessageBox(ErrMsg);
  254. return;
  255. }
  256. m_pToolBar_viewmode->EnableDocking(CBRS_ALIGN_ANY);
  257. DockControlBar(m_pToolBar_viewmode);
  258. m_pToolBar_viewmode->SetWindowText(_T("显示"));
  259. }
  260. else
  261. // If the window is visible, hide it.
  262. if(m_pToolBar_viewmode->IsWindowVisible() == TRUE)
  263. ShowControlBar(m_pToolBar_viewmode, FALSE, FALSE);
  264. else
  265. // Otherwise, show it.
  266. ShowControlBar(m_pToolBar_viewmode, TRUE, FALSE);
  267. }
  268. void CMainFrame::OnUpdateViewTbview(CCmdUI* pCmdUI) 
  269. {
  270. // TODO: Add your command update UI handler code here
  271. if (0 == m_pToolBar_viewmode)
  272. pCmdUI->SetCheck(FALSE);
  273. else
  274. if(m_pToolBar_viewmode->IsWindowVisible() == TRUE)
  275. pCmdUI->SetCheck(TRUE);
  276. else
  277. pCmdUI->SetCheck(FALSE);
  278. }
  279. void CMainFrame::OnDestroy() 
  280. {
  281. CMDIFrameWnd::OnDestroy();
  282. // TODO: Add your message handler code here
  283. if (0 != m_pToolBar_impexp)
  284. {
  285. delete m_pToolBar_impexp;
  286. m_pToolBar_impexp = 0;
  287. }
  288. if (0 != m_pToolBar_light)
  289. {
  290. delete m_pToolBar_light;
  291. m_pToolBar_light = 0;
  292. }
  293. if (0 != m_pToolBar_selectmode)
  294. {
  295. delete m_pToolBar_selectmode;
  296. m_pToolBar_selectmode = 0;
  297. }
  298. if (0 != m_pToolBar_viewmode)
  299. {
  300. delete m_pToolBar_viewmode;
  301. m_pToolBar_viewmode = 0;
  302. }
  303. }
  304. void CMainFrame::OnViewFullScreen() 
  305. {
  306. // TODO: Add your command handler code here
  307. if(m_bFullScreenMode)
  308. FullScreenModeOff();
  309. else FullScreenModeOn();
  310. }
  311. void CMainFrame::OnUpdateViewFullScreen(CCmdUI* pCmdUI) 
  312. {
  313. // TODO: Add your command update UI handler code here
  314. pCmdUI->SetCheck(m_bFullScreenMode);
  315. }
  316. void CMainFrame::FullScreenModeOn()
  317. {
  318. // 获取当前活动文档的窗口
  319. CMDIChildWnd* pChild=MDIGetActive();
  320. if(!pChild) return;
  321. m_bToolBarWasVisible=(m_wndToolBar.IsWindowVisible()!=0);
  322. m_wndToolBar.ShowWindow(SW_HIDE);
  323. m_bStatusBarWasVisible=(m_wndStatusBar.IsWindowVisible()!=0);
  324. m_wndStatusBar.ShowWindow(SW_HIDE);
  325. // 保存主窗口和子窗口的位置
  326. GetWindowRect(&m_mainRect);
  327. // 移走主窗口的标题
  328. LONG style=::GetWindowLong(m_hWnd,GWL_STYLE);
  329. style&=~WS_CAPTION;
  330. ::SetWindowLong(m_hWnd,GWL_STYLE,style);
  331. int screenx=GetSystemMetrics(SM_CXSCREEN);
  332. int screeny=GetSystemMetrics(SM_CYSCREEN);
  333. // 设置窗口位置
  334. SetWindowPos(NULL,0,0,screenx,screeny,SWP_NOZORDER);
  335. style=::GetWindowLong(pChild->m_hWnd,GWL_STYLE);
  336. m_bChildMax=(style & WS_MAXIMIZE)?true:false;
  337. // 保存最初的菜单,并设置菜单为NULL
  338.     ASSERT(m_OrgMenu.GetSafeHmenu()==NULL);
  339.     CMenu* pOldMenu=GetMenu();
  340.     m_OrgMenu.Attach(pOldMenu->Detach());
  341.     SetMenu((CMenu*)NULL);
  342. // 最大化子窗口
  343. this->ShowWindow (SW_SHOWMAXIMIZED);
  344. style=::GetWindowLong(pChild->m_hWnd,GWL_STYLE);
  345. style&=~WS_CAPTION;
  346. ::SetWindowLong(pChild->m_hWnd,GWL_STYLE,style);
  347. pChild->ShowWindow(SW_SHOWMAXIMIZED);
  348. m_bFullScreenMode=true;
  349. }
  350. void CMainFrame::FullScreenModeOff()
  351. {
  352. ASSERT(m_OrgMenu.GetSafeHmenu()!=NULL);
  353.     SetMenu(&m_OrgMenu);
  354.     m_OrgMenu.Detach();
  355. LONG style=::GetWindowLong(m_hWnd,GWL_STYLE);
  356. style|=WS_CAPTION;
  357. ::SetWindowLong(m_hWnd,GWL_STYLE,style);
  358. if(m_bToolBarWasVisible)
  359. m_wndToolBar.ShowWindow(SW_SHOW);
  360. if(m_bStatusBarWasVisible)
  361. m_wndStatusBar.ShowWindow(SW_SHOW);
  362. MoveWindow(&m_mainRect);
  363. RecalcLayout();
  364. CMDIChildWnd* pChild=MDIGetActive();
  365. style=::GetWindowLong(pChild->m_hWnd,GWL_STYLE);
  366. style|=WS_CAPTION;
  367. ::SetWindowLong(pChild->m_hWnd,GWL_STYLE,style);
  368. if(pChild){
  369. if(m_bChildMax)
  370. MDIMaximize(pChild);
  371. else MDIRestore(pChild);
  372. }
  373. m_bFullScreenMode=false;
  374. }
  375. void CMainFrame::OnViewTbcapture() 
  376. {
  377. // TODO: Add your command handler code here
  378. if (0 == m_pToolBar_capture)
  379. {
  380. m_pToolBar_capture = new CToolBar;
  381. CString ErrMsg;
  382. if (0 == m_pToolBar_capture->CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
  383. | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC))
  384. {
  385. ErrMsg.LoadString(IDS_TOOLBAR_CREATE);
  386. ::AfxMessageBox(ErrMsg);
  387. return;
  388. }
  389. if (0 == m_pToolBar_capture->LoadToolBar(IDR_TOOLBAR_CAPTURE))
  390. {
  391. ErrMsg.LoadString(IDS_TOOLBAR_LOAD);
  392. ::AfxMessageBox(ErrMsg);
  393. return;
  394. }
  395. m_pToolBar_capture->EnableDocking(CBRS_ALIGN_ANY);
  396. DockControlBar(m_pToolBar_capture);
  397. m_pToolBar_capture->SetWindowText(_T("录制"));
  398. }
  399. else
  400. // If the window is visible, hide it.
  401. if(m_pToolBar_capture->IsWindowVisible() == TRUE)
  402. ShowControlBar(m_pToolBar_capture, FALSE, FALSE);
  403. else
  404. // Otherwise, show it.
  405. ShowControlBar(m_pToolBar_capture, TRUE, FALSE);
  406. }
  407. void CMainFrame::OnUpdateViewTbcapture(CCmdUI* pCmdUI) 
  408. {
  409. // TODO: Add your command update UI handler code here
  410. if (0 == m_pToolBar_capture)
  411. pCmdUI->SetCheck(FALSE);
  412. else
  413. if(m_pToolBar_capture->IsWindowVisible() == TRUE)
  414. pCmdUI->SetCheck(TRUE);
  415. else
  416. pCmdUI->SetCheck(FALSE);
  417. }