00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00021
00022
00023
00024 #include "stdafx.h"
00025 #include "HtmlFrm.h"
00026
00027 CHtmlFrame::CHtmlFrame(CMainFrame *pMainFrame) :
00028 m_pHtmlView(NULL)
00029 {
00030 m_pMainFrame = pMainFrame;
00031 m_pCmdBar = NULL;
00032 }
00033
00034 void CHtmlFrame::OnFinalMessage(HWND )
00035 {
00036 delete this;
00037 }
00038 void CHtmlFrame::SetCommandBarCtrlForContextMenu(CTabbedMDICommandBarCtrl* pCmdBar)
00039 {
00040 m_pCmdBar = pCmdBar;
00041 }
00042
00043 LRESULT CHtmlFrame::OnCreate(UINT , WPARAM , LPARAM , BOOL& bHandled)
00044 {
00045 LRESULT lRet = DefWindowProc();
00046 bHandled = TRUE;
00047
00048 m_pHtmlView = new CHtmlView(this);
00049
00050
00051 m_hWndClient = m_pHtmlView->Create( m_hWnd,
00052 rcDefault,
00053 _T(""),
00054 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_HSCROLL | WS_VSCROLL,
00055 WS_EX_CLIENTEDGE);
00056 if ( NULL == m_hWndClient ) {
00057 ATLTRACE ( _T ( "Error: failed to create child window\n" ) );
00058 return FALSE;
00059 }
00060
00061 m_pHtmlView->get_Control(&m_punkBrowser);
00062 if(m_punkBrowser)
00063 DispEventAdvise(m_punkBrowser, &DIID_DWebBrowserEvents2);
00064
00065 return TRUE;
00066 }
00067 LRESULT CHtmlFrame::OnDestroy(UINT , WPARAM , LPARAM , BOOL& bHandled)
00068 {
00069 if(m_punkBrowser)
00070 DispEventUnadvise(m_punkBrowser, &DIID_DWebBrowserEvents2);
00071 bHandled = FALSE;
00072 return 0;
00073 }
00074 LRESULT CHtmlFrame::OnForwardMsg(UINT , WPARAM , LPARAM lParam, BOOL& )
00075 {
00076 LPMSG pMsg = (LPMSG)lParam;
00077
00078 if(baseClass::PreTranslateMessage(pMsg))
00079 return TRUE;
00080
00081 return m_pHtmlView->PreTranslateMessage(pMsg);
00082 }
00083 LRESULT CHtmlFrame::OnSettingChange(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& )
00084 {
00085
00086
00087 SendMessageToDescendants(uMsg, wParam, lParam, TRUE);
00088
00089 return 0;
00090 }
00091 LRESULT CHtmlFrame::OnShowTabContextMenu(UINT , WPARAM , LPARAM lParam, BOOL& bHandled)
00092 {
00093 bHandled = TRUE;
00094
00095 POINT ptPopup = {GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)};
00096
00097
00098 CMenu mnuContext;
00099
00100
00101
00102
00103
00104
00105
00106 if(mnuContext.CreatePopupMenu()) {
00107 int cchWindowText = GetWindowTextLength();
00108 CString sWindowText;
00109 GetWindowText(sWindowText.GetBuffer(cchWindowText+1), cchWindowText+1);
00110 sWindowText.ReleaseBuffer();
00111
00112 CString sSave(_T("&Save '"));
00113 sSave += sWindowText;
00114 sSave += _T("'");
00115
00116 mnuContext.AppendMenu((MF_ENABLED | MF_STRING), ID_FILE_SAVE, sSave);
00117 mnuContext.AppendMenu((MF_ENABLED | MF_STRING), ID_FILE_CLOSE, _T("&Close\tCtrl+F4"));
00118 mnuContext.AppendMenu(MF_SEPARATOR);
00119
00120 if(m_pCmdBar != NULL) {
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133 DWORD nSelection = m_pCmdBar->TrackPopupMenu(mnuContext, TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_TOPALIGN | TPM_VERTICAL | TPM_RETURNCMD,
00134 ptPopup.x, ptPopup.y);
00135 if(nSelection != 0)
00136 PostMessage(WM_COMMAND, MAKEWPARAM(nSelection, 0));
00137 } else {
00138 mnuContext.TrackPopupMenuEx(TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_TOPALIGN | TPM_VERTICAL,
00139 ptPopup.x, ptPopup.y, m_hWnd, NULL);
00140 }
00141 }
00142
00143 return 0;
00144 }
00145 LRESULT CHtmlFrame::OnFileSave(WORD , WORD , HWND , BOOL& )
00146 {
00147 MessageBox(_T("OnFileSave"));
00148 return 0;
00149 }
00150 LRESULT CHtmlFrame::OnFileClose(WORD , WORD , HWND , BOOL& )
00151 {
00152 PostMessage(WM_SYSCOMMAND, SC_CLOSE, 0L);
00153 return 0;
00154 }
00155
00157
00158 void CALLBACK CHtmlFrame::OnTitleChange(BSTR sTitle)
00159 {
00160 USES_CONVERSION;
00161 baseClass::SetTitle(OLE2CT(sTitle));
00162 }
00163
00164 void CALLBACK CHtmlFrame::OnNavigateComplete2(IDispatch* pDisp, VARIANT* vtURL)
00165 {
00166 HRESULT hr = S_OK;
00167 CComQIPtr<IWebBrowser2> pBrowser(pDisp);
00168 if(pBrowser) {
00169
00170 CComPtr<IDispatch> pDocument;
00171 hr = pBrowser->get_Document(&pDocument);
00172
00173 CComQIPtr<IHTMLDocument2> pHtmlDocument(pDocument);
00174 if(pHtmlDocument) {
00175 CComPtr<IHTMLLocation> pHtmlLocation;
00176 pHtmlDocument->get_location(&pHtmlLocation);
00177 if(pHtmlLocation) {
00178 CComBSTR sHref;
00179 pHtmlLocation->get_href(&sHref);
00180 if(sHref.Length() > 0) {
00181 USES_CONVERSION;
00182 baseClass::SetTabToolTip(OLE2CT(sHref));
00183 }
00184 }
00185 }
00186 }
00187 }
00188
00189 void CALLBACK CHtmlFrame::OnDocumentComplete(IDispatch* pDisp, VARIANT* vtURL)
00190 {
00191 HRESULT hr = S_OK;
00192 CComQIPtr<IWebBrowser2> pBrowser(pDisp);
00193 if(pBrowser) {
00194
00195 CComPtr<IDispatch> pDocument;
00196 hr = pBrowser->get_Document(&pDocument);
00197
00198 CComQIPtr<IPersistStreamInit> pPersistStreamInit(pDocument);
00199 if(pPersistStreamInit) {
00200 ULARGE_INTEGER cbSize = {0};
00201 pPersistStreamInit->GetSizeMax(&cbSize);
00202
00203 HGLOBAL hGlobal = ::GlobalAlloc(GHND, (DWORD)cbSize.QuadPart);
00204
00205 if(hGlobal != NULL) {
00206 CComPtr<IStream> pStream;
00207 hr = ::CreateStreamOnHGlobal(hGlobal, FALSE, &pStream);
00208 if(pStream) {
00209 hr = pPersistStreamInit->Save(pStream, TRUE);
00210
00211
00212
00213 LPVOID sText = ::GlobalLock(hGlobal);
00214 DWORD cbText = ::GlobalSize(hGlobal);
00215
00216
00217
00218 ::GlobalUnlock(hGlobal);
00219 }
00220
00221 ::GlobalFree(hGlobal);
00222 }
00223 }
00224 }
00225 }