Click here to Skip to main content
16,007,858 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralCFormView MDI App. Pin
nimrodel12-Mar-04 17:41
nimrodel12-Mar-04 17:41 
GeneralRe: CFormView MDI App. Pin
Antti Keskinen13-Mar-04 23:05
Antti Keskinen13-Mar-04 23:05 
GeneralRe: CFormView MDI App. Pin
nimrodel14-Mar-04 21:39
nimrodel14-Mar-04 21:39 
Generalsquare-root project Pin
bishead12-Mar-04 17:12
bishead12-Mar-04 17:12 
GeneralRe: square-root project Pin
greba12-Mar-04 17:59
greba12-Mar-04 17:59 
GeneralRe: square-root project Pin
Roger Wright12-Mar-04 18:39
professionalRoger Wright12-Mar-04 18:39 
GeneralAbout MSChart Pin
junli12-Mar-04 15:49
junli12-Mar-04 15:49 
GeneralUsing File Streams with an MFC app Pin
Blue Pyre12-Mar-04 13:11
Blue Pyre12-Mar-04 13:11 
Hi
I've been trying to find a way to create a basic text editor which saves what you've entered in the text box into a text file. I encountered a few errors and problems though....

Firstly, for the user to specify the name of the file it must be of type string to be used in the file name (ofstream file(variable.c_str());). This won't work with CStrings. How could I go about converting a CString to a string?
Secondly, I try to add the "using namespace std;" statement, but no matter where on the page I add it, I still get about 4 errors....

Here's my Pages code:

<code>
// PyreSoft  Text EditorDlg.cpp : implementation file
//

#include <fstream>
#include "stdafx.h"
#include "PyreSoft  Text Editor.h"
#include "PyreSoft  Text EditorDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPyreSoftTextEditorDlg dialog

CPyreSoftTextEditorDlg::CPyreSoftTextEditorDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CPyreSoftTextEditorDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPyreSoftTextEditorDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CPyreSoftTextEditorDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPyreSoftTextEditorDlg)
	DDX_Control(pDX, IDC_FILENAME, m_FileName);
	DDX_Control(pDX, IDC_EDIT_BOX, m_TextBoxString);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CPyreSoftTextEditorDlg, CDialog)
	//{{AFX_MSG_MAP(CPyreSoftTextEditorDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON1, OnSave)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPyreSoftTextEditorDlg message handlers

BOOL CPyreSoftTextEditorDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CPyreSoftTextEditorDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CPyreSoftTextEditorDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CPyreSoftTextEditorDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}



void CPyreSoftTextEditorDlg::OnSave() 
{

	// get an error when I put the using namespace std here,
	// or anywhere else on the page.

	CString FileName;
	CString MainText;

	m_TextBoxString.GetWindowText( MainText );
	m_FileName.GetWindowText( FileName );
	CString JustChecking = FileName + ".txt";

	// Some way to convert to CString to string here
	
	/*

	ofstream file(StringVersionOfFileName.c_str());
	if(!file) AfxMessageBox("Error creating file");
	else {
	file << StringVersionOfMainText;
	}
	file.close();

	*/


}

</code>

GeneralRe: Using File Streams with an MFC app Pin
Michael Dunn12-Mar-04 15:01
sitebuilderMichael Dunn12-Mar-04 15:01 
GeneralRe: Using File Streams with an MFC app Pin
l a u r e n12-Mar-04 20:25
l a u r e n12-Mar-04 20:25 
GeneralRe: Using File Streams with an MFC app Pin
Blue Pyre12-Mar-04 22:52
Blue Pyre12-Mar-04 22:52 
GeneralRe: Using File Streams with an MFC app Pin
Antti Keskinen13-Mar-04 23:09
Antti Keskinen13-Mar-04 23:09 
GeneralFTP and Ident Server :: Winsock Pin
valikac12-Mar-04 10:14
valikac12-Mar-04 10:14 
GeneralRe: FTP and Ident Server :: Winsock Pin
Rob Groves12-Mar-04 11:23
Rob Groves12-Mar-04 11:23 
GeneralRe: FTP and Ident Server :: Winsock Pin
valikac12-Mar-04 12:43
valikac12-Mar-04 12:43 
GeneralSend Print Job Pin
Anonymous12-Mar-04 9:22
Anonymous12-Mar-04 9:22 
GeneralRe: Send Print Job Pin
Rob Groves12-Mar-04 11:32
Rob Groves12-Mar-04 11:32 
Generaledit boxes linking Pin
Oriented12-Mar-04 9:05
Oriented12-Mar-04 9:05 
Generaledit boxes linking Pin
Oriented12-Mar-04 9:02
Oriented12-Mar-04 9:02 
GeneralRe: edit boxes linking Pin
David Crow12-Mar-04 9:29
David Crow12-Mar-04 9:29 
GeneralRe: edit boxes linking Pin
John R. Shaw12-Mar-04 11:56
John R. Shaw12-Mar-04 11:56 
GeneralRe: edit boxes linking Pin
Branislav13-Mar-04 0:27
Branislav13-Mar-04 0:27 
GeneralWin32 TimerQueue problems on DUAL PROCESSORS Pin
Gavin Stark12-Mar-04 8:47
Gavin Stark12-Mar-04 8:47 
GeneralRe: Win32 TimerQueue problems on DUAL PROCESSORS Pin
Mike Dimmick12-Mar-04 8:52
Mike Dimmick12-Mar-04 8:52 
GeneralRe: Win32 TimerQueue problems on DUAL PROCESSORS Pin
Gavin Stark12-Mar-04 11:51
Gavin Stark12-Mar-04 11:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.