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

📄 mainwnd.h

📁 wince下internet explorer的浏览器的简单实现
💻 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
#define _MAINWND_H_

#include "mshtmhst.h"

#ifndef NO_FAVORITES
#include "defines.h"
#include "FavStorageIfc.h"
#endif

#define ADDRESSBARWIDTH		250

class CAnimThread;

class CMainWnd :    public IOleContainer,
    public IOleClientSite,
    public IOleInPlaceSite,
    public DWebBrowserEvents2,
    public IDocHostShowUI
{

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 == DIID_DWebBrowserEvents2)
        {
            *ppv = (DWebBrowserEvents2 *)this;
        }
        else if (riid == IID_IDocHostShowUI)
        {
            *ppv = (IDocHostShowUI *)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)
    {
        int nHeight = 0;
        GetClientRect(_hWnd, lprcPosRect);
        GetClientRect(_hWnd, lprcClipRect);

        RECT rc = {0,0,0,0};

#ifndef NOCOMMANDBAR
        GetClientRect(_hWndCmdband, &rc);
        lprcPosRect->top += rc.bottom;
        lprcClipRect->top += rc.bottom;
#endif	//NOCOMMANDBAR

#ifndef NOSTATUSBAR
        GetClientRect(_hWndStatus, &rc);
        lprcPosRect->bottom -= rc.bottom;
        lprcClipRect->bottom -= rc.bottom;
#endif //NOSTATUSBAR

        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;}

    //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);

    
    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;
    }

    BOOL CMainWnd::_LoadBrowserHelperObjects(void);
    
public:
    BOOL                    PreTranslateMessage(LPMSG pMsg);
    VOID                    Close();
    HWND                    GetWindow() {   return _hWnd;}

#ifndef NOCOMMANDBAR
    VOID                    UpdateUrlList(LPCTSTR lpszUrl);
    VOID                    SelChange();
    HWND                    GetCommandBand()    { return _hWndCmdband;}
#endif	//NOCOMMANDBAR

#ifndef NOPRINT
    VOID                    Print();
#endif	//NOPRINT

    HANDLE                  hEvent;

    IWebBrowser2            *_pBrowser;

#ifndef NO_FAVORITES
	UINT				_nNumFavorites;	// current number of favorites
	UINT				_nLastFavoriteID;	// ID number of the last favorite menu item
	IFavStorage*			_pIFavStorage;
#endif


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

protected:

#ifndef NOCOMMANDBAR
    static LRESULT  CALLBACK AddressEditProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
    WNDPROC         _lpfnAddressEditProc;

#endif	//NOCOMMANDBAR

#ifndef NOOPTIONS
    static BOOL     CALLBACK    OptionsDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
#endif

#ifndef NOFIND
    //Added for HTML Find Dialogs
    HRESULT                 FindString();
#endif	//NOFIND


#ifndef NOCOMMANDBAR
    BOOL                    CreateCommandbar();
    LRESULT                 HandleCommand(WPARAM wParam, LPARAM lParam);
    VOID                    ChangeFontSize(WORD wSize);
    VOID                    LoadTypedUrls();
#endif //NOCOMMANDBAR

    BOOL                    RegisterMainWnd();
    HWND                    CreateBrowser();
    HRESULT                 Activate(IOleObject *pObject);
    HRESULT                 InitEvents();

#ifndef NO_FAVORITES
	BOOL					InsertFavoriteIntoMenu(HMENU hMenu, LPTSTR szPath, UINT uID, UINT uPos=FIRST_FAV_MENU_ITEM_POS);
	BOOL					AddMenuItem (HMENU hMenu, UINT &uID, LPCTSTR szText, LPCTSTR szInfo);
	BOOL					DeleteMenuItem (HMENU hMenu, UINT uID);
	HMENU					SetMenuInfo (HMENU hMenu, UINT uID, UINT uPos);
	BOOL					GetUrlFromID(UINT nID, TCHAR* szUrl, UINT nMaxLen);
	UINT					PopulateFavoritesMenu();
	VOID					AddToFavorites();
	VOID					OrganizeFavorites();
	LPTSTR					GetRegistryKeyString(HKEY hKey, LPCTSTR lptValueName);
#endif

#ifndef NOSTATUSBAR
    BOOL                    CreateStatusBar();
#ifdef ZONEDISPLAY
	VOID					UpdateZonePane();
#endif  //ZONEDISPLAY
#endif	//NOSTATUSBAR

public:
    LPTSTR                _lpszUrl;
    BOOL                   _fEmpty;
    
protected:
    HACCEL                  _hAccelTbl;			//a handle to the accelerator table
    HWND                    _hWnd;				//the main window

    ULONG                   _ulRefs;            //reference count for the interfaces supported by the container
    BOOL                    _bInPlaceActive;

    BOOL                    _bTyped;
    HMENU		   _hMenu;
    
#ifndef NOCOMMANDBAR
    HWND                    _hWndCmdband;
    HWND                    _hWndMenuBar;
    HWND                    _hWndAddrBar;
    HWND                    _hWndToolBar;

    HWND                    _hWndAddressCombo;  //the combo box for typed urls
    HWND                    _hWndAddressEdit;   //the edit box of that combo box

    HIMAGELIST           _himlCmdBand;
#endif	//NOCOMMANDBAR

#ifndef	NOSTATUSBAR
    HWND                    _hWndStatus;        //handle to the status bar
    HWND                    _hWndProgress;      //handle to the progress bar
#endif	//NOSTATUSBAR

    HWND                    _hWndBrowser;       //handle to the browser window

    IOleObject              *_pObject;
    IConnectionPoint        *_pCP;
    IOleInPlaceActiveObject *_pIPActiveObj;
    DWORD                   _dwEventCookie;

    TCHAR                   _szTitle[MAXLEN];   //title of the current document
    HWND                    _hwndPrint;			//handle to the print status dialog
    CAnimThread             *_pthrdAnimation;   //the animation thread

#ifndef NOOFFLINE
	BOOL					_fCheckedOffline;
#endif	//NOOFFLINE
};

#endif	//_MAINWND_H_

⌨️ 快捷键说明

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