Click here to Skip to main content
15,884,237 members
Articles / Desktop Programming / WTL

The Psychology of a WTL Project: Lowercase Cause (a typing program)

Rate me:
Please Sign up or sign in to vote.
4.99/5 (32 votes)
20 Apr 200524 min read 63.6K   2.7K   25  
A psychological journey into a project crafted from start to finish.
#pragma once
#include "stdafx.h"
#include "resource.h"
#include "TextTypedCtrl.h"

class CInputDlg : public CDialogImpl<CInputDlg>, public CDialogResize<CInputDlg>
{
public:
	enum { IDD = DLG_INPUT };

	// text is the phrase to display
	// life is how long the dialog will be displayed before "dying" in seconds
	// color is what color we should be faded into
	CInputDlg(const std::string& text, int life, COLORREF color) 
		: _text(text), _life(life), _color(color) {};

	virtual void OnFinalMessage(HWND hWnd);

	BEGIN_MSG_MAP(CInputDlg)
		MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
		MESSAGE_HANDLER(WM_TIMER, OnTimer)
		MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBkgnd)
		MESSAGE_HANDLER(WM_PAINT, OnPaint)
		CHAIN_MSG_MAP(CDialogResize<CInputDlg>)
	END_MSG_MAP()

	BEGIN_DLGRESIZE_MAP(CInputDlg)
		BEGIN_DLGRESIZE_GROUP()
		DLGRESIZE_CONTROL(STC_TARGET, DLSZ_SIZE_X | DLSZ_SIZE_Y)
		DLGRESIZE_CONTROL(STC_INPUT, DLSZ_SIZE_X | DLSZ_SIZE_Y | DLSZ_MOVE_Y)
		END_DLGRESIZE_GROUP()
		DLGRESIZE_CONTROL(PRG_LIFE, DLSZ_MOVE_X | DLSZ_SIZE_Y)
	END_DLGRESIZE_MAP()
	
	LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
	LRESULT OnTimer(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
	LRESULT OnEraseBkgnd(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
	LRESULT OnPaint(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);

	// get the phrase (target) text
	std::string get_text() const { return _text; }

	// set the text that has been typed, we determine what's correct and
	// what's not. correct shows up red (or blue depending on the fade color)
	void set_text(const std::string& text);

	// get the size of dialog based on the phrase before displayed
	CSize get_size();

	// get the full life span given
	int get_life() const { return _life; }

	// get the life that remains
	int get_life_left() const;

	// determine if the life has expired
	bool is_dead() const; 

	// get the time in seconds of how long the dialog has been displayed
	int get_seconds_running() const;

private:
	CTextTypedCtrl _stcTyped;
	CTextTypedCtrl _stcTarget;

	std::string _text; // phrase text 
	int _life; // number of seconds to live
	CTime _start_time; 
	COLORREF _color; // end fade color

	CProgressBarCtrl _prgLife;
};

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
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions