00001
00002
00003
00004
00005
00006 #include "stdafx.h"
00007 #include "FdmApp.h"
00008 #include "fsShellWindowsEvents.h"
00009
00010 #ifdef _DEBUG
00011 #define new DEBUG_NEW
00012 #undef THIS_FILE
00013 static char THIS_FILE[] = __FILE__;
00014 #endif
00015
00016 IMPLEMENT_DYNCREATE(fsShellWindowsEvents, CCmdTarget)
00017
00018 fsShellWindowsEvents::fsShellWindowsEvents()
00019 {
00020 m_pConnPt = NULL;
00021 m_pfnEvents = NULL;
00022 EnableAutomation ();
00023 }
00024
00025 fsShellWindowsEvents::~fsShellWindowsEvents()
00026 {
00027 Detach ();
00028 }
00029
00030 BEGIN_MESSAGE_MAP(fsShellWindowsEvents, CCmdTarget)
00031
00032
00033
00034 END_MESSAGE_MAP()
00035
00036 BEGIN_DISPATCH_MAP(fsShellWindowsEvents, CCmdTarget)
00037 DISP_FUNCTION_ID(fsShellWindowsEvents, "WindowRegistered",DISPID_WINDOWREGISTERED,OnWindowRegistered,VT_EMPTY,VTS_I4)
00038 DISP_FUNCTION_ID(fsShellWindowsEvents, "WindowRevoked",DISPID_WINDOWREVOKED,OnWindowRevoked,VT_EMPTY,VTS_I4)
00039 END_DISPATCH_MAP()
00040
00041 HRESULT fsShellWindowsEvents::Attach(SHDocVw::IShellWindowsPtr& spSHWnds)
00042 {
00043 LPCONNECTIONPOINTCONTAINER pConnPtContr;
00044 HRESULT hr;
00045
00046 hr = spSHWnds->QueryInterface (IID_IConnectionPointContainer, (LPVOID*) &pConnPtContr);
00047 if (FAILED (hr))
00048 return hr;
00049
00050 hr = pConnPtContr->FindConnectionPoint (__uuidof (SHDocVw::DShellWindowsEvents), &m_pConnPt);
00051 if (FAILED (hr))
00052 {
00053 pConnPtContr->Release ();
00054 return hr;
00055 }
00056
00057 hr = m_pConnPt->Advise (GetIDispatch (FALSE), &m_dwCookie);
00058
00059 pConnPtContr->Release ();
00060
00061 return S_OK;
00062 }
00063
00064 void fsShellWindowsEvents::Detach()
00065 {
00066 try {
00067 if (m_pConnPt)
00068 {
00069 m_pConnPt->Unadvise (m_dwCookie);
00070 m_pConnPt->Release ();
00071 m_pConnPt = NULL;
00072 }
00073 }catch (...){}
00074 }
00075
00076 void fsShellWindowsEvents::OnWindowRegistered(long lCookie)
00077 {
00078 if (m_pfnEvents)
00079 m_pfnEvents (SWE_WINDOWOPENED, m_lpEventsParam);
00080 }
00081
00082 void fsShellWindowsEvents::OnWindowRevoked(long lCookie)
00083 {
00084 if (m_pfnEvents)
00085 m_pfnEvents (SWE_WINDOWCLOSED, m_lpEventsParam);
00086 }
00087
00088 void fsShellWindowsEvents::SetEventFunc(fntSHWindowsEvents pfn, LPVOID lpParam)
00089 {
00090 m_pfnEvents = pfn;
00091 m_lpEventsParam = lpParam;
00092 }