#include <windows.h>
#include "cadvsink.h"

extern HWND hMainWnd ;
extern SYSTEMTIME st ;

CAdviseSink::CAdviseSink()
{
	m_RefCount = 1 ;
    return;
}

CAdviseSink::~CAdviseSink(void)
{
    return;
}


STDMETHODIMP CAdviseSink::QueryInterface(REFIID riid, LPVOID *ppv)
{
    if (IsEqualIID(riid, IID_IUnknown)
        || IsEqualIID(riid, IID_IAdviseSink))
    {
	    *ppv = (LPVOID)this;  
        AddRef();
        return S_OK ;
    }
    else
    {
    	*ppv = NULL;       
    	return  ResultFromScode(E_NOINTERFACE) ;
    }
}


STDMETHODIMP_(ULONG) CAdviseSink::AddRef(void)
{
    m_RefCount ++ ;
    return m_RefCount ;
}

STDMETHODIMP_(ULONG) CAdviseSink::Release(void)
{
    ULONG ReleaseCount ;

    m_RefCount -- ;
    ReleaseCount = m_RefCount ;
    
    if (m_RefCount == 0L)
    {   
    	delete this;
    }

    return ReleaseCount ;
}




STDMETHODIMP_(void) CAdviseSink::OnViewChange(DWORD dwAspect, LONG lindex)
{
    return;
}



STDMETHODIMP_(void) CAdviseSink::OnDataChange(LPFORMATETC pFEIn, LPSTGMEDIUM pSTM)
{
	char *cp ;
	MessageBeep (0) ;
	cp = (char *)GlobalLock (pSTM->hGlobal) ;
	memmove (&st, cp, sizeof (st)) ;
	GlobalUnlock (pSTM->hGlobal) ;
	ReleaseStgMedium (pSTM) ;
	InvalidateRect (hMainWnd, NULL, TRUE) ;
    return;
}


STDMETHODIMP_(void) CAdviseSink::OnRename(LPMONIKER pmk)
{
    return;
}

STDMETHODIMP_(void) CAdviseSink::OnSave(void)
{
	return;
}

STDMETHODIMP_(void) CAdviseSink::OnClose(void)
{
    return;
}
