共用方式為


IViewProvider::Initialize method

Initializes the application object.

Syntax

HRESULT Initialize(
  [in] ICoreWindow          *window,
  [in] ICoreApplicationView *applicationView
);

Parameters

  • window [in]
    Type: ICoreWindow*

    The window that the application object has created for this view.

  • applicationView [in]
    Type: ICoreApplicationView*

    A pointer to a view object that the application object associates with this new view.

Return value

Type: HRESULT

If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.

Examples

class CMyApplicationView : public RuntimeClass<IViewProvider>
{
    ~CMyApplicationView()
    {
        _spApplicationView->remove_TileActivated(_evtToken);
    }

    HRESULT Initialize(__in IWindow* window,
                       __in IApplicationView* view)
    {
        _spWindow = window;
        _spApplicationView = view;

        return window.As(&_spWindowDispatcher);
    }

    HRESULT Load(HSTRING contentId)
    {
        return _spApplicationView->add_TileActivated(Callback<this,
                     CMyApplicationView::OnTileActivated>, &_evtToken);
    }

    HRESULT Run()
    {
        return _spWindowDispatcher->ProcessEvents();
    }

    HRESULT OnTileActivated(__in IApplication* source,
                            __in ITileEventArgs* ea)
    {
        // Set up code to do drawing here
    }

private:
    ComPtr<IWindow> _spWindow;
    ComPtr<IDispatcher> _spWindowDispatcher;
    ComPtr<IApplicationView> _spApplicationView;
    EventToken _evtToken;
}

Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Header

Windows.ApplicationModel.Core.h

IDL

Windows.ApplicationModel.Core.idl

See also

IViewProvider