MainFrm.cpp
上传用户:shangwu01
上传日期:2013-04-22
资源大小:707k
文件大小:9k
源码类别:

CAD

开发平台:

Visual C++

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3. #include "stdafx.h"
  4. #include "CAD.h"
  5. #include "MainFrm.h"
  6. #include "CADDoc.h"
  7. #include "DLG_LineWSet.h"
  8. #include "Splash.h"
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CMainFrame
  16. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  17. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  18. //{{AFX_MSG_MAP(CMainFrame)
  19. ON_WM_CREATE()
  20. ON_CBN_SELCHANGE(IDC_COMBO2, OnSelchangeCombo2)
  21. ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1)
  22. ON_CBN_SELCHANGE(IDC_COMBO3, OnSelchangeCombo3)
  23. ON_COMMAND(IDM_VIEW_DRAWBAR, OnViewDrawbar)
  24. ON_UPDATE_COMMAND_UI(IDM_VIEW_DRAWBAR, OnUpdateViewDrawbar)
  25. ON_COMMAND(IDM_VIEW_CATCHBAR, OnViewCatchbar)
  26. ON_UPDATE_COMMAND_UI(IDM_VIEW_CATCHBAR, OnUpdateViewCatchbar)
  27. ON_WM_TIMER()
  28. ON_WM_PAINT()
  29. ON_WM_SHOWWINDOW()
  30. //}}AFX_MSG_MAP
  31. END_MESSAGE_MAP()
  32. static UINT indicators[] =
  33. {
  34. ID_SEPARATOR,           // status line indicator
  35. ID_INDICATOR_CAPS,
  36. ID_INDICATOR_NUM,
  37. ID_INDICATOR_SCRL,
  38. };
  39. /////////////////////////////////////////////////////////////////////////////
  40. // CMainFrame construction/destruction
  41. CMainFrame::CMainFrame()
  42. {
  43. }
  44. CMainFrame::~CMainFrame()
  45. {
  46. }
  47. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  48. {
  49. CSplashWnd::ShowSplashScreen(this);
  50. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  51. return -1;
  52. if (!m_wndToolBar.CreateEx(this) ||
  53. !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
  54. {
  55. TRACE0("Failed to create toolbarn");
  56. return -1;      // fail to create
  57. }
  58. if (!m_wndDrawTool.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE |CBRS_ALIGN_LEFT
  59. | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
  60. !m_wndDrawTool.LoadToolBar(IDR_TOOLBAR1))
  61. {
  62. TRACE0("Failed to create toolbarn");
  63. return -1;      // fail to create
  64. }
  65. if (!m_wndCatchTool.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE |CBRS_ALIGN_BOTTOM
  66. | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
  67. !m_wndCatchTool.LoadToolBar(IDR_TOOLBAR2))
  68. {
  69. TRACE0("Failed to create toolbarn");
  70. return -1;      // fail to create
  71. }
  72. if (!m_wndDlgBar.Create(this, IDR_MAINFRAME, 
  73. CBRS_ALIGN_RIGHT, AFX_IDW_DIALOGBAR))
  74. {
  75. TRACE0("Failed to create dialogbarn");
  76. return -1; // fail to create
  77. }
  78. if (!m_wndReBar.Create(this) ||
  79. !m_wndReBar.AddBar(&m_wndToolBar) ||
  80. !m_wndReBar.AddBar(&m_wndDlgBar))
  81. {
  82. TRACE0("Failed to create rebarn");
  83. return -1;      // fail to create
  84. }
  85. if (!m_wndStatusBar.Create(this) ||
  86. !m_wndStatusBar.SetIndicators(indicators,
  87.   sizeof(indicators)/sizeof(UINT)))
  88. {
  89. TRACE0("Failed to create status barn");
  90. return -1;      // fail to create
  91. }
  92. // TODO: Remove this if you don't want tool tips
  93. m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
  94. CBRS_TOOLTIPS | CBRS_FLYBY);
  95. m_wndDrawTool.EnableDocking(CBRS_ALIGN_ANY);
  96. EnableDocking(CBRS_ALIGN_LEFT);
  97. DockControlBar(&m_wndDrawTool);
  98. m_wndCatchTool.EnableDocking(CBRS_ALIGN_ANY);
  99. EnableDocking(CBRS_ALIGN_BOTTOM);
  100. DockControlBar(&m_wndCatchTool);
  101. // this->ShowWindow(SW_SHOWMAXIMIZED);
  102. SetTimer(1,1000,NULL);
  103. /////////////////////// combobox /////////////////////////////////////////
  104. // ((CComboBox *)m_wndDlgBar.GetDlgItem(IDC_COMBO3))->AddString("");
  105. ((CComboBox *)m_wndDlgBar.GetDlgItem(IDC_COMBO1))->SetCurSel(0);
  106. ((CComboBox *)m_wndDlgBar.GetDlgItem(IDC_COMBO2))->SetCurSel(0);
  107. ((CComboBox *)m_wndDlgBar.GetDlgItem(IDC_COMBO3))->SetCurSel(0);
  108. ///
  109. /* CComboBoxEx *pCombo=(CComboBoxEx *)(m_wndDlgBar.GetDlgItem(IDC_COMBOBOXEX2));
  110. m_imageList.Create(32,16,ILC_MASK,8,4);
  111. CBitmap bitmap;
  112. bitmap.LoadBitmap(IDB_BITMAP1);
  113. m_imageList.Add(&bitmap,RGB(0,0,255));
  114. bitmap.DeleteObject();
  115. bitmap.LoadBitmap(IDB_BITMAP2);
  116. m_imageList.Add(&bitmap,RGB(0,0,255));
  117. bitmap.DeleteObject();
  118. bitmap.LoadBitmap(IDB_BITMAP3);
  119. m_imageList.Add(&bitmap,RGB(0,0,255));
  120. bitmap.DeleteObject();
  121. bitmap.LoadBitmap(IDB_BITMAP4);
  122. m_imageList.Add(&bitmap,RGB(0,0,255));
  123. bitmap.DeleteObject();
  124. pCombo->SetImageList(&m_imageList);
  125. COMBOBOXEXITEM cbi;
  126. cbi.mask=CBEIF_IMAGE|CBEIF_SELECTEDIMAGE|CBEIF_INDENT;
  127. CString strTemp;
  128. int nBitmapCount=0;
  129. for(int nCount=0;nCount<4;nCount++)
  130. {
  131. cbi.iItem=nCount;
  132. cbi.pszText=(LPTSTR)(LPCTSTR)strTemp;
  133. cbi.cchTextMax=256;
  134. pCombo->GetItem(&cbi);
  135. cbi.iImage=nBitmapCount;
  136. cbi.iSelectedImage=nBitmapCount++;
  137. cbi.iIndent=(nCount&0x03);
  138. pCombo->SetItem(&cbi);
  139. }
  140. */
  141. //////////////////////////////////////////////////////////////////////////
  142. // CG: The following line was added by the Splash Screen component.
  143. return 0;
  144. }
  145. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  146. {
  147. if( !CFrameWnd::PreCreateWindow(cs) )
  148. return FALSE;
  149. // TODO: Modify the Window class or styles here by modifying
  150. //  the CREATESTRUCT cs
  151. cs.cy = ::GetSystemMetrics(SM_CYSCREEN); 
  152.     cs.cx = ::GetSystemMetrics(SM_CXSCREEN); 
  153.     cs.y = ::GetSystemMetrics(SM_CYSCREEN); 
  154.     cs.x = ::GetSystemMetrics(SM_CYSCREEN);
  155. cs.lpszClass=AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW,0,0,AfxGetApp()->LoadIcon(IDI_ICON1));
  156. return TRUE;
  157. }
  158. /////////////////////////////////////////////////////////////////////////////
  159. // CMainFrame diagnostics
  160. #ifdef _DEBUG
  161. void CMainFrame::AssertValid() const
  162. {
  163. CFrameWnd::AssertValid();
  164. }
  165. void CMainFrame::Dump(CDumpContext& dc) const
  166. {
  167. CFrameWnd::Dump(dc);
  168. }
  169. #endif //_DEBUG
  170. /////////////////////////////////////////////////////////////////////////////
  171. // CMainFrame message handlers
  172. void CMainFrame::OnSelchangeCombo2() 
  173. {
  174. CCADDoc* pDoc = (CCADDoc*)GetActiveDocument();
  175. if(((CComboBox *)m_wndDlgBar.GetDlgItem(IDC_COMBO2))->GetCurSel()==0)
  176. pDoc->m_line_width=1;
  177. if(((CComboBox *)m_wndDlgBar.GetDlgItem(IDC_COMBO2))->GetCurSel()==1)
  178. pDoc->m_line_width=2;
  179. if(((CComboBox *)m_wndDlgBar.GetDlgItem(IDC_COMBO2))->GetCurSel()==2)
  180. pDoc->m_line_width=3;
  181. if(((CComboBox *)m_wndDlgBar.GetDlgItem(IDC_COMBO2))->GetCurSel()==3)
  182. pDoc->m_line_width=4;
  183. if(((CComboBox *)m_wndDlgBar.GetDlgItem(IDC_COMBO2))->GetCurSel()==4)
  184. {
  185. CDLG_LineWSet dlg;
  186. if(dlg.DoModal()==IDOK)
  187. pDoc->m_line_width=dlg.m_LineSet;
  188. }
  189. }
  190. //DEL void CMainFrame::OnSelchangeComboboxex1() 
  191. //DEL {
  192. //DEL // this->MessageBox("");
  193. //DEL 
  194. //DEL 
  195. //DEL }
  196. //DEL void CMainFrame::OnSelchangeComboboxex2() 
  197. //DEL {
  198. //DEL /* COMBOBOXEXITEM cbi;
  199. //DEL  CString str;
  200. //DEL  CComboBoxEx *pCombo=(CComboBoxEx *)(m_wndDlgBar.GetDlgItem(IDC_COMBOBOXEX2));
  201. //DEL  int nSel=pCombo->GetCurSel();
  202. //DEL  cbi.iItem=nSel;
  203. //DEL  cbi.pszText=(LPTSTR)(LPCTSTR)str;
  204. //DEL  cbi.mask=CBEIF_TEXT;
  205. //DEL  cbi.cchTextMax=str.GetLength();
  206. //DEL  pCombo->GetItem(&cbi);
  207. //DEL  return;*/
  208. //DEL 
  209. //DEL }
  210. void CMainFrame::OnSelchangeCombo1() 
  211. {
  212. CCADDoc* pDoc = (CCADDoc*)GetActiveDocument();
  213. if(((CComboBox *)m_wndDlgBar.GetDlgItem(IDC_COMBO1))->GetCurSel()==0)
  214. pDoc->m_line_style=PS_SOLID;
  215. if(((CComboBox *)m_wndDlgBar.GetDlgItem(IDC_COMBO1))->GetCurSel()==1)
  216. pDoc->m_line_style=PS_DASH;
  217. if(((CComboBox *)m_wndDlgBar.GetDlgItem(IDC_COMBO1))->GetCurSel()==2)
  218. pDoc->m_line_style=PS_DASHDOT;
  219. if(((CComboBox *)m_wndDlgBar.GetDlgItem(IDC_COMBO1))->GetCurSel()==3)
  220. pDoc->m_line_style=PS_DASHDOTDOT;
  221. }
  222. void CMainFrame::OnSelchangeCombo3() 
  223. {
  224. CCADDoc* pDoc = (CCADDoc*)GetActiveDocument();
  225. if(((CComboBox *)m_wndDlgBar.GetDlgItem(IDC_COMBO3))->GetCurSel()==0)
  226. pDoc->m_line_color=RGB(0,0,0);
  227. if(((CComboBox *)m_wndDlgBar.GetDlgItem(IDC_COMBO3))->GetCurSel()==1)
  228. pDoc->m_line_color=RGB(255,0,0);
  229. if(((CComboBox *)m_wndDlgBar.GetDlgItem(IDC_COMBO3))->GetCurSel()==2)
  230. pDoc->m_line_color=RGB(0,255,0);
  231. if(((CComboBox *)m_wndDlgBar.GetDlgItem(IDC_COMBO3))->GetCurSel()==3)
  232. pDoc->m_line_color=RGB(0,0,255);
  233. if(((CComboBox *)m_wndDlgBar.GetDlgItem(IDC_COMBO3))->GetCurSel()==4)
  234. pDoc->m_line_color=RGB(255,255,255);
  235. if(((CComboBox *)m_wndDlgBar.GetDlgItem(IDC_COMBO3))->GetCurSel()==5)
  236. pDoc->m_line_color=RGB(255,255,0);
  237. if(((CComboBox *)m_wndDlgBar.GetDlgItem(IDC_COMBO3))->GetCurSel()==6)
  238. pDoc->m_line_color=RGB(0,255,255);
  239. if(((CComboBox *)m_wndDlgBar.GetDlgItem(IDC_COMBO3))->GetCurSel()==7)
  240. {
  241. CColorDialog dlg;
  242. if(dlg.DoModal()==IDOK)
  243. pDoc->m_line_color=dlg.GetColor();
  244. }
  245. }
  246. void CMainFrame::OnViewDrawbar() 
  247. {
  248. ShowControlBar(&m_wndDrawTool,!m_wndDrawTool.IsWindowVisible(),false);
  249. }
  250. void CMainFrame::OnUpdateViewDrawbar(CCmdUI* pCmdUI) 
  251. {
  252. pCmdUI->SetCheck(m_wndDrawTool.IsWindowVisible());
  253. }
  254. void CMainFrame::OnViewCatchbar() 
  255. {
  256. ShowControlBar(&m_wndCatchTool,!m_wndCatchTool.IsWindowVisible(),false);
  257. }
  258. void CMainFrame::OnUpdateViewCatchbar(CCmdUI* pCmdUI) 
  259. {
  260. pCmdUI->SetCheck(m_wndCatchTool.IsWindowVisible());
  261. }
  262. void CMainFrame::OnTimer(UINT nIDEvent) 
  263. {
  264. static BOOL show=true;
  265. if(show)
  266. {  
  267. int cscy = ::GetSystemMetrics(SM_CYSCREEN) / 5*4; 
  268. int cscx = ::GetSystemMetrics(SM_CXSCREEN) / 5*4; 
  269. int csy = cscy/7; 
  270. int csx = cscx/7;
  271. this->MoveWindow(csx,csy,cscx,cscy);
  272. this->ShowWindow(SW_SHOWMAXIMIZED);
  273. show=false;
  274. }
  275. // CFrameWnd::OnTimer(nIDEvent);
  276. }
  277. void CMainFrame::OnPaint() 
  278. {
  279. CPaintDC dc(this); 
  280. //this->ShowWindow(SW_SHOWMINIMIZED);
  281. }
  282. void CMainFrame::OnShowWindow(BOOL bShow, UINT nStatus) 
  283. {
  284. /* static bool show=true;
  285. if(show)
  286. {
  287. this->ShowWindow(SW_SHOWMINIMIZED);
  288. }
  289. */
  290. }