MainFrm.cpp
上传用户:qiye66671
上传日期:2009-12-10
资源大小:182k
文件大小:7k
源码类别:

绘图程序

开发平台:

C/C++

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3. #include "stdafx.h"
  4. #include "EastDraw.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. /////////////////////////////////////////////////////////////////////////////
  13. // CMainFrame
  14. IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
  15. BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
  16. //{{AFX_MSG_MAP(CMainFrame)
  17. ON_WM_CREATE()
  18. ON_COMMAND(Menu_ShowPorDlg, OnShowPorDlg)
  19. ON_UPDATE_COMMAND_UI(Menu_ShowPorDlg, OnUpdateShowPorDlg)
  20. ON_COMMAND(ID_ShowDrawTool_Bar, OnShowDrawToolBar)
  21. ON_UPDATE_COMMAND_UI(ID_ShowDrawTool_Bar, OnUpdateShowDrawToolBar)
  22. ON_WM_TIMER()
  23. //}}AFX_MSG_MAP
  24.     
  25. ON_UPDATE_COMMAND_UI(ID_MousPoint,OnUpdateMousPoint)
  26. ON_UPDATE_COMMAND_UI(ID_MousCaption,OnUpdateMousCaption)
  27. END_MESSAGE_MAP()
  28. static UINT indicators[] =
  29. {
  30. ID_SEPARATOR, // status line indicator
  31.     ID_MousCaption,
  32. ID_MousPoint,
  33.     ID_SEPARATOR,
  34. ID_INDICATOR_CAPS,
  35.     ID_INDICATOR_NUM,
  36. ID_INDICATOR_SCRL,
  37. };
  38. /////////////////////////////////////////////////////////////////////////////
  39. // CMainFrame construction/destruction
  40. CMainFrame::CMainFrame()
  41. {
  42. // TODO: add member initialization code here
  43. }
  44. CMainFrame::~CMainFrame()
  45. {
  46. }
  47. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  48. { // CG: The following line was added by the Splash Screen component.
  49. CSplashWnd::ShowSplashScreen(this);
  50. if (CMDIFrameWnd::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 toolbarn");
  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 barn");
  64. return -1;      // fail to create
  65. }
  66. // TODO: Delete these three lines if you don't want the toolbar to
  67. //  be dockable
  68. if (!m_wndDrawToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_LEFT
  69. | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
  70. !m_wndDrawToolBar.LoadToolBar(IDR_TOOLBAR1_DrawTool))
  71. {
  72. TRACE0("Failed to create toolbarn");
  73. return -1;      // fail to create
  74. }
  75. m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
  76. EnableDocking(CBRS_ALIGN_ANY);
  77. DockControlBar(&m_wndToolBar);
  78.     m_wndDrawToolBar.EnableDocking(CBRS_ALIGN_ANY);
  79. DockControlBar(&m_wndDrawToolBar);
  80.    
  81. //m_DLineProperty->MoveWindow(500,500,340,240);
  82.     
  83.     
  84.    if (!m_wndStyleBar.Create (this, WS_CHILD| CBRS_ALIGN_TOP|
  85.         CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC, IDW_STYLE_BAR))
  86.         return FALSE;
  87.     m_wndStyleBar.SetWindowText (_T ("文字工具条"));
  88.     m_wndStyleBar.EnableDocking (CBRS_ALIGN_ANY);
  89.     DockControlBar (&m_wndStyleBar);
  90. FloatControlBar(&m_wndStyleBar,CPoint(300,10));
  91.    
  92. m_DLineProperty=new CDLineProperty(_T("图元属性页"));
  93.     m_DLineProperty->Create(this,WS_SYSMENU | WS_POPUP | WS_CAPTION | DS_MODALFRAME,WS_EX_TOOLWINDOW);
  94.     
  95.     SetTimer(1, 1000, NULL);
  96.     return 0;
  97. }
  98. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  99. {
  100.     cs.cy = ::GetSystemMetrics(SM_CYSCREEN); 
  101.     cs.cx = ::GetSystemMetrics(SM_CXSCREEN); 
  102.     cs.y = ::GetSystemMetrics(SM_CYSCREEN); 
  103.     cs.x = -::GetSystemMetrics(SM_CYSCREEN);
  104. if( !CMDIFrameWnd::PreCreateWindow(cs) )
  105. return FALSE;
  106. // TODO: Modify the Window class or styles here by modifying
  107. //  the CREATESTRUCT cs
  108. return TRUE;
  109. }
  110. /////////////////////////////////////////////////////////////////////////////
  111. // CMainFrame diagnostics
  112. #ifdef _DEBUG
  113. void CMainFrame::AssertValid() const
  114. {
  115. CMDIFrameWnd::AssertValid();
  116. }
  117. void CMainFrame::Dump(CDumpContext& dc) const
  118. {
  119. CMDIFrameWnd::Dump(dc);
  120. }
  121. #endif //_DEBUG
  122. /////////////////////////////////////////////////////////////////////////////
  123. // CMainFrame message handlers
  124. void CMainFrame::OnShowPorDlg() 
  125. {
  126. // TODO: Add your command handler code here
  127. if(m_DLineProperty)
  128.   m_DLineProperty->ShowWindow(!m_DLineProperty->IsWindowVisible());
  129. }
  130. void CMainFrame::OnUpdateShowPorDlg(CCmdUI* pCmdUI) 
  131. {
  132. // TODO: Add your command update UI handler code here
  133. if(m_DLineProperty)
  134. pCmdUI->SetCheck(m_DLineProperty->IsWindowVisible());
  135. }
  136. void CMainFrame::ShowFontBar(BOOL isShow)
  137. {
  138.         
  139.   if((!(!isShow&&!m_wndStyleBar.IsWindowVisible()))&&!(isShow&&m_wndStyleBar.IsWindowVisible()))
  140. OnBarCheck(IDW_STYLE_BAR);
  141. }
  142. void CMainFrame::OnUpdateMousPoint(CCmdUI* pCmdUI)
  143. {
  144. pCmdUI->Enable();
  145. }
  146. void CMainFrame::OnUpdateMousCaption(CCmdUI* pCmdUI)
  147. {
  148. pCmdUI->Enable();
  149. }
  150. void CMainFrame::SetMousePosText(CPoint Logpoint,CPoint Devpoint)
  151. {
  152. CString strText;
  153. strText.Format("逻辑坐标:(%d,%d)",Logpoint.x,-Logpoint.y);
  154. int nIndex=m_wndStatusBar.CommandToIndex(ID_MousPoint);
  155. m_wndStatusBar.SetPaneText(nIndex,strText);
  156. CWindowDC dc(&m_wndStatusBar);
  157. CSize sizeText=dc.GetTextExtent(strText);
  158. m_wndStatusBar.SetPaneInfo(nIndex,ID_MousPoint,SBPS_NORMAL,sizeText.cx);
  159.     strText.Format("屏幕坐标:(%d,%d)",Devpoint.x,Devpoint.y);
  160. nIndex=m_wndStatusBar.CommandToIndex(ID_MousCaption);
  161. m_wndStatusBar.SetPaneText(nIndex,strText);
  162.     sizeText=dc.GetTextExtent(strText);
  163. m_wndStatusBar.SetPaneInfo(nIndex,ID_MousCaption,SBPS_NORMAL,sizeText.cx);
  164. }
  165. void CMainFrame::OnShowDrawToolBar() 
  166. {
  167. // TODO: Add your command handler code here
  168. ShowControlBar(&m_wndDrawToolBar,!m_wndDrawToolBar.IsWindowVisible(),false);
  169. }
  170. void CMainFrame::OnUpdateShowDrawToolBar(CCmdUI* pCmdUI) 
  171. {
  172. // TODO: Add your command update UI handler code here
  173.     pCmdUI->SetCheck(m_wndDrawToolBar.IsWindowVisible()?1:0);
  174. }
  175. void CMainFrame::OnTimer(UINT nIDEvent) 
  176. {
  177. // TODO: Add your message handler code here and/or call default
  178. static BOOL bShow=false;
  179. if(!bShow)
  180. {  
  181.      int cscy = ::GetSystemMetrics(SM_CYSCREEN) / 4*3; 
  182.          int cscx = ::GetSystemMetrics(SM_CXSCREEN) / 4*3; 
  183.          int csy = cscy/6; 
  184.          int csx = cscx/6;
  185.          CRect rect;
  186.      
  187.  this->MoveWindow(csx,csy,cscx,cscy);
  188.          this->ShowWindow(SW_SHOWMAXIMIZED);
  189.          this->m_DLineProperty->GetWindowRect(&rect);
  190.          this->m_DLineProperty->MoveWindow(cscx*4/3-rect.Width(),0,rect.Width(),rect.Height());
  191.      this->m_DLineProperty->ShowWindow(SW_SHOW);
  192. }
  193. bShow=true;
  194. CMDIFrameWnd::OnTimer(nIDEvent);
  195. }
  196. void CMainFrame::AddTempFile()
  197. {
  198.    
  199. }