MyFrameWnd.cpp
上传用户:huashan618
上传日期:2013-03-26
资源大小:261k
文件大小:7k
- // MyFrameWnd.cpp : 实现文件
- //
- #include "stdafx.h"
- #include "PPExplorer.h"
- #include "MyFrameWnd.h"
- #include ".myframewnd.h"
- //#include "ppexplorerdlg.h"
- #include <commctrl.h>
- typedef UINT (CALLBACK* LPFNORGFAV)(HWND, LPTSTR);
- typedef BOOL (CALLBACK* LPFNADDFAV)(HWND, TCHAR*, UINT, TCHAR*, UINT, LPITEMIDLIST);
- #include <urlhist.h>
- #include <comdef.h>
- // CMyFrameWnd
- extern CString g_statusinfo;
- extern CCustomTabCtrl g_explorer;
- IMPLEMENT_DYNCREATE(CMyFrameWnd, CMiniFrameWnd)
- CMyFrameWnd::CMyFrameWnd()
- {
- m_pAutoEnumString=NULL;
- }
- CMyFrameWnd::~CMyFrameWnd()
- {
- }
- BEGIN_MESSAGE_MAP(CMyFrameWnd, CMiniFrameWnd)
- ON_WM_CREATE()
- ON_WM_PAINT()
- ON_COMMAND(ID_TOOL_MOVIE,OnShowMoviePage)
- ON_COMMAND(ID_URL_PREV,OnWebBack)
- ON_COMMAND(ID_URL_NEXT,OnWebNext)
- ON_COMMAND(ID_URL_STOP,OnWebStop)
- ON_COMMAND(ID_URL_FRASH,OnWebStop)
- ON_COMMAND(ID_URL_HOME,OnWebHome)
- ON_CBN_EDITCHANGE(AFX_IDW_TOOLBAR + 1,OnAddressChange)
- ON_CBN_SELENDOK(AFX_IDW_TOOLBAR + 1,OnNewAddress)
- ON_COMMAND(IDOK, OnNewAddressEnter)
- ON_WM_SIZE()
- END_MESSAGE_MAP()
- // CMyFrameWnd 消息处理程序
- int CMyFrameWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CMiniFrameWnd::OnCreate(lpCreateStruct) == -1)
- return -1;
- // CImageList img;
- // CString str;
- if (!m_toolbar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
- | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
- !m_toolbar.LoadToolBar(IDR_TOLMENU))
- {
- return -1; // 未能创建
- }
- if (!m_toolnav.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
- | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
- !m_toolnav.LoadToolBar(IDR_TOLURLBAR))
- {
- return -1; // 未能创建
- }
- if (!m_toolurl.Create(this))
- {
- TRACE0("Failed to create rebarn");
- return -1; // fail to create
- }
- if (!m_wndAddress.Create(CBS_DROPDOWN | WS_CHILD, CRect(0, 0, 200, 120), this, AFX_IDW_TOOLBAR + 1))
- {
- TRACE0("Failed to create comboboxn");
- return -1; // fail to create
- }
- m_wndAddress.LimitText(0);
- InitAddress();
- //m_toolurl.AddBar(&m_toolbar,NULL, NULL, RBBS_GRIPPERALWAYS|RBBS_FIXEDBMP);
- //m_toolurl.AddBar(&m_toolnav,NULL, NULL, RBBS_GRIPPERALWAYS|RBBS_FIXEDBMP);
- m_toolurl.AddBar(&m_wndAddress, _T("地址:"), NULL, RBBS_FIXEDBMP | RBBS_BREAK);
- m_toolbar.EnableDocking(CBRS_ALIGN_ANY);
- m_toolnav.EnableDocking(CBRS_ALIGN_ANY);
- m_toolurl.EnableDocking(CBRS_ALIGN_ANY);
- EnableDocking(CBRS_ALIGN_ANY);
- DockControlBar(&m_toolbar);
- DockControlBar(&m_toolnav);
- DockControlBar(&m_toolurl);
- return 0;
- }
- void CMyFrameWnd::OnPaint()
- {
- CPaintDC dc(this); // device context for painting
- //CRect rect;
- // GetClientRect(&rect);
- // dc.FillRect(&rect,&CBrush(RGB(192,255,218)));
- }
- //显示电影页面
- void CMyFrameWnd::OnShowMoviePage()
- {
- ::SendMessage(GetParent()->GetSafeHwnd(),WM_MENU_MESSAGE,ID_TOOL_MOVIE,0);
- }
- //处理页面控制栏的消息
- void CMyFrameWnd::OnWebBack()
- {
- if(g_explorer.m_oldwnd==NULL) return;
- ((CIEView*)g_explorer.m_oldwnd)->GoBack();
- return;
- }
- //下一页
- void CMyFrameWnd::OnWebNext()
- {
- if(g_explorer.m_oldwnd==NULL) return;
- ((CIEView*)g_explorer.m_oldwnd)->GoForward();
- }
- //停止
- void CMyFrameWnd::OnWebStop()
- {
- if(g_explorer.m_oldwnd==NULL) return;
- ((CIEView*)g_explorer.m_oldwnd)->Stop();
- }
- //刷新
- void CMyFrameWnd::OnWebFrash()
- {
- if(g_explorer.m_oldwnd==NULL) return;
- ((CIEView*)g_explorer.m_oldwnd)->Refresh();
- }
- //主页
- void CMyFrameWnd::OnWebHome()
- {
- if(g_explorer.m_oldwnd==NULL) return;
- ((CIEView*)g_explorer.m_oldwnd)->GoHome();
- }
- void CMyFrameWnd::EnableGoBack(BOOL bEnable)
- {
- m_bEnableGoBack=bEnable;
- }
- void CMyFrameWnd::EnableGoForward(BOOL bEnable)
- {
- m_bEnableGoForward=bEnable;
- }
- //从注册表中获取历史数据
- BOOL CMyFrameWnd::AddHistory(LPCTSTR lpszURL, LPCTSTR lpszTitle)
- {
- #if 0
- HRESULT hr;
- IUrlHistoryStg2 *puhs;
- _bstr_t bstrUrl(lpszURL);
- _bstr_t bstrTitle(lpszURL);
- hr = ::CoCreateInstance(CLSID_CUrlHistory, NULL, CLSCTX_INPROC_SERVER, IID_IUrlHistoryStg, (LPVOID *)&puhs);
- if(SUCCEEDED(hr))
- {
- hr=puhs->AddUrl(bstrUrl,bstrTitle,NULL);
- ASSERT(hr==S_OK);
- puhs->Release();
- m_pAutoEnumString->AddRef();
- m_pAutoEnumString->AddString(lpszURL);
- m_pAutoEnumString->Release();
- }
- #endif
- return TRUE;
- }
- BOOL CMyFrameWnd::InitAddress()
- {
- typedef HRESULT (CALLBACK* LPFNDLLFUNC1)(HWND ,DWORD);
- HINSTANCE hIns = LoadLibrary("shlwapi.dll");
- if(hIns != NULL)
- {
- LPFNDLLFUNC1 lpfnDllFunc1 = (LPFNDLLFUNC1)GetProcAddress(hIns, "SHAutoComplete");
- if(lpfnDllFunc1!=NULL)
- lpfnDllFunc1(m_wndAddress.GetEditCtrl()->m_hWnd, 0xe);
-
- FreeLibrary(hIns);
- }
- HRESULT hr;
- IUrlHistoryStg2 *puhs;
- IEnumSTATURL *pesu;
- STATURL su;
- ULONG celt;
- _bstr_t bstr;
- hr = ::CoCreateInstance(CLSID_CUrlHistory, NULL, CLSCTX_INPROC_SERVER, IID_IUrlHistoryStg, (LPVOID *)&puhs);
- m_pAutoEnumString=new CAutoEnumString;
- m_pAutoEnumString->AddRef();
- if(SUCCEEDED(hr))
- {
- hr = puhs->EnumUrls(&pesu);
- if(SUCCEEDED(hr))
- {
- while(SUCCEEDED(pesu->Next(1, &su, &celt)) && celt > 0)
- {
- bstr = su.pwcsUrl;
- CString strAddress;
- strAddress=(LPCTSTR)(bstr);
- if(strAddress.Find("http://",0)==0)//有选择的添加
- {
- // m_wndAddress.AddString(bstr);
- if(strAddress.GetLength()<30)
- {
- COMBOBOXEXITEM item;
- item.mask = CBEIF_TEXT;
- item.iItem = -1; // insert at the end. So the order is keeped
- item.pszText = (LPTSTR)(LPCTSTR)bstr;
- m_wndAddress.InsertItem(&item);
- }
- }
- m_pAutoEnumString->AddString(bstr);
- }
- puhs->Release();
- }
- }
- //自动完成功能的添加
- m_pAutoEnumString->QueryInterface(IID_IEnumString,(LPVOID*)&m_pEnumSting);
- m_pAutoEnumString->Release();
- ::CoCreateInstance( CLSID_AutoComplete, NULL,
- CLSCTX_INPROC_SERVER, IID_IAutoComplete,
- (LPVOID *) &m_pAutoCmpAddress );
- HWND hwnd= (HWND)m_wndAddress.SendMessage(CBEM_GETEDITCONTROL);
- if(hwnd)
- {
- m_pAutoCmpAddress->Init(hwnd,m_pEnumSting,NULL,NULL);
- }
- IAutoComplete2 *pac2;
- if (SUCCEEDED(m_pAutoCmpAddress->QueryInterface(IID_IAutoComplete2, (LPVOID*)&pac2)))
- {
- pac2->SetOptions(ACO_AUTOSUGGEST|ACO_AUTOAPPEND);
- pac2->Release();
- }
- return TRUE;
- }
- //当地址栏的数据发生变化时调用
- void CMyFrameWnd::OnAddressChange()
- {
- //AfxMessageBox(_T("the addresschange!"));
- }
- //在地址栏中输入了新的地址信息,按下回车键后响应
- void CMyFrameWnd::OnNewAddressEnter()
- {
- CString str;
- m_wndAddress.GetWindowText(str);
- if (str.GetLength() == 0)
- return;
- if(g_explorer.m_oldwnd)
- {
- ((CIEView*)g_explorer.m_oldwnd)->ReadUrlDocument(str);
- }
- else
- {
- g_explorer.InsertItem(0,str,RUNTIME_CLASS(CIEView));
- g_explorer.SetCurSel(0);
- }
-
- }
- //在组合框中选择了一项地址后响应
- void CMyFrameWnd::OnNewAddress()
- {
- CString str;
- m_wndAddress.GetLBText(m_wndAddress.GetCurSel(), str);
- if (str.GetLength() == 0)
- return;
- if(g_explorer.m_oldwnd)
- {
- ((CIEView*)g_explorer.m_oldwnd)->ReadUrlDocument(str);
- }
- else
- {
- g_explorer.InsertItem(0,str,RUNTIME_CLASS(CIEView));
- g_explorer.SetCurSel(0);
- }
- }
- // 设置地址框信息
- void CMyFrameWnd::SetAddressBarText(CString url)
- {
- m_wndAddress.SetWindowText(url);
- }
- // 当所浏览的网页发生改变时,重新显示标题
- void CMyFrameWnd::SetTabCtrlTitle(CString title)
- {
- g_explorer.SetItemText(g_explorer.GetCurSel(),title);
- }