MainFrm.cpp
上传用户:ckg1000
上传日期:2013-01-26
资源大小:630k
文件大小:15k
源码类别:

CAD

开发平台:

Visual C++

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3. #include "stdafx.h"
  4. #include "CAD2006.h"
  5. #include "MainFrm.h"
  6. #include "NewDialogBar.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CMainFrame
  14. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  15. IMPLEMENT_MENUXP(CMainFrame, CFrameWnd);
  16. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  17. //{{AFX_MSG_MAP(CMainFrame)
  18. ON_WM_CREATE()
  19. ON_WM_TIMER()
  20. ON_WM_CLOSE()
  21. ON_COMMAND(ID_REALLINE, OnRealline)
  22. ON_COMMAND(ID_BROKENLINE, OnBrokenline)
  23. ON_COMMAND(ID_TRIGON, OnTrigon)
  24. ON_COMMAND(ID_RECT, OnRect)
  25. ON_COMMAND(ID_POLYGON, OnPolygon)
  26. ON_COMMAND(ID_ROUND, OnRound)
  27. ON_COMMAND(ID_ELLIPSE, OnEllipse)
  28. ON_COMMAND(ID_ARC, OnArc)
  29. ON_COMMAND(IDD_LINE, OnLine)
  30. ON_COMMAND(IDD_FOLD_LINE, OnFoldLine)
  31. ON_COMMAND(IDD_ANGLE_LINE, OnAngleLine)
  32. ON_COMMAND(ID_COLORFOR, OnColorfor)
  33. ON_COMMAND(ID_COLORBACK, OnColorback)
  34. ON_UPDATE_COMMAND_UI(ID_REALLINE, OnUpdateRealline)
  35. ON_UPDATE_COMMAND_UI(ID_BROKENLINE, OnUpdateBrokenline)
  36. ON_UPDATE_COMMAND_UI(IDD_LINE, OnUpdateLine)
  37. ON_UPDATE_COMMAND_UI(IDD_FOLD_LINE, OnUpdateFoldLine)
  38. ON_UPDATE_COMMAND_UI(IDD_ANGLE_LINE, OnUpdateAngleLine)
  39. ON_COMMAND(ID_DOTLINE, OnDotline)
  40. ON_UPDATE_COMMAND_UI(ID_DOTLINE, OnUpdateDotline)
  41. ON_COMMAND(ID_TWOLINE, OnTwoline)
  42. ON_UPDATE_COMMAND_UI(ID_TWOLINE, OnUpdateTwoline)
  43. ON_UPDATE_COMMAND_UI(ID_ROUND, OnUpdateRound)
  44. ON_UPDATE_COMMAND_UI(ID_ELLIPSE, OnUpdateEllipse)
  45. ON_UPDATE_COMMAND_UI(ID_ARC, OnUpdateArc)
  46. ON_COMMAND(ID_NUM1, OnNum1)
  47. ON_UPDATE_COMMAND_UI(ID_NUM1, OnUpdateNum1)
  48. ON_COMMAND(ID_NUM2, OnNum2)
  49. ON_UPDATE_COMMAND_UI(ID_NUM2, OnUpdateNum2)
  50. ON_COMMAND(ID_NUM3, OnNum3)
  51. ON_UPDATE_COMMAND_UI(ID_NUM3, OnUpdateNum3)
  52. ON_COMMAND(ID_NUM4, OnNum4)
  53. ON_UPDATE_COMMAND_UI(ID_NUM4, OnUpdateNum4)
  54. ON_COMMAND(ID_NUM5, OnNum5)
  55. ON_UPDATE_COMMAND_UI(ID_NUM5, OnUpdateNum5)
  56. ON_COMMAND(ID_NUM6, OnNum6)
  57. ON_UPDATE_COMMAND_UI(ID_NUM6, OnUpdateNum6)
  58. ON_COMMAND(ID_NUM7, OnNum7)
  59. ON_UPDATE_COMMAND_UI(ID_NUM7, OnUpdateNum7)
  60. ON_MENUXP_MESSAGES()
  61. //}}AFX_MSG_MAP
  62. END_MESSAGE_MAP()
  63. //ON_MENUXP_MESSAGES()
  64. static UINT indicators[] =
  65. {
  66. ID_SEPARATOR,           // status line indicator
  67. ID_SEPARATOR,
  68. ID_INDICATOR_EXT,
  69. ID_INDICATOR_CAPS,
  70. // ID_INDICATOR_NUM,
  71. ID_INDICATOR_SCRL,
  72. };
  73. /////////////////////////////////////////////////////////////////////////////
  74. // CMainFrame construction/destruction
  75. CMainFrame::CMainFrame()
  76. {
  77. // TODO: add member initialization code here
  78. m_style = realline;
  79. m_linewidth = one;
  80. m_shape = new CShape;
  81. }
  82. CMainFrame::~CMainFrame()
  83. {
  84. delete m_shape;
  85. }
  86. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  87. {
  88. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  89. return -1;
  90. ::AnimateWindow(GetSafeHwnd(),1000,AW_BLEND);
  91. CMenuXP::UpdateMenuBar(this);
  92. CMenuXP::SetXPLookNFeel (this);
  93. CMenu *m_menu = this->GetActiveFrame()->GetMenu();
  94. int i = m_menu->EnableMenuItem(32775,MF_ENABLED|MF_BYPOSITION);
  95. m_menu->EnableMenuItem(32776,MF_ENABLED|MF_BYCOMMAND);
  96. m_menu->EnableMenuItem(32777,MF_DISABLED);
  97. if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
  98. | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
  99. !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
  100. {
  101. TRACE0("Failed to create toolbarn");
  102. return -1;      // fail to create
  103. }
  104. m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
  105. EnableDocking(CBRS_ALIGN_ANY);
  106. DockControlBar(&m_wndToolBar);
  107. if(!m_wndDialogBar.Create(this,IDD_DIALOGBAR,CBRS_LEFT|CBRS_TOOLTIPS|CBRS_FLYBY,103))
  108. {
  109. ::AfxMessageBox("Failed to create DialogBar!");
  110. return -1;
  111. }
  112. m_wndDialogBar.SetBarStyle(m_wndDialogBar.GetBarStyle()|CBRS_TOOLTIPS|CBRS_FLYBY);
  113. m_wndDialogBar.EnableDocking(CBRS_ALIGN_ANY);
  114. //EnableDocking(CBRS_ALIGN_ANY);
  115. //DockControlBar(&m_wndDialogBar);
  116. m_wndDialogBar.InitDialogBar();
  117. if(!m_wndTrigon.Create(this,IDD_DIALOGBAR_TRIGON,CBRS_TOP|CBRS_TOOLTIPS|CBRS_FLYBY,104))
  118. {
  119. ::AfxMessageBox("Failed to create DialogBar!");
  120. return -1;
  121. }
  122. m_wndTrigon.InitDialogBar();
  123. if (!m_wndcoolbar.Create(_T("我的控制条"),this,CSize(100,80),TRUE,124))
  124. TRACE0("Failed to create mybarn");
  125. return -1; 
  126. }
  127. m_wndcoolbar.SetBarStyle(m_wndcoolbar.GetBarStyle() | CBRS_TOOLTIPS |
  128. CBRS_FLYBY | CBRS_SIZE_DYNAMIC|CBRS_BOTTOM);
  129. m_wndedit.Create(WS_VSCROLL|WS_CHILD|WS_VISIBLE|ES_AUTOVSCROLL|
  130. ES_MULTILINE|ES_WANTRETURN,CRect(0,0,0,0),&m_wndcoolbar,101);
  131. m_wndedit.ModifyStyleEx(0,WS_EX_CLIENTEDGE);
  132. m_wndcoolbar.EnableDocking(CBRS_ALIGN_ANY);
  133. DockControlBar(&m_wndcoolbar, AFX_IDW_DOCKBAR_BOTTOM);
  134. if (!m_wndStatusBar.Create(this) ||
  135. !m_wndStatusBar.SetIndicators(indicators,
  136.   sizeof(indicators)/sizeof(UINT)))
  137. {
  138. TRACE0("Failed to create status barn");
  139. return -1;      // fail to create
  140. }
  141. m_wndStatusBar.SetBarStyle(m_wndStatusBar.GetBarStyle()|CBRS_BOTTOM);
  142. m_wndStatusBar.SetPaneInfo(3,ID_SEPARATOR,SBPS_NORMAL,50);
  143. m_wndStatusBar.SetPaneInfo(2,ID_INDICATOR_EXT,SBPS_NORMAL,30);
  144. m_wndStatusBar.SetPaneInfo(1,ID_INDICATOR_EXT,SBPS_NORMAL,500);
  145. m_wndStatusBar.SetPaneInfo(0,ID_SEPARATOR,SBPS_NORMAL,::GetSystemMetrics(SM_CXSCREEN) - 630);
  146. // TODO: Delete these three lines if you don't want the toolbar to
  147. //  be dockable
  148. /* int index = 0;
  149. RECT rect;
  150. while(m_wndToolBar.GetItemID(index) != ID_BUTTON_COMBOBOX)
  151. {
  152. index++;
  153. }
  154. m_wndToolBar.SetButtonInfo(index,ID_BUTTON_COMBOBOX,TBBS_SEPARATOR,80);
  155. m_wndToolBar.GetItemRect(index,&rect);
  156. rect.top += 5;
  157. rect.bottom += 200;
  158. if(!m_wndToolBar.m_wndComboBox.Create(WS_CHILD|WS_VISIBLE |CBS_AUTOHSCROLL|CBS_DROPDOWNLIST | 
  159. CBS_HASSTRINGS,rect,&m_wndToolBar,ID_BUTTON_COMBOBOX))
  160. {
  161. TRACE0("Failed to create toolbarn");
  162. return -1;      // fail to create
  163. }
  164. m_wndToolBar.m_wndComboBox.ShowWindow(SW_SHOW);
  165. m_wndToolBar.m_wndComboBox.AddString("1sdf");
  166. m_wndToolBar.m_wndComboBox.AddString("2sdf");
  167. m_wndToolBar.m_wndComboBox.AddString("3sdf");
  168. m_wndToolBar.m_wndComboBox.AddString("4sdf");
  169. m_wndToolBar.m_wndComboBox.SetCurSel(2);*/
  170. SetTimer(1,1,NULL);
  171. SetTimer(2,100,NULL);
  172. return 0;
  173. }
  174. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  175. {
  176. if( !CFrameWnd::PreCreateWindow(cs) )
  177. return FALSE;
  178. // TODO: Modify the Window class or styles here by modifying
  179. //  the CREATESTRUCT cs
  180. return TRUE;
  181. }
  182. /////////////////////////////////////////////////////////////////////////////
  183. // CMainFrame diagnostics
  184. #ifdef _DEBUG
  185. void CMainFrame::AssertValid() const
  186. {
  187. CFrameWnd::AssertValid();
  188. }
  189. void CMainFrame::Dump(CDumpContext& dc) const
  190. {
  191. CFrameWnd::Dump(dc);
  192. }
  193. #endif //_DEBUG
  194. /////////////////////////////////////////////////////////////////////////////
  195. // CMainFrame message handlers
  196. BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) 
  197. {
  198. // TODO: Add your specialized code here and/or call the base class
  199. if(m_wndDialogBar.OnCmdMsg(nID,nCode,pExtra,pHandlerInfo))
  200. return true;
  201. return CFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
  202. }
  203. void CMainFrame::OnTimer(UINT nIDEvent) 
  204. {
  205. // TODO: Add your message handler code here and/or call default
  206. switch( nIDEvent )
  207. {
  208. case 1:
  209. {
  210. CString Timeinfor;
  211. CTime Time = CTime::GetCurrentTime();
  212. Timeinfor.Format("%02d:%02d:%02d",Time.GetHour(),Time.GetMinute(),Time.GetSecond());
  213. m_wndStatusBar.SetPaneText(3,Timeinfor);
  214. break;
  215. }
  216. case 2:
  217. {
  218. static int index = 0;
  219. if( index > 80 )
  220. {
  221. index = 0;
  222. }
  223. index += 2;
  224. CString m_info = "  欢迎使用CAD2006试用版,如有问题,请不吝指教!作者: 汤红波 陆立新 孙永滔 邓萌 徐讷讷";
  225. m_wndStatusBar.SetPaneText(1,m_info.Left(index));
  226. }
  227. }
  228. CFrameWnd::OnTimer(nIDEvent);
  229. }
  230. BOOL CMainFrame::LoadFrame(UINT nIDResource, DWORD dwDefaultStyle, CWnd* pParentWnd, CCreateContext* pContext) 
  231. {
  232. // TODO: Add your specialized code here and/or call the base class
  233. return CFrameWnd::LoadFrame(nIDResource, dwDefaultStyle, pParentWnd, pContext);
  234. }
  235. void CMainFrame::OnClose()
  236. {
  237. // TODO: Add your message handler code here and/or call default
  238. if( ::AfxMessageBox("您是否要退出?",MB_OKCANCEL) == IDOK )
  239. {
  240. ::AnimateWindow(GetSafeHwnd(),1000,AW_HIDE|AW_BLEND);
  241. CFrameWnd::OnClose();
  242. }
  243. }
  244. void CMainFrame::OnRealline() 
  245. {
  246. // TODO: Add your command handler code here
  247. this->m_style = realline;
  248. m_shape->SetBorderStyle(PS_SOLID);
  249. m_wndTrigon.m_ComMode.SetCurSel(2);
  250. }
  251. void CMainFrame::OnBrokenline() 
  252. {
  253. // TODO: Add your command handler code here
  254. this->m_style = brokenline;
  255. m_shape->SetBorderStyle(PS_DASH);
  256. m_wndTrigon.m_ComMode.SetCurSel(3);
  257. }
  258. void CMainFrame::OnTrigon() 
  259. {
  260. // TODO: Add your command handler code here
  261. m_wndDialogBar.OnButtonTrigon();
  262. }
  263. void CMainFrame::OnRect() 
  264. {
  265. // TODO: Add your command handler code here
  266. m_wndDialogBar.OnButtonRect();
  267. }
  268. void CMainFrame::OnPolygon() 
  269. {
  270. // TODO: Add your command handler code here
  271. m_wndDialogBar.OnButtonPolygon();
  272. }
  273. void CMainFrame::OnRound() 
  274. {
  275. // TODO: Add your command handler code here
  276. //this->m_circle = round;
  277. m_wndDialogBar.OnButtonCircle();
  278. }
  279. void CMainFrame::OnEllipse() 
  280. {
  281. // TODO: Add your command handler code here
  282. //this->m_circle = ellips;
  283. m_wndDialogBar.OnButtonEllipse();
  284. }
  285. void CMainFrame::OnArc() 
  286. {
  287. // TODO: Add your command handler code here
  288. // this->m_circle = roundmeter;
  289. m_wndDialogBar.OnButtonCirclemeter();
  290. }
  291. void CMainFrame::OnLine() 
  292. {
  293. // TODO: Add your command handler code here
  294. // this->m_line = beeline;
  295. m_wndDialogBar.OnButtonLine();
  296. }
  297. void CMainFrame::OnFoldLine() 
  298. {
  299. // TODO: Add your command handler code here
  300. // this->m_line = foldline;
  301. m_wndDialogBar.OnButtonFoldline();
  302. }
  303. void CMainFrame::OnAngleLine() 
  304. {
  305. // TODO: Add your command handler code here
  306. // this->m_line = angleline;
  307. m_wndDialogBar.OnButtonAngleline();
  308. }
  309. void CMainFrame::OnColorfor() 
  310. {
  311. // TODO: Add your command handler code here
  312. this->m_wndDialogBar.OnClickLabelForbk();
  313. }
  314. void CMainFrame::OnColorback() 
  315. {
  316. // TODO: Add your command handler code here
  317. this->m_wndDialogBar.OnClickLabelBackbk();
  318. }
  319. void CMainFrame::OnUpdateRealline(CCmdUI* pCmdUI) 
  320. {
  321. // TODO: Add your command update UI handler code here
  322. SetLineStyle(pCmdUI,realline);
  323. }
  324. void CMainFrame::OnUpdateBrokenline(CCmdUI* pCmdUI) 
  325. {
  326. // TODO: Add your command update UI handler code here
  327. SetLineStyle(pCmdUI,brokenline);
  328. }
  329. void CMainFrame::OnUpdateLine(CCmdUI* pCmdUI) 
  330. {
  331. // TODO: Add your command update UI handler code here
  332. SetButtonCheck(pCmdUI,line);
  333. }
  334. void CMainFrame::OnUpdateFoldLine(CCmdUI* pCmdUI) 
  335. {
  336. // TODO: Add your command update UI handler code here
  337. SetButtonCheck(pCmdUI,linedown);
  338. }
  339. void CMainFrame::OnUpdateAngleLine(CCmdUI* pCmdUI) 
  340. {
  341. // TODO: Add your command update UI handler code here
  342. SetButtonCheck(pCmdUI,lineangle);
  343. }
  344. void CMainFrame::OnDotline() 
  345. {
  346. // TODO: Add your command handler code here
  347. this->m_style = dotline;
  348. m_shape->SetBorderStyle(PS_DOT);
  349. m_wndTrigon.m_ComMode.SetCurSel(0);
  350. }
  351. void CMainFrame::OnUpdateDotline(CCmdUI* pCmdUI) 
  352. {
  353. // TODO: Add your command update UI handler code here
  354. SetLineStyle(pCmdUI,dotline);
  355. }
  356. void CMainFrame::OnTwoline() 
  357. {
  358. // TODO: Add your command handler code here
  359. this->m_style = twoline;
  360. m_shape->SetBorderStyle(PS_DASHDOT);
  361. m_wndTrigon.m_ComMode.SetCurSel(1);
  362. }
  363. void CMainFrame::OnUpdateTwoline(CCmdUI* pCmdUI) 
  364. {
  365. // TODO: Add your command update UI handler code here
  366. SetLineStyle(pCmdUI,twoline);
  367. }
  368. void CMainFrame::OnUpdateRound(CCmdUI* pCmdUI) 
  369. {
  370. // TODO: Add your command update UI handler code here
  371. SetButtonCheck(pCmdUI,circle);
  372. }
  373. void CMainFrame::OnUpdateEllipse(CCmdUI* pCmdUI) 
  374. {
  375. // TODO: Add your command update UI handler code here
  376. SetButtonCheck(pCmdUI,ellipse);
  377. }
  378. void CMainFrame::OnUpdateArc(CCmdUI* pCmdUI) 
  379. {
  380. // TODO: Add your command update UI handler code here
  381. SetButtonCheck(pCmdUI,circlemater);
  382. }
  383. void CMainFrame::OnNum1() 
  384. {
  385. // TODO: Add your command handler code here
  386. m_linewidth = one;
  387. m_shape->SetBorderWidth(1);
  388. m_wndTrigon.m_ComSize.SetCurSel(0);
  389. }
  390. void CMainFrame::OnUpdateNum1(CCmdUI* pCmdUI) 
  391. {
  392. // TODO: Add your command update UI handler code here
  393. SetNumCheck(pCmdUI,one);
  394. }
  395. void CMainFrame::OnNum2() 
  396. {
  397. // TODO: Add your command handler code here
  398. m_linewidth = two;
  399. m_shape->SetBorderWidth(2);
  400. m_wndTrigon.m_ComSize.SetCurSel(1);
  401. }
  402. void CMainFrame::OnUpdateNum2(CCmdUI* pCmdUI) 
  403. {
  404. // TODO: Add your command update UI handler code here
  405. SetNumCheck(pCmdUI,two);
  406. }
  407. void CMainFrame::OnNum3() 
  408. {
  409. // TODO: Add your command handler code here
  410. m_linewidth = three;
  411. m_shape->SetBorderWidth(3);
  412. m_wndTrigon.m_ComSize.SetCurSel(2);
  413. }
  414. void CMainFrame::OnUpdateNum3(CCmdUI* pCmdUI) 
  415. {
  416. // TODO: Add your command update UI handler code here
  417. SetNumCheck(pCmdUI,three);
  418. }
  419. void CMainFrame::OnNum4() 
  420. {
  421. // TODO: Add your command handler code here
  422. m_linewidth = four;
  423. m_shape->SetBorderWidth(4);
  424. m_wndTrigon.m_ComSize.SetCurSel(3);
  425. }
  426. void CMainFrame::OnUpdateNum4(CCmdUI* pCmdUI) 
  427. {
  428. // TODO: Add your command update UI handler code here
  429. SetNumCheck(pCmdUI,four);
  430. }
  431. void CMainFrame::OnNum5() 
  432. {
  433. // TODO: Add your command handler code here
  434. m_linewidth = five;
  435. m_shape->SetBorderWidth(5);
  436. m_wndTrigon.m_ComSize.SetCurSel(4);
  437. }
  438. void CMainFrame::OnUpdateNum5(CCmdUI* pCmdUI) 
  439. {
  440. // TODO: Add your command update UI handler code here
  441. SetNumCheck(pCmdUI,five);
  442. }
  443. void CMainFrame::OnNum6() 
  444. {
  445. // TODO: Add your command handler code here
  446. m_linewidth = six;
  447. m_shape->SetBorderWidth(6);
  448. m_wndTrigon.m_ComSize.SetCurSel(5);
  449. }
  450. void CMainFrame::OnUpdateNum6(CCmdUI* pCmdUI) 
  451. {
  452. // TODO: Add your command update UI handler code here
  453. SetNumCheck(pCmdUI,six);
  454. }
  455. void CMainFrame::OnNum7() 
  456. {
  457. // TODO: Add your command handler code here
  458. m_linewidth = seven;
  459. m_shape->SetBorderWidth(7);
  460. m_wndTrigon.m_ComSize.SetCurSel(6);
  461. }
  462. void CMainFrame::OnUpdateNum7(CCmdUI* pCmdUI) 
  463. {
  464. // TODO: Add your command update UI handler code here
  465. SetNumCheck(pCmdUI,seven);
  466. }
  467. void CMainFrame::SetButtonCheck(CCmdUI *pCmdUI, SHAPE shape)
  468. {
  469. CCAD2006Doc *m_pDoc = (CCAD2006Doc *)this->GetActiveDocument();
  470. if( m_pDoc->m_shape == shape )
  471. {
  472. pCmdUI->SetCheck(true);
  473. }
  474. else
  475. {
  476. pCmdUI->SetCheck(false);
  477. }
  478. }
  479. void CMainFrame::SetNumCheck(CCmdUI *pCmdUI, LINEWIDTH width)
  480. {
  481. if( m_linewidth == width )
  482. {
  483. pCmdUI->SetCheck(true);
  484. }
  485. else
  486. {
  487. pCmdUI->SetCheck(false);
  488. }
  489. }
  490. void CMainFrame::SetLineStyle(CCmdUI *pCmdUI, LINESTYLE style)
  491. {
  492. if( m_style == style )
  493. {
  494. pCmdUI->SetCheck(true);
  495. }
  496. else
  497. {
  498. pCmdUI->SetCheck(false);
  499. }
  500. }