Click here to Skip to main content
15,896,201 members
Articles / Desktop Programming / MFC

Controlling console applications

Rate me:
Please Sign up or sign in to vote.
4.17/5 (9 votes)
4 Feb 2002Ms-PL2 min read 173.4K   3.1K   65  
Run console applications and controll/use their input/output streams
#if !defined(AFX_CMDEDIT_H__8ED74B38_62CF_4629_95A8_2FE88E4F6521__INCLUDED_)
#define AFX_CMDEDIT_H__8ED74B38_62CF_4629_95A8_2FE88E4F6521__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// CmdEdit.h : header file
//
#include "spawn.h"

class CCmdEdit;	
class CSpawnConsumer1;

/////////////////////////////////////////////////////////////////////////////
// CCmdEdit window

class CCmdEdit : public CEdit
{
// Construction
public:
	CCmdEdit();
	
	// Attributes
public:
	
	// Operations
public:
	void	Append(LPCTSTR szText);
	void	AppendRaw(LPCTSTR szText);
	
	// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CCmdEdit)
protected:
	virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
	//}}AFX_VIRTUAL
	
	// Implementation
public:
	virtual ~CCmdEdit();
	
	// Generated message map functions
protected:
	//{{AFX_MSG(CCmdEdit)
	afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg UINT OnGetDlgCode();
	afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
	//}}AFX_MSG
	
	DECLARE_MESSAGE_MAP()
		
	CString					m_strCmd;
	CSpawn					m_Spawn;
	CSpawnConsumer1*		m_pConsumer;
};


class CSpawnConsumer1 : public CSpawnConsumer
{
public:
	CSpawnConsumer1(CCmdEdit* pEdit) {m_pEdit = pEdit;}
	void Consume(TCHAR* p, DWORD)
	{
		m_pEdit->AppendRaw(p);
	}
	
private:
	CCmdEdit* m_pEdit;
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_CMDEDIT_H__8ED74B38_62CF_4629_95A8_2FE88E4F6521__INCLUDED_)

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 Microsoft Public License (Ms-PL)


Written By
Software Developer (Senior)
Portugal Portugal
Software Smith, Blacksmith, Repeat Founder, Austrian, Asgardian.

Comments and Discussions