定义接口文件:
//接口文件:
#pragma once
#ifdef IeWeatherPlug__Exports
#define Weather_Api __declspec(dllexport)
#else
#define Weather_Api __declspec(dllimport)
#endif
class IeWeatherPlug
{
public:
virtual BOOL CreateWeatherWnd(HWND hMainWnd) = 0;
virtual void DestroyWeatherWnd() = 0;
virtual void ShowWeatherWnd()=0;
virtual void HideWeatherWnd()=0;
virtual void NetWorkIsConected()=0;
virtual void SetCallBack(void * pFun)=0 ;
virtual HWND GetWeatherWnd()=0;
};
extern "C" Weather_Api IeWeatherPlug* GetWeatherPlug();
模块的stdafx文件:
// stdafx.h
typedef BOOL (*Fun_CallBack)(CString);
extern Fun_CallBack g_CallBackFun;
//stdafx.cpp
Fun_CallBack g_CallBackFun=NULL;
// 接下来的文件就可以这样调用:
(*g_CallBackFun)(strPic);
定义实现类:
#pragma once
#include "ieweatherplug.h"
#include "DlgWeather.h"
class CWeatherPlug :
public IeWeatherPlug
{
public:
CWeatherPlug(void);
virtual ~CWeatherPlug(void);
virtual BOOL CreateWeatherWnd(HWND hMainWnd);
virtual void DestroyWeatherWnd();
virtual void ShowWeatherWnd();
virtual void HideWeatherWnd();
virtual void NetWorkIsConected();
virtual void SetCallBack(void * pFun);
virtual HWND GetWeatherWnd();
CDlgWeather* m_pWeather;
};
实现类的cpp文件:
extern "C" Weather_Api IeWeatherPlug* GetWeatherPlug()
{
static CWeatherPlug Weather;
return &Weather;
}
CWeatherPlug::CWeatherPlug(void)
{
}
CWeatherPlug::~CWeatherPlug(void)
{
}
BOOL CWeatherPlug::CreateWeatherWnd(HWND hMainWnd)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
if( m_pWeather == NULL )
{
m_pWeather = new CDlgWeather();
m_pWeather->SetMainHwnd(hMainWnd);
if( m_pWeather->Create( CDlgWeather::IDD, CWnd::FromHandle( GetDesktopWindow() ) ) )
{
return TRUE;
}
else
return FALSE;
}
return TRUE ;
}
void CWeatherPlug::ShowWeatherWnd()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
if (m_pWeather!=NULL)
{
if (IsWindow(m_pWeather->GetSafeHwnd()))
{
m_pWeather->ShoweWeatherWnd();
}
}
}
void CWeatherPlug::DestroyWeatherWnd()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
if( m_pWeather != NULL )
{
if( ::IsWindow( m_pWeather->GetSafeHwnd() ) )
{
m_pWeather->ShowWindow( SW_HIDE );
m_pWeather->DestroyWindow();
}
delete m_pWeather;
m_pWeather = NULL;
}
}
void CWeatherPlug::SetCallBack( void * pFun )
{
Fun_CallBack CallBack = (Fun_CallBack)pFun ;
g_CallBackFun = CallBack ;
}
HWND CWeatherPlug::GetWeatherWnd()
{
return m_pWeather->GetSafeHwnd() ;
}
// weatherStaticWnd.h
#ifdef WXH_NEW_WEATHER
#include "..\\..\\include\\IeWeatherPlug.h"
#pragma comment(lib,"..\\..\\eWeatherExPlug\\Release\\eWeatherExPlug.lib")
#endif
class CWeatherStaticWnd :
public CStatic ,public IZxRenderUpdate
{
public:
CWeatherStaticWnd(void);
~CWeatherStaticWnd(void);
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnPaint();
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
protected:
virtual void PreSubclassWindow();
};
实现文件:
// cpp文件:
HWND g_Weather_hwnd=NULL ;
CString g_sWeathImgPath;
BOOL RenderWeatherCallBack( CString sWeathImgPath )
{
g_sWeathImgPath=sWeathImgPath ;
::PostMessage(g_Weather_hwnd,WM_UPDATE_WEATHER,0,0);
return TRUE ;
}
void CWeatherStaticWnd::PreSubclassWindow()
{
// TODO: 在此添加专用代码和/或调用基类
g_Weather_hwnd=m_hWnd ;
#ifdef WXH_NEW_WEATHER
GetWeatherPlug()->CreateWeatherWnd(AfxGetMainWnd()->GetSafeHwnd());
GetWeatherPlug()->SetCallBack(RenderWeatherCallBack);
#endif
__super::PreSubclassWindow();
}