Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

CatchCulator

, 18 Oct 2005 CPOL
A tool used to catch and combine values output by different applications.
catchculator_demo.zip
TestValues2.exe
TestValues1.exe
CatchCulator.exe
catchculator_sourcecode.zip
CatchCulator.clw
CatchCulator.dsp
CatchCulator.dsw
res
bitmap1.bmp
bmp00001.bmp
bmp00002.bmp
bmp00003.bmp
bmp00004.bmp
bmp00005.bmp
bmp00006.bmp
bmp00007.bmp
bmp00008.bmp
bmp00009.bmp
bmp00010.bmp
CatchCulator.ico
catchd1.bmp
catchu1.bmp
catchu2.bmp
catchu3.bmp
d1u1.bmp
d1u2.bmp
d1u3.bmp
d2u1.bmp
d2u2.bmp
d2u3.bmp
d3u1.bmp
d3u2.bmp
d3u3.bmp
delitemu.bmp
delu1.bmp
delu2.bmp
delu3.bmp
display_1.bmp
display_2.bmp
display_3.bmp
grad.bmp
settimer.bmp
timerset.bmp
timeru2.bmp
timeru3.bmp
// CatchDlg.cpp : implementation file
//

#include "stdafx.h"
#include "CatchCulator.h"
#include "CatchDlg.h"

#include "CatchCulatorDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CCatchDlg dialog


CCatchDlg::CCatchDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CCatchDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CCatchDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	m_colorBkGnd = RGB(186, 198, 179);
	m_brushBkGnd.CreateSolidBrush(m_colorBkGnd);
	m_hMonitoredWnd = NULL;
}


void CCatchDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCatchDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CCatchDlg, CDialog)
	//{{AFX_MSG_MAP(CCatchDlg)
	ON_WM_CTLCOLOR()
	ON_BN_CLICKED(IDC_BUTTON_TRY, OnButtonTry)
	ON_BN_CLICKED(IDC_BUTTON_HIDE, OnButtonHide)
	ON_BN_CLICKED(IDC_BUTTON_CATCH, OnButtonCatch)
	ON_WM_DESTROY()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCatchDlg message handlers

HBRUSH CCatchDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

	if ( nCtlColor != CTLCOLOR_EDIT)
	{
		hbr = (HBRUSH)m_brushBkGnd.GetSafeHandle();
		pDC->SetBkColor(m_colorBkGnd);
	}
	return hbr;
}

BOOL CCatchDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	CRect	rcThis;
	CRgn	rgnAux;
	CPoint	ptArea[7];
	int		w, h;

	// Set the window region
	GetWindowRect(&rcThis);
	w = rcThis.Width();
	h = rcThis.Height() + 20;
	ScreenToClient(&rcThis);
	rcThis.bottom = rcThis.top + h;
	rcThis.right += 2;
	if ( m_rgnClip.GetSafeHandle() ) m_rgnClip.DeleteObject();
	m_rgnClip.CreateRectRgn(rcThis.left, rcThis.top, rcThis.right, rcThis.bottom);
	ptArea[0].x = 0;						ptArea[0].y = 0;
	ptArea[1].x = ptArea[0].x + w / 2 + 6;	ptArea[1].y = ptArea[0].y;
	ptArea[2].x = ptArea[0].x;				ptArea[2].y = ptArea[0].y + 20;
	rgnAux.CreatePolygonRgn(ptArea, 3, ALTERNATE);
	m_rgnClip.CombineRgn(&m_rgnClip, &rgnAux, RGN_DIFF);
	rgnAux.DeleteObject();
	ptArea[0].x = w;						ptArea[0].y = 0;
	ptArea[1].x = ptArea[0].x - w / 2 - 6;	ptArea[1].y = ptArea[0].y;
	ptArea[2].x = ptArea[0].x;				ptArea[2].y = ptArea[0].y + 20;
	rgnAux.CreatePolygonRgn(ptArea, 3, ALTERNATE);
	m_rgnClip.CombineRgn(&m_rgnClip, &rgnAux, RGN_DIFF);
	rgnAux.DeleteObject();
	SetWindowRgn((HRGN)m_rgnClip.GetSafeHandle(), TRUE);
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CCatchDlg::OnButtonTry() 
{
	// TODO: Add your control notification handler code here
	CEdit		*pE = (CEdit *)GetDlgItem(IDC_EDIT_TRY);
	CEdit		*pEdit;
	CRect		rcThis;
	CPoint		ptAt;
	HWND		hParent;
	CString		strText;
	char		chText[256];
	int			N;

	GetWindowRect(&rcThis);
	m_ptPosition.x = rcThis.left + rcThis.Width() / 2;
	m_ptPosition.y = rcThis.top;
	ptAt = m_ptPosition;
	ptAt = ptAt + CPoint(0, -1);
	hParent = ::WindowFromPoint(ptAt);
	if ( hParent )
	{
		m_hMonitoredWnd = hParent;
		::GetWindowText(hParent, chText, 255);
		strText = chText;
		if ( strText == "" )
		{
			// This may be a CEdit control, so try to get its first line
			pEdit = (CEdit *)FromHandle(hParent);
			N = pEdit->GetLine(0, chText, 255);
			chText[N] = 0; // null termination
			strText = chText;
		}
		if ( pE ) pE->SetWindowText(chText);
	}
}

void CCatchDlg::ShowHiddenWindows()
{
	HWND		hWnd;
	POSITION	pos;
	
	if ( !m_listHiddenWnd.IsEmpty() )
	{
		pos = m_listHiddenWnd.GetTailPosition();
		while ( pos )
		{
			hWnd = m_listHiddenWnd.GetPrev(pos);
			if ( ::IsWindow(hWnd) ) ::ShowWindow(hWnd, SW_SHOW);
		}
		// Empty the list of hidden windows
		m_listHiddenWnd.RemoveAll();
	}
}

void CCatchDlg::OnDestroy() 
{
	CDialog::OnDestroy();
	
	// TODO: Show any previously hidden windows (if any)
	ShowHiddenWindows();
}

void CCatchDlg::OnOK() 
{
	// TODO: Show any previously hidden windows (if any)
	ShowHiddenWindows();
	
	CDialog::OnOK();
}

void CCatchDlg::OnButtonHide() 
{
	// TODO: Add your control notification handler code here
	OnButtonTry(); // first try to get the handle of what we actually want to hide
	if ( ::IsWindow(m_hMonitoredWnd) ) 
	{
		// Add the window handle to the list
		m_listHiddenWnd.AddTail(m_hMonitoredWnd);
		// Hide the window
		::ShowWindow(m_hMonitoredWnd, SW_HIDE);
	}
}

void CCatchDlg::OnButtonCatch() 
{
	// TODO: Add your control notification handler code here
	CCatchCulatorDlg	*pMain;
	HWND				hWnd;
	POSITION			pos;
	HTREEITEM			hItem;
	char				chText[256];
	unsigned int		N;

	// Show the caught content
	OnButtonTry();
	// Add the handler to the list of catched windows in the main dialog
	pMain = (CCatchCulatorDlg *)AfxGetMainWnd();
	if ( !pMain ) return; // should not be the case
	N = pMain->m_treeCatches.GetCount() + 1;
	sprintf(chText, "Name %u", N);
	hItem = pMain->m_treeCatches.InsertItem(chText);
	if ( hItem ) pMain->m_treeCatches.SetItemData(hItem, (DWORD)m_hMonitoredWnd);
	// Show any previously hidden windows (if any)
	if ( !m_listHiddenWnd.IsEmpty() )
	{
		pos = m_listHiddenWnd.GetTailPosition();
		while ( pos )
		{
			hWnd = m_listHiddenWnd.GetPrev(pos);
			if ( ::IsWindow(hWnd) ) ::ShowWindow(hWnd, SW_SHOW);
		}
		// Empty the list of hidden windows
		m_listHiddenWnd.RemoveAll();
	}
}

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Mircea Puiu
Software Developer (Senior)
Europe Europe
More than 22 years of software development experience.
SCRUM Master nowadays

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141223.1 | Last Updated 18 Oct 2005
Article Copyright 2005 by Mircea Puiu
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid