In this article, you will see my implementation which is similar to the TV's Sleep timer function. You will also see my Media Player plug-in which instead of turning Media Player off after the specified interval of time turns the PC off when the media ends.
|
/////////////////////////////////////////////////////////////////////////////
// #ifndef __ARMEN_H__
// #define __ARMEN_H__//
// Armen Hakobyan, 2005.
// http://www.codeproject.com/script/articles/list_articles.asp?userid=25653
// #endif // __ARMEN_H__
/////////////////////////////////////////////////////////////////////////////
#ifndef __MPST_CONTROLS_H__
#define __MPST_CONTROLS_H__
#if _MSC_VER > 1000
#pragma once
#endif
/////////////////////////////////////////////////////////////////////////////
#include "StdAfx.h"
/////////////////////////////////////////////////////////////////////////////
template < class T, class TBase = ATL::CWindow, class TWinTraits = ATL::CControlWinTraits >
class ATL_NO_VTABLE CWmpHyperLinkImpl : public ATL::CWindowImpl< T, TBase, TWinTraits >
{
public:
HCURSOR m_hCursor;
CToolTipCtrl m_tip;
public: // Constructor/Destructor
CWmpHyperLinkImpl( VOID ) : m_hCursor( NULL )
{
}
public: // Operations
BOOL SubclassWindow( IN HWND hWnd )
{
ATLASSERT( m_hWnd == NULL );
ATLASSERT( ::IsWindow( hWnd ) );
#if ( _MSC_VER >= 1300 )
BOOL bRet = ATL::CWindowImpl< T, TBase, TWinTraits>::SubclassWindow( hWnd );
#else //!(_MSC_VER >= 1300)
typedef ATL::CWindowImpl< T, TBase, TWinTraits> _baseClass;
BOOL bRet = _baseClass::SubclassWindow( hWnd );
#endif //!(_MSC_VER >= 1300)
if( bRet )
{
T* pT = static_cast< T* >( this );
pT->Init();
}
return bRet;
}
public: // Message map and handlers
BEGIN_MSG_MAP( CWmpHyperLinkImpl )
MESSAGE_HANDLER( WM_SETCURSOR, OnSetCursor )
MESSAGE_RANGE_HANDLER( WM_MOUSEFIRST, WM_MOUSELAST, OnMouseMessage )
END_MSG_MAP()
LRESULT OnSetCursor( IN UINT /*uMsg*/, IN WPARAM /*wParam*/, IN LPARAM /*lParam*/, IN OUT BOOL& /*bHandled*/ )
{
::SetCursor( m_hCursor );
return TRUE;
}
LRESULT OnMouseMessage( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled )
{
MSG msg = { m_hWnd, uMsg, wParam, lParam };
if( m_tip.IsWindow() )
m_tip.RelayEvent( &msg );
bHandled = FALSE;
return 1;
}
public: // Implementation
void Init( VOID )
{
ModifyStyle( 0, SS_NOTIFY );
m_hCursor = ::LoadCursor( NULL, IDC_HAND );
ATLASSERT( m_hCursor );
// create a tool tip
if( m_tip.Create( m_hWnd ) )
{
RECT rcClient = { 0 };
GetClientRect( &rcClient );
m_tip.Activate( TRUE );
m_tip.SetMaxTipWidth( 256 ); // IMPORTANT, for multiline tips !!!
m_tip.AddTool(
m_hWnd, GetDlgCtrlID(), &rcClient, 1
);
}
ATLASSERT( m_tip.IsWindow() );
}
};
/////////////////////////////////////////////////////////////////////////////
class CWmpHyperLink : public CWmpHyperLinkImpl< CWmpHyperLink >
{
public:
DECLARE_WND_CLASS( _T( "Wmp_HyperLink" ) )
};
/////////////////////////////////////////////////////////////////////////////
#endif // __MPST_CONTROLS_H__
/////////////////////////////////////////////////////////////////////////////
|
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.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.