MainFrame.cpp
上传用户:popouu88
上传日期:2013-02-11
资源大小:2894k
文件大小:8k
源码类别:

IP电话/视频会议

开发平台:

Visual C++

  1. // MainFrame.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "IE.h"
  5. #include "MainFrame.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CMainFrame
  13. CMainFrame::CMainFrame( )
  14. {
  15. this->view = new CTabView( );
  16. if( ! this->Create( NULL , "协同浏览" , WS_OVERLAPPEDWINDOW , rectDefault , NULL , 0 ) )
  17. {
  18. delete this->view;
  19. this->view = NULL;
  20. }
  21. this->OnIEURL = NULL;
  22. this->wParam = NULL;
  23. this->user_name = "";
  24. }
  25. CMainFrame::~CMainFrame( )
  26. {
  27. }
  28. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  29. //{{AFX_MSG_MAP(CMainFrame)
  30. ON_WM_CREATE()
  31. ON_COMMAND(ID_OPEN, OnOpen)
  32. ON_COMMAND(ID_SAVE, OnSave)
  33. ON_COMMAND(ID_BACKWORD, OnBackword)
  34. ON_COMMAND(ID_FORWORD, OnForword)
  35. ON_COMMAND(ID_STOP, OnStop)
  36. ON_COMMAND(ID_FLUSH, OnFlush)
  37. ON_COMMAND(ID_HOME, OnHome)
  38. ON_COMMAND(ID_SEARCH, OnSearch)
  39. ON_COMMAND(ID_FAVORITE, OnFavorite)
  40. ON_COMMAND(ID_HISTORY, OnHistory)
  41. ON_COMMAND(ID_FONT, OnFont)
  42. ON_WM_CHAR()
  43. ON_UPDATE_COMMAND_UI(ID_FAVORITE, OnUpdateFavorite)
  44. //}}AFX_MSG_MAP
  45. ON_NOTIFY(NM_CLICK, IDC_TREE, OnSelchangedTree)
  46. ON_COMMAND_RANGE( ID_FONT_BIGGEST , ID_FONT_SMALLEST , OnFontMenu )
  47. END_MESSAGE_MAP()
  48. static UINT indicators[] =
  49. {
  50. ID_SEPARATOR,    
  51. // ID_INDICATOR_CAPS,
  52. // ID_INDICATOR_NUM,
  53. // ID_INDICATOR_SCRL,
  54. };
  55. /////////////////////////////////////////////////////////////////////////////
  56. // CMainFrame message handlers
  57. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  58. {
  59. if ( CFrameWnd::OnCreate(lpCreateStruct) == -1 )
  60. return -1;
  61. this->reBar.Create( this );
  62.     //工具栏
  63. this->toolBar.CreateEx( this , TBSTYLE_FLAT | TBSTYLE_TRANSPARENT |TBSTYLE_TOOLTIPS ); 
  64. this->toolBar.LoadToolBar(IDR_MAIN_TOOLBAR );
  65. CImageList imglist;
  66. imglist.Create( 21 , 20 , ILC_COLORDDB|ILC_MASK, 35, 1);
  67. CBitmap bmp;
  68. bmp.LoadBitmap( IDB_COLDTOOLBAR );
  69. imglist.Add( &bmp , RGB( 255 , 0 , 255 ) );
  70. bmp.Detach( );
  71. this->toolBar.GetToolBarCtrl( ).SetImageList( &imglist );
  72. imglist.Detach( );
  73. imglist.Create( 21 , 20 , ILC_COLORDDB|ILC_MASK, 35, 1);
  74. bmp.LoadBitmap( IDB_HOTTOOLBAR );
  75. imglist.Add( &bmp , RGB( 255 , 0 , 255 ) );
  76. bmp.Detach( );
  77. CString text;
  78. CRect rc;
  79. for( int i = 0; i < this->toolBar.GetCount( ); i ++ )
  80. {
  81. text.LoadString( this->toolBar.GetItemID( i ) );
  82. text.Delete( 'n' );
  83. this->toolBar.SetButtonText( i , text );
  84. this->toolBar.GetItemRect( 0 , &rc );
  85. this->toolBar.SetSizes( CSize( rc.Width( ) , rc.Height( ) ) , CSize( 16 , 20 ) );
  86. }
  87. this->toolBar.GetToolBarCtrl( ).SetHotImageList( &imglist );
  88. this->toolBar.GetToolBarCtrl( ).HideButton( ID_SEARCH );
  89. this->toolBar.GetToolBarCtrl( ).HideButton( ID_HISTORY );
  90. imglist.Detach( );
  91. this->reBar.AddBar( &this->toolBar , RGB( 10 , 10 , 10 ) , RGB( 214 , 239 , 255 ) , NULL , RBBS_NOGRIPPER | RBBS_HIDDEN );
  92.     //地址栏
  93. this->addrCombo.Create( WS_CHILD | WS_VISIBLE | CBS_DROPDOWN | WS_VSCROLL | WS_TABSTOP , CRect( 0 , 0 , 1 , 200 ) , this , ID_ADDR_COMBO );
  94. this->editAddr.SubclassWindow(  this->addrCombo.GetEditCtrl( )->GetSafeHwnd( ) );
  95. this->editAddr.RegisterGetURLFunction( CMainFrame::OnAddress , this );
  96. this->reBar.AddBar( &this->addrCombo , RGB( 10 , 10 , 10 ) , RGB( 214 , 239 , 255 ) , "地址栏" ,RBBS_NOGRIPPER | RBBS_BREAK | RBBS_HIDDEN );
  97. //状态栏
  98. this->statusBar.CreateEx( this );
  99. this->statusBar.ShowWindow( SW_HIDE );
  100. this->statusBar.SetIndicators( indicators , sizeof( indicators ) / sizeof( UINT ) );
  101.     //视图
  102. this->view->Create( NULL , NULL , AFX_WS_DEFAULT_VIEW , CRect( 0 , 0 , 0 , 0 ) , this , AFX_IDW_PANE_FIRST , NULL );
  103. //自动搜索地址
  104. HINSTANCE hIns = LoadLibrary("shlwapi.dll");
  105. if(hIns != NULL)
  106. {
  107. typedef HRESULT (CALLBACK* LPFNDLLFUNC1)(HWND ,DWORD);
  108. LPFNDLLFUNC1 lpfnDllFunc1 = (LPFNDLLFUNC1)GetProcAddress(hIns, "SHAutoComplete");
  109. if(lpfnDllFunc1!=NULL)
  110. lpfnDllFunc1(this->addrCombo.GetSafeHwnd( ) , 0xe );
  111. FreeLibrary(hIns);
  112. }
  113. //收藏夹
  114. this->favorite_bar.Create( this );
  115. this->ShowControlBar( &this->favorite_bar , FALSE , FALSE );
  116. //历史纪录
  117. this->history_bar.Create( this );
  118. this->ShowControlBar( &this->history_bar , FALSE , FALSE );
  119. return 0;
  120. }
  121. void CMainFrame::SetStatusText( LPCSTR text )
  122. {
  123. if( this->statusBar )
  124. this->statusBar.SetWindowText( text );
  125. }
  126. void CMainFrame::OnAddress( void * wParam )
  127. {
  128. CMainFrame * pThis = ( CMainFrame * )wParam;
  129. CString url;
  130. pThis->editAddr.GetWindowText( url );
  131. if( ! url.IsEmpty( ) )
  132. {
  133. CIEView * ieView = pThis->view->CreateIEView( );
  134.         //设定id   
  135. ieView->ieid = ( int )ieView;
  136. ieView->username = pThis->user_name;
  137.         //通知外部
  138. ieView->m_bNotify = TRUE;
  139. ieView->Navigate2( url );
  140. }
  141. }
  142. void CMainFrame::OnOpen() 
  143. {
  144. CFileDialog dlg( true , NULL , NULL ,  OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT , "网页文件(*.html,*.htm,*.jsp,*.asp)|*.html,*.htm,*.jsp,*.asp|所有文件(*.*)|*.*||");
  145. if( dlg.DoModal( ) == IDOK )
  146. {
  147. this->editAddr.SetWindowText( dlg.GetPathName( ) );
  148. this->OnAddress( this );
  149. }
  150. }
  151. void CMainFrame::OnSave() 
  152. {
  153. CIEView * ieView = this->GetView( )->GetIEView( );
  154. if( ieView )
  155. ieView->ExecWB(OLECMDID_SAVEAS, OLECMDEXECOPT_DODEFAULT, NULL, NULL);
  156. }
  157. void CMainFrame::OnBackword() 
  158. {
  159. CIEView * ieView = this->GetView( )->GetIEView( );
  160. if( ieView )
  161. {
  162. ieView->m_bNotify = TRUE;
  163. ieView->GoBack( );
  164. }
  165. }
  166. void CMainFrame::OnForword() 
  167. {
  168. CIEView * ieView = this->GetView( )->GetIEView( );
  169. if( ieView )
  170. {
  171. ieView->m_bNotify = TRUE;
  172. ieView->GoForward( );
  173. }
  174. }
  175. void CMainFrame::OnStop() 
  176. {
  177. CIEView * ieView = this->GetView( )->GetIEView( );
  178. if( ieView )
  179. ieView->Stop( );
  180. }
  181. void CMainFrame::OnFlush() 
  182. {
  183. CIEView * ieView = this->GetView( )->GetIEView( );
  184. if( ieView )
  185. ieView->Refresh2( REFRESH_NORMAL );
  186. }
  187. void CMainFrame::OnHome() 
  188. {
  189. CIEView * ieView = this->GetView( )->GetIEView( );
  190. if( ieView )
  191. {
  192. ieView->m_bNotify = TRUE;
  193. ieView->GoHome( );
  194. }
  195. }
  196. void CMainFrame::OnSearch() 
  197. {
  198. CIEView * ieView = this->GetView( )->GetIEView( );
  199. if( ieView )
  200. ieView->GoSearch( );
  201. }
  202. void CMainFrame::OnFavorite() 
  203. {
  204. this->ShowControlBar( &this->favorite_bar , ! this->favorite_bar.IsVisible( ) , FALSE );
  205. }
  206. void CMainFrame::OnUpdateFavorite(CCmdUI* pCmdUI) 
  207. {
  208. pCmdUI->SetCheck( this->favorite_bar.IsVisible( ) );
  209. }
  210. void CMainFrame::OnHistory() 
  211. {
  212. this->ShowControlBar( &this->history_bar , ! this->history_bar.IsVisible( ) , FALSE );
  213. }
  214. void CMainFrame::OnFont( ) 
  215. {
  216. CIEView * ieView = this->GetView( )->GetIEView( );
  217. if( ieView )
  218. {
  219. COleVariant vaZoomFactor;
  220. ieView->ExecWB( OLECMDID_ZOOM , OLECMDEXECOPT_DONTPROMPTUSER , NULL , &vaZoomFactor );
  221. CRect rc;
  222. this->toolBar.GetItemRect( 10 , &rc );
  223. this->toolBar.ClientToScreen( &rc );
  224. CMenu menu;
  225. menu.LoadMenu( IDR_FONT_MENU );
  226. menu.GetSubMenu( 0 )->CheckMenuItem( 4 - vaZoomFactor.intVal , MF_CHECKED | MF_BYPOSITION );
  227. menu.GetSubMenu( 0 )->TrackPopupMenu( TPM_LEFTALIGN  , rc.left , rc.bottom + 1 , this );
  228. }
  229. }
  230. void CMainFrame::OnFontMenu( UINT id )
  231. {
  232. CIEView * ieView = this->GetView( )->GetIEView( );
  233. if( ieView )
  234. {
  235. COleVariant vaZoomFactor( ( long )( ID_FONT_BIGGEST + 4 - id ) );
  236. ieView->ExecWB( OLECMDID_ZOOM , OLECMDEXECOPT_DONTPROMPTUSER , &vaZoomFactor , NULL );
  237. }
  238. }
  239. void CMainFrame::OnSelchangedTree( NMHDR* pNMHDR, LRESULT* pResult )
  240. {
  241. CString url;
  242. this->favorite_bar.GetCurURL( url );
  243. if( ! url.IsEmpty( ) )
  244. {
  245. this->editAddr.SetWindowText( url );
  246. CIEView * ieView = this->GetView( )->GetIEView( );
  247. if( ! ieView )
  248. this->OnAddress( this );
  249.         else
  250. {
  251. ieView->m_bNotify = TRUE;
  252. ieView->Navigate2( url );
  253. }
  254. }
  255. }