ChildFrm.cpp
上传用户:zhanglf88
上传日期:2013-11-19
资源大小:6036k
文件大小:7k
源码类别:

金融证券系统

开发平台:

Visual C++

  1. // ChildFrm.cpp : implementation of the CChildFrame class
  2. //
  3. #include "stdafx.h"
  4. #include "StkUI.h"
  5. #include "ChildFrm.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CChildFrame
  13. #define IDC_CHILDFRAME_TABCTRL 1000
  14. IMPLEMENT_DYNCREATE(CChildFrame, CMDIChildWnd)
  15. BEGIN_MESSAGE_MAP(CChildFrame, CMDIChildWnd)
  16. //{{AFX_MSG_MAP(CChildFrame)
  17. ON_WM_CREATE()
  18. ON_WM_WINDOWPOSCHANGED()
  19. ON_NOTIFY(TCN_SELCHANGE, IDC_CHILDFRAME_TABCTRL, OnTabSelChange)
  20. ON_WM_CLOSE()
  21. //}}AFX_MSG_MAP
  22. END_MESSAGE_MAP()
  23. CChildFrame* CChildFrame::CreateNewFrame( CStaticDoc* pStaticDoc )
  24. {
  25. if (pStaticDoc != NULL)
  26. ASSERT_VALID(pStaticDoc);
  27. // create a frame wired to the specified document
  28. ASSERT( pStaticDoc->GetIDResource() != 0); // must have a resource ID to load from
  29. CCreateContext context;
  30. context.m_pCurrentFrame = NULL;
  31. context.m_pCurrentDoc = NULL; //pStaticDoc;
  32. context.m_pLastView = NULL;
  33. context.m_pNewViewClass = NULL; // pViewClass if this is set, a view will be created!
  34. context.m_pNewDocTemplate = NULL;
  35. CRuntimeClass* pFrameClass = RUNTIME_CLASS(CChildFrame);
  36. CChildFrame * pFrame = (CChildFrame*)pFrameClass->CreateObject();
  37. if (pFrame == NULL)
  38. {
  39. TRACE1("Warning: Dynamic create of frame %hs failed.n",
  40. pFrameClass->m_lpszClassName);
  41. return NULL;
  42. }
  43. ASSERT_KINDOF(CChildFrame, pFrame);
  44. // create new from resource
  45. if (!pFrame->LoadFrame( pStaticDoc->GetIDResource(),
  46. WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE,   // default frame styles
  47. AfxGetMainFrame(), &context))
  48. {
  49. TRACE0("Warning: Couldn't create a child frame.n");
  50. // frame will be deleted in PostNcDestroy cleanup
  51. return NULL;
  52. }
  53. // it worked !
  54. return pFrame;
  55. }
  56. /////////////////////////////////////////////////////////////////////////////
  57. // CChildFrame construction/destruction
  58. CChildFrame::CChildFrame()
  59. {
  60. // TODO: add member initialization code here
  61. }
  62. CChildFrame::~CChildFrame()
  63. {
  64. }
  65. BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
  66. {
  67. // TODO: Modify the Window class or styles here by modifying
  68. //  the CREATESTRUCT cs
  69. return CMDIChildWnd::PreCreateWindow(cs);
  70. }
  71. BOOL CChildFrame::PreTranslateMessage(MSG* pMsg) 
  72. {
  73. // TODO: Add your specialized code here and/or call the base class
  74. CMainFrame * pMainFrame = AfxGetMainFrame( );
  75. if( WM_SYSKEYDOWN == pMsg->message
  76. || WM_SYSKEYUP == pMsg->message 
  77. || WM_SYSCHAR == pMsg->message )
  78. {
  79. if( pMainFrame && VK_F4 == pMsg->wParam )
  80. {
  81. pMainFrame->PostMessage( WM_CLOSE );
  82. return TRUE;
  83. }
  84. }
  85. else if( WM_RBUTTONUP == pMsg->message
  86. || WM_RBUTTONDOWN == pMsg->message
  87. || WM_NCRBUTTONUP == pMsg->message
  88. || WM_NCRBUTTONDOWN == pMsg->message )
  89. {
  90. CWnd* pWnd = CWnd::FromHandlePermanent(pMsg->hwnd);
  91. CView * pView = DYNAMIC_DOWNCAST( CView, pWnd );
  92. if( NULL == pView )
  93. pView = GetActiveView();
  94. UINT nMenuID = 0;
  95. if( pView && pView->IsKindOf(RUNTIME_CLASS(CSimuView)) )
  96. nMenuID = IDR_POPUP_SIMUVIEW;
  97. else if( pView && pView->IsKindOf(RUNTIME_CLASS(CSListView)) )
  98. nMenuID = IDR_POPUP_SLISTVIEW;
  99. else if( pView && pView->IsKindOf(RUNTIME_CLASS(CGraphView)) )
  100. {
  101. pView->PostMessage(WM_USER_MYRBUTTONDOWN,pMsg->wParam,pMsg->lParam);
  102. nMenuID = IDR_POPUP_GRAPHVIEW;
  103. }
  104. else if( pView && pView->IsKindOf(RUNTIME_CLASS(CRealTimeView)) )
  105. nMenuID = IDR_POPUP_REALTIMEVIEW;
  106. else if( pView && pView->IsKindOf(RUNTIME_CLASS(CMultiSortView)) )
  107. nMenuID = IDR_POPUP_MULTISORTVIEW;
  108. else if( pView && pView->IsKindOf(RUNTIME_CLASS(CBaseView)) )
  109. nMenuID = IDR_POPUP_BASEVIEW;
  110. else if( pView && pView->IsKindOf(RUNTIME_CLASS(CSelectorView)) )
  111. nMenuID = IDR_POPUP_SETTING;
  112. if( pMainFrame && 0 != nMenuID )
  113. {
  114. if( pWnd && WM_RBUTTONUP == pMsg->message )
  115. {
  116. CPoint pt;
  117. pt.x = LOWORD(pMsg->lParam);
  118. pt.y = HIWORD(pMsg->lParam);
  119. pWnd->ClientToScreen(&pt);
  120. CMenu menu;
  121. if( menu.LoadMenu( nMenuID ) )
  122. {
  123. CMenu * pMenu = menu.GetSubMenu(0);
  124. for( UINT nMenu=0; pMenu && nMenu<pMenu->GetMenuItemCount(); nMenu++ )
  125. {
  126. CMenu * pPopupMenu = pMenu->GetSubMenu(nMenu);
  127. pMainFrame->InitMenuPopup( pPopupMenu );
  128. }
  129. VERIFY( pMenu->TrackPopupMenu( TPM_LEFTALIGN | TPM_RIGHTBUTTON, pt.x, pt.y, pMainFrame ) );
  130. }
  131. }
  132. return TRUE;
  133. }
  134. }
  135. return CMDIChildWnd::PreTranslateMessage(pMsg);
  136. }
  137. void CChildFrame::OnUpdateFrameTitle(BOOL bAddToTitle)
  138. {
  139. GetMDIFrame()->OnUpdateFrameTitle(bAddToTitle);
  140. if ((GetStyle() & FWS_ADDTOTITLE) == 0)
  141. return;     // leave child window alone!
  142. CView * pView = GetActiveView( );
  143. if (bAddToTitle)
  144. {
  145. TCHAR szText[256+_MAX_PATH];
  146. memset( szText, 0, sizeof(szText) );
  147. if (pView == NULL)
  148. lstrcpyn(szText, m_strTitle, 256+MAX_PATH);
  149. else
  150. pView->SendMessage( WM_USER_GETVIEWTITLE, 255+MAX_PATH, long(szText) );
  151. // set title if changed, but don't remove completely
  152. AfxSetWindowText(m_hWnd, szText);
  153. }
  154. }
  155. /////////////////////////////////////////////////////////////////////////////
  156. // CChildFrame diagnostics
  157. #ifdef _DEBUG
  158. void CChildFrame::AssertValid() const
  159. {
  160. CMDIChildWnd::AssertValid();
  161. }
  162. void CChildFrame::Dump(CDumpContext& dc) const
  163. {
  164. CMDIChildWnd::Dump(dc);
  165. }
  166. #endif //_DEBUG
  167. /////////////////////////////////////////////////////////////////////////////
  168. // CChildFrame message handlers
  169. int CChildFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  170. {
  171. if (CMDIChildWnd::OnCreate(lpCreateStruct) == -1)
  172. return -1;
  173. return 0;
  174. }
  175. void CChildFrame::ResetClientPosition( BOOL bMaximized )
  176. {
  177. }
  178. void CChildFrame::OnWindowPosChanged(WINDOWPOS FAR* lpwndpos) 
  179. {
  180. /* My Own Tab
  181. if( !(lpwndpos->flags & SWP_NOSIZE) || !(lpwndpos->flags & SWP_NOMOVE)
  182. || (lpwndpos->flags & SWP_SHOWWINDOW) )
  183. {
  184. CView * pView = GetActiveView();
  185. if( pView && ::IsWindow(pView->GetSafeHwnd()) )
  186. pView->SetWindowPos( NULL, 0,0,0,0, SWP_NOSIZE | SWP_NOMOVE | SWP_HIDEWINDOW );
  187. }
  188. */
  189. CMDIChildWnd::OnWindowPosChanged(lpwndpos);
  190. /* My Own Tab
  191. if( !(lpwndpos->flags & SWP_NOSIZE) || !(lpwndpos->flags & SWP_NOMOVE)
  192. || (lpwndpos->flags & SWP_SHOWWINDOW) )
  193. {
  194. ResetClientPosition( IsZoomed() );
  195. }
  196. */
  197. }
  198. void CChildFrame::OnTabSelChange(NMHDR* pNMHDR, LRESULT* pResult)
  199. {
  200. //int nSel = m_tabctrl.GetCurSel();
  201. //if( -1 == nSel )
  202. // return;
  203. //CMainFrame * pFrame = AfxGetMainFrame();
  204. //if( NULL == pFrame )
  205. // return;
  206. //TCITEM tci;
  207. //tci.mask = TCIF_PARAM;
  208. //if( m_tabctrl.GetItem( nSel, &tci ) )
  209. //{
  210. // pFrame->OnCmdMsg( tci.lParam, 0, NULL, NULL );
  211. //}
  212. }
  213. void CChildFrame::OnClose()
  214. {
  215. // TODO: Add your message handler code here and/or call default
  216. // Get View Title
  217. CView * pView = GetActiveView( );
  218. TCHAR szText[256+_MAX_PATH];
  219. memset( szText, 0, sizeof(szText) );
  220. if (pView == NULL)
  221. lstrcpyn(szText, m_strTitle, 256+MAX_PATH);
  222. else
  223. {
  224. BOOL bCanClose = TRUE;
  225. if( 0 == pView->SendMessage( WM_USER_CANCLOSEVIEW, NULL, (LPARAM)(&bCanClose) )
  226. && !bCanClose )
  227. return;
  228. pView->SendMessage( WM_USER_GETVIEWTITLE, 255+MAX_PATH, long(szText) );
  229. }
  230. CMDIChildWnd::OnClose();
  231. }