模块的编写及其调用

定义接口文件:

//接口文件:
#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();
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值