⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainwnd.h

📁 Windows CE 下的机顶盒应用实例
💻 H
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.

Module Name:  mainwnd.h

Abstract:  Implements the main window, the container for the webbrowser

Functions:

Notes: This class implements the container and its interaction with the webbrowser control,
        commandbar, statusbar etc.

--*/

#ifndef _MAINWND_H_46C56CA3_9572_49B2_8A73_CD2D47492C8C_
#define _MAINWND_H_46C56CA3_9572_49B2_8A73_CD2D47492C8C_

#include "mshtmhst.h"
#include "interned.h"

#define MAX_URL  2048

class CMainWnd : 
	public IOleContainer,
	public IOleClientSite,
	public IOleInPlaceSite,
	public IServiceProvider,
	public DWebBrowserEvents2,
	public IDocHostUIHandler,
	public IDocHostShowUI,			// msgbox, help window
	public IHTMLOMWindowServices	// for window move, resize events
{

	friend class CHostExternal;
	friend class CRCtlKeys;

public:
	CMainWnd();
	~CMainWnd();

	BOOL Create();

	//IUnknown methods
	STDMETHOD(QueryInterface) (REFIID riid, LPVOID * ppv)
	{
		if ((riid == IID_IOleContainer) || (riid == IID_IUnknown))
		{
			*ppv = (IOleContainer *) this;
		}
		else if (riid == IID_IOleClientSite)
		{
			*ppv = (IOleClientSite *)this;
		}
		else if (riid == IID_IOleInPlaceSite)
		{
			*ppv = (IOleInPlaceSite *)this;
		}
		else if (riid == IID_IOleWindow)
		{
			*ppv = (IOleWindow *)this;
		}
		else if ((riid == DIID_DWebBrowserEvents2) || (riid == IID_IDispatch))
		{
			*ppv = (DWebBrowserEvents2 *)this;
		}
		else if(riid == IID_IServiceProvider)
		{
		*ppv = (IServiceProvider *)this;
		}
		else if (riid == IID_IDocHostUIHandler)
		{
			*ppv = (IDocHostUIHandler *)this;
		}
		else if (riid == IID_IDocHostShowUI)
		{
			*ppv = (IDocHostShowUI *)this;
		}
		else if (riid == IID_IHTMLOMWindowServices)
		{
			*ppv = (IHTMLOMWindowServices *)this;
		}
		else
		{
			*ppv = NULL;
			return E_NOINTERFACE;
		}
		AddRef();
		return S_OK;
	}

	STDMETHOD_(ULONG, AddRef) (void)
	{
		InterlockedIncrement((LONG*)&_ulRefs);
		return _ulRefs;
	}

	STDMETHOD_(ULONG, Release) (void)
	{
		ULONG ulRefs = _ulRefs;
		if (InterlockedDecrement((LONG*)&_ulRefs) == 0)
		{
			delete this;
			return 0;
		}
		return ulRefs - 1;
	}

	// IOleContainer methods
	STDMETHOD(ParseDisplayName)(IBindCtx *, LPOLESTR, ULONG *, IMoniker **) { return E_NOTIMPL;}
	STDMETHOD(EnumObjects)(DWORD, IEnumUnknown **) { return E_NOTIMPL;}
	STDMETHOD(LockContainer)(BOOL) { return S_OK;}

	// IOleClientSite methods
	STDMETHOD(SaveObject) (void) { return E_NOTIMPL;}	
	STDMETHOD(GetMoniker) (DWORD dwAssign, DWORD dwWhichMoniker, LPMONIKER * ppmk) { return E_NOTIMPL;}
	STDMETHOD(GetContainer) (LPOLECONTAINER * ppContainer) { return E_NOINTERFACE;}
	STDMETHOD(ShowObject) (void) { return E_NOTIMPL;}
	STDMETHOD(OnShowWindow) (BOOL fShow) { return E_NOTIMPL;}
	STDMETHOD(RequestNewObjectLayout) (void) { return E_NOTIMPL;}

	// IOleWindow methods
	STDMETHOD(GetWindow)(HWND *phwnd)
	{
		*phwnd = _hWnd;
		return S_OK;
	}
	STDMETHOD(ContextSensitiveHelp)(BOOL fEnterMode) { return E_NOTIMPL;}

	// IOleInPlaceSite methods
	STDMETHOD(CanInPlaceActivate) (void) { return S_OK;}
	STDMETHOD(OnInPlaceActivate) (void)
	{
		_bInPlaceActive = TRUE;
		return S_OK;
	}

	STDMETHOD(OnUIActivate) (void) { return E_NOTIMPL;}
	STDMETHOD(GetWindowContext) (LPOLEINPLACEFRAME FAR *	lplpFrame,
								 LPOLEINPLACEUIWINDOW FAR *	lplpDoc,
								 LPRECT						lprcPosRect,
								 LPRECT						lprcClipRect,
								 LPOLEINPLACEFRAMEINFO		lpFrameInfo)
	{
		GetClientRect(_hWnd, lprcPosRect);
		GetClientRect(_hWnd, lprcClipRect);
		return S_OK;
	}

	STDMETHOD(Scroll) (SIZE scrollExtent) { return E_NOTIMPL;}
	STDMETHOD(OnUIDeactivate) (BOOL fUndoable) { return E_NOTIMPL;}
	STDMETHOD(OnInPlaceDeactivate) (void)
	{
		_bInPlaceActive = FALSE;
		return S_OK;
	}

	STDMETHOD(DiscardUndoState) (void) { return E_NOTIMPL;}
	STDMETHOD(DeactivateAndUndo) (void) { return E_NOTIMPL;}
	STDMETHOD(OnPosRectChange) (LPCRECT lprcPosRect) { return E_NOTIMPL;}

	// IServiceProvider
	STDMETHOD(QueryService)(REFGUID guidService, REFIID riid, void **ppvObj)
	{
		if(guidService == IID_IHTMLOMWindowServices)
		{
			return QueryInterface(riid, ppvObj);
		}
		else
			return E_FAIL;
	}

	//DWebBrowserEvents
	//IDispatch methods
	STDMETHOD(GetTypeInfoCount)(UINT FAR* pctinfo) { return E_NOTIMPL;}
	STDMETHOD(GetTypeInfo)(UINT itinfo,LCID lcid,ITypeInfo FAR* FAR* pptinfo) { return E_NOTIMPL;}
	STDMETHOD(GetIDsOfNames)(REFIID riid,OLECHAR FAR* FAR* rgszNames,UINT cNames,
							 LCID lcid, DISPID FAR* rgdispid)
							 { return E_NOTIMPL;}
	STDMETHOD(Invoke)(DISPID dispidMember,REFIID riid,LCID lcid,WORD wFlags,
					  DISPPARAMS FAR* pdispparams, VARIANT FAR* pvarResult,
					  EXCEPINFO FAR* pexcepinfo,UINT FAR* puArgErr);

	// IDocHostUIHandler methods
	STDMETHOD(EnableModeless)(BOOL fEnable) { return E_NOTIMPL; }
	STDMETHOD(FilterDataObject)(IDataObject *pDO, IDataObject **ppDORet) { return E_NOTIMPL; }
	STDMETHOD(GetDropTarget)(IDropTarget *pDropTarget, IDropTarget **ppDropTarget) { return E_NOTIMPL; }
	STDMETHOD(GetExternal)(IDispatch **ppDispatch);
	STDMETHOD(GetHostInfo)(DOCHOSTUIINFO *pInfo);
	STDMETHOD(GetOptionKeyPath)(LPOLESTR *pchKey, DWORD dw) { return E_NOTIMPL; }
	STDMETHOD(HideUI)(void) { return E_NOTIMPL; }
	STDMETHOD(OnDocWindowActivate)(BOOL fActivate) { return E_NOTIMPL; }
	STDMETHOD(OnFrameWindowActivate)(BOOL fActivate) { return E_NOTIMPL; }
	STDMETHOD(ResizeBorder)(LPCRECT prcBorder, IOleInPlaceUIWindow *pUIWindow, BOOL fFrameWindow) { return E_NOTIMPL; }
	STDMETHOD(ShowContextMenu)(DWORD dwID, POINT *ppt, IUnknown *pcmdtReserved, IDispatch *pdispReserved) { return E_NOTIMPL; }
	STDMETHOD(ShowUI)(DWORD dwID, IOleInPlaceActiveObject *pActiveObject,
					  IOleCommandTarget *pCommandTarget, IOleInPlaceFrame *pFrame,
					  IOleInPlaceUIWindow *pDoc)
					  { return E_NOTIMPL; }
	STDMETHOD(TranslateAccelerator)(LPMSG lpMsg, const GUID *pgudCmdGroup, DWORD nCmdID) { return E_NOTIMPL; }
	STDMETHOD(TranslateUrl)(DWORD dwTranslate, OLECHAR *pchURLIn, OLECHAR **ppchURLOut) { return E_NOTIMPL; }
	STDMETHOD(UpdateUI)(void) { return E_NOTIMPL; }

	// IDocHostShowUI methods
	STDMETHOD(ShowHelp)(HWND hwnd, LPOLESTR pszHelpFile, UINT uCommand,
						DWORD dwData, POINT ptMouse, IDispatch *pDispatchObjectHit)
						{ return E_NOTIMPL; }

	STDMETHOD(ShowMessage)( HWND hwnd, LPOLESTR lpstrText, LPOLESTR lpstrCaption, DWORD dwType,
							LPOLESTR lpstrHelpFile, DWORD dwHelpContext, LRESULT *plResult)
	{
		int res = MessageBox(hwnd, lpstrText, lpstrCaption, dwType);
		if (plResult)
			*plResult = res;
		return S_OK;
	}

	// IHTMLOMWindowServices methods
	STDMETHOD(moveTo)( LONG x, LONG y);     
	STDMETHOD(moveBy)( LONG x, LONG y);
	STDMETHOD(resizeTo)( LONG x,LONG y);
	STDMETHOD(resizeBy)( LONG x, LONG y);

public:
	BOOL PreTranslateMessage(LPMSG pMsg);
	VOID Close();
	HWND GetWindow() {return _hWnd;}
	LRESULT HandleCommand(WPARAM wParam, LPARAM lParam);

	HANDLE hEvent;
	IWebBrowser2 *_pBrowser;

	static LRESULT CALLBACK MainWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);

protected:
    //Added for HTML Find Dialogs
	HRESULT FindString();
	VOID CMainWnd::ChangeFontSize(BOOL fInit);
	BOOL RegisterMainWnd();
	HWND CreateBrowser();
	HRESULT Activate(IOleObject *pObject);
	HRESULT InitEvents();
	BOOL EnableSafeArea(BOOL fEnable);
	BOOL AssignAccelerator(ACCEL accel, SHORT nKey);
	BOOL CreateAccelTbl(ULONG bmKeys);
	BOOL DestroyAccelTbl();

public:
	LPTSTR _lpszUrl;
	BOOL _fEmpty;

protected:
	RECT _rcWnd;
	HACCEL _hAccelTblDef;		// a handle to the default accelerator table
	HACCEL _hAccelTblNew;		// handle to accelerator table that temporarily overrides default
	HWND _hWnd;					// the main window
	ULONG _ulRefs;				// reference count for the interfaces supported by the container
	HWND _hWndBrowser;			//handle to the browser window
	RECT _rcBrowser;
	IOleObject *_pObject;
	IConnectionPoint *_pCP;
	IOleInPlaceActiveObject *_pIPActiveObj;
	BOOL _bInPlaceActive;
	DWORD _dwEventCookie;
	TCHAR _szTitle[MAX_URL];	//title of the current document
	HWND _hwndProgress;			// progress bar
	RECT _rcProgress;
	int _wZoom;
	int _wDLCCounter;
	BOOL _fSafeArea;			// whether or not safe area is in use
	LONG _lSafeWidth;			// width of TV safe area
	LONG _lSafeHeight;			// height of TV safe area
	POINT _ptSafe;				// coordinates of safe areas upper left corner
	IUnknown* _pUnkExternal;	// pointer to window.external object's IUnknown
	int _cNewAccels;			// size of _rgNewAccels below
	LPACCEL _rgNewAccels;		// array of new ACCEL structures to override default accelerator table
	BOOL _fUseNewAccels;		// whether to override default accelerator table

};

#endif	// _MAINWND_H_46C56CA3_9572_49B2_8A73_CD2D47492C8C_

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -