Click here to Skip to main content
15,885,141 members
Articles / Desktop Programming / MFC

Exile 1.8 - The Password Manager

Rate me:
Please Sign up or sign in to vote.
4.57/5 (51 votes)
6 Mar 20058 min read 255.1K   7.4K   111  
Yet another password manager.
// hyperlink.cpp : implementation file
//

#include "stdafx.h"
#include "Exile.h"
#include "hyperlink.h"
#include ".\hyperlink.h"


// CHyperlink

IMPLEMENT_DYNAMIC(CHyperlink, CReadonlyEdit)
CHyperlink::CHyperlink()
{
	//
	// Initializing GDI objects
	//	
	m_crHyperlink = RGB(0, 0, 192);

	// Font
	NONCLIENTMETRICS ncm = { 0 };
	ncm.cbSize = sizeof(ncm);
	SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncm, 0);

	LOGFONT lfHyperlink = ncm.lfMessageFont;	
	lfHyperlink.lfUnderline = TRUE;	

	m_fnHyperlink.CreateFontIndirect(&lfHyperlink);

	// Loading cursor
	m_hHand = ::LoadCursor(0, IDC_HAND);
}

CHyperlink::~CHyperlink()
{
	::DeleteObject(m_hHand);
}


BEGIN_MESSAGE_MAP(CHyperlink, CReadonlyEdit)	
	ON_WM_CTLCOLOR_REFLECT()
	ON_WM_SETCURSOR()
	ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()



// CHyperlink message handlers
HBRUSH CHyperlink::CtlColor(CDC* pDC, UINT nCtlColor)
{
	pDC->SetTextColor(m_crHyperlink);
	return GetSysColorBrush(COLOR_WINDOW);
}

void CHyperlink::PreSubclassWindow()
{
	CReadonlyEdit::PreSubclassWindow();

	SetFont(&m_fnHyperlink);
}

BOOL CHyperlink::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
	CPoint ptCursor;
	::GetCursorPos(&ptCursor);
	ScreenToClient(&ptCursor);

	if(PointOverText(ptCursor))
	{
		::SetCursor(m_hHand);
		return TRUE;
	} // if
	
	return CReadonlyEdit::OnSetCursor(pWnd, nHitTest, message);
}

// Returns true if ptPoint (client coordinates) is in text rectangle
BOOL CHyperlink::PointOverText(const CPoint& ptPoint)
{	
	CDC *pDC = GetDC();

	// Dimensions & stuff
	CRect rcClient;
	CSize szText;
	CString strText;
	
	GetClientRect(rcClient);
	GetWindowText(strText);

	CFont *pFont = pDC->SelectObject(GetFont());
	szText = pDC->GetTextExtent(strText);
	pDC->SelectObject(pFont);

	ReleaseDC(pDC);

	return PtInRect(CRect(CPoint(0, 0), szText), ptPoint);
}

void CHyperlink::OnLButtonDown(UINT nFlags, CPoint point)
{
	if(PointOverText(point))
	{
		CString strText;
		GetWindowText(strText);

		::ShellExecute(0, _T("open"), strText, 0, 0, SW_SHOW);

		return;
	} // if

	CReadonlyEdit::OnLButtonDown(nFlags, point);
}

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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Russian Federation Russian Federation
I'll think about it later on...

Comments and Discussions