// StaticLink.cpp : implementation file
//

#include "stdafx.h"
#include "StaticLink.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CStaticLink

CStaticLink::CStaticLink()
	: m_bUnderline(FALSE)
{
}

CStaticLink::~CStaticLink()
{
}

BEGIN_MESSAGE_MAP(CStaticLink, CStatic)
	ON_WM_CTLCOLOR_REFLECT()
	ON_WM_MOUSEMOVE()
	ON_WM_TIMER()
	ON_CONTROL_REFLECT(BN_CLICKED, OnClicked)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CStaticLink message handlers


void CStaticLink::PreSubclassWindow()
{
	ModifyStyle(0, SS_NOTIFY);
	SetTimer(0, 100, nullptr);
	CStatic::PreSubclassWindow();
}


HBRUSH CStaticLink::CtlColor(CDC *pDC, UINT nCtlColor)
{
	pDC->SetTextColor(::GetSysColor(COLOR_HIGHLIGHT));
	pDC->SetBkColor(::GetSysColor(COLOR_BTNFACE));
	LOGFONT log;
	GetFont()->GetLogFont(&log);
	log.lfUnderline = m_bUnderline;
	CFont font;
	font.CreateFontIndirect(&log);
	pDC->SelectObject(&font);
	//pOldFont->DeleteObject();
	//delete pOldFont;
	// transparent text.
	//pDC->SetBkMode (TRANSPARENT);
	return (HBRUSH)GetStockObject(NULL_BRUSH);
}


void CStaticLink::OnMouseMove(UINT nFlags, CPoint point)
{
	m_bUnderline = TRUE;
	Invalidate(TRUE);
	CStatic::OnMouseMove(nFlags, point);
}


void CStaticLink::OnTimer(UINT_PTR nIDEvent)
{
	CPoint ptCursor;
	GetCursorPos(&ptCursor);
	CRect rcClient;
	GetClientRect(&rcClient);
	ClientToScreen(&rcClient);
	m_bUnderline = rcClient.PtInRect(ptCursor);
	Invalidate(TRUE);
	CStatic::OnTimer(nIDEvent);
}


void CStaticLink::OnClicked()
{
	CString strURL;
	GetWindowText(strURL);
	ShellExecute(nullptr, _T("open"), strURL, nullptr, nullptr, SW_SHOW);
}
