|
#pragma once
#include <connmgr_status.h>
// Bonus!
// This WTL class can be added to any CWindowImpl<> derived Window (as in the
// example below) to be notified of any changes in the connection manager
// status.
//
// class CMyWindow : public CWindowImpl< CMyWindow >,
// // ...
// public CMStatusChangeWindow< CMyWindow >
// {
// public:
// BEGIN_MSG_MAP( CMyWindow )
// // ...
// CHAIN_MSG_MAP( CMStatusChangeWindow< CMyWindow > )
// END_MSG_MAP()
//
// void OnStatusChange( DWORD status )
// {
// // Alert! The Connection Manager status has changed.
// };
// }; // class CMyWindow
//
/// @brief sent by connection manager to indicate a change in status
/// @param WPARAM wParam - [DWORD] new status
/// @param LPARAM lParam - unused.
static const UINT UWM_CM_STATUS_CHANGE =
::RegisterWindowMessage( CONNMGR_STATUS_CHANGE_NOTIFICATION_MSG );
/// A window that listens for connection manager status change notifications
template< class T >
class CMStatusChangeWindow
{
public:
BEGIN_MSG_MAP( CMStatusChangeWindow< T > )
MESSAGE_HANDLER( WM_CREATE, OnCreate )
MESSAGE_HANDLER( UWM_CM_STATUS_CHANGE, OnCMStatusChange )
MESSAGE_HANDLER( WM_DESTROY, OnDestroy )
END_MSG_MAP()
LRESULT OnCreate( UINT /*uMsg*/,
WPARAM /*wParam*/,
LPARAM /*lParam*/,
BOOL& bHandled )
{
bHandled = FALSE;
T* pT = static_cast< T* >( this );
::ConnMgrRegisterForStatusChangeNotification( TRUE, pT->m_hWnd );
return 0;
};
LRESULT OnDestroy( UINT /*uMsg*/,
WPARAM /*wParam*/,
LPARAM /*lParam*/,
BOOL& bHandled )
{
bHandled = FALSE;
T* pT = static_cast< T* >( this );
::ConnMgrRegisterForStatusChangeNotification( FALSE, pT->m_hWnd );
return 0;
};
LRESULT OnCMStatusChange( UINT /*uMsg*/,
WPARAM wParam,
LPARAM /*lParam*/,
BOOL& /*bHandled*/ )
{
T* pT = static_cast< T* >( this );
pT->OnStatusChange( static_cast< DWORD >( wParam ) );
return 0;
};
void OnStatusChange( DWORD status )
{
// must be implemented in a derived class
ASSERT( FALSE );
};
}; // class CMStatusChangeWindow
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.