Hello, first I want to say I'm a total noob to C++ and Visual Studio and MFC. Before this I studied Java in school. Anyway I'm required to learn MFC for work and I've been going through a reference book my supervisor has and I've run into an error that google can't seem to solve and I thought I'd try here before tracking down my supervisor for help.

I'm using Visual Studio 2008 and referencing a book called "MFC Programming with Visual C++ 6"

Here's what I'm going by: "Listing 2.1 demonstrates how the constructor is used in the MFCSample application to intialize the m_currentColor member variables." The idea behind the program is to fill a section with a colour chosen with the Colour Picker.

This is their code:

CMFCSampleDlg::CMFCSampleDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMFCSampleDlg::IDD, pParent)
	, m_currentColor(RGB(0,0,255))
	
{
	//{{AFX_DATA_INIT(CMFCSampleDlg)
        m_fileName = _T("");
        //}}AFX_DATA_INIT

        //[omitted code]
}

it continues to state that m_fileName was generated by Visual Studio.

Here's the code I have

CMFCSampleeDlg::CMFCSampleeDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMFCSampleeDlg::IDD, pParent)
	, m_strFile(_T(""))
	//////////////////////
	//MY CODE STARTS HERE
	/////////////////////
	, m_currentColor(RGB(0,0,255))
	/////////////////////
	//MY CODE ENDS HERE
	/////////////////////
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

Ignore the extra 'e' in Sample, I already had a file called MFCSample.

"Listing 2.2 shows the calls to EnableToolTips and DrawBitMapWithColor in the initialization for the MFCSample application

BOOL CMFCSampleDlg::OnInitDialog()
{
    CDialog::OnInitDialog();
    //[omitted code]
    
   //TODO: Add extra initialization here
   EnableToolTips();
   DrawBitmapWithColor();

   return TRUE; //return TRUE unless you set the focus to a control
}

And this is my code, I left out the tooltips.

BOOL CMFCSampleeDlg::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
	/////////////////////
	//MY CODE STARTS HERE
	//////////////////////
	DrawBitmapWithColor();
	////////////////////
	//MY CODE ENDS HERE
	////////////////////
	return TRUE;  // return TRUE  unless you set the focus to a control
}

Please note that in the book this is the first mention of m_currentColor or DrawBitmapWithColor.

And finally the event for the button clicked. It should, bring up the colour picker, let me pick a colour and fill a rectangle with that colour.

void CMFCSampleeDlg::OnBnClickedColour()
{
	// TODO: Add your control notification handler code here
	CColorDialog colorDlg(m_currentColor);
	if(colorDlg.DoModal() == IDOK){
	m_currentColor = colorDlg.GetColor();
	DrawBitmapWithColor();
	}
}

And these are the errors I'm getting:


------ Build started: Project: MFCSamplee, Configuration: Debug Win32 ------
Compiling...
MFCSampleeDlg.cpp
c:\documents and settings\danielle\my documents\visual studio 2008\projects\mfcsamplee\mfcsamplee\mfcsampleedlg.cpp(59) : error C2614: 'CMFCSampleeDlg' : illegal member initialization: 'm_currentColor' is not a base or member
c:\documents and settings\danielle\my documents\visual studio 2008\projects\mfcsamplee\mfcsamplee\mfcsampleedlg.cpp(119) : error C3861: 'DrawBitmapWithColor': identifier not found
c:\documents and settings\danielle\my documents\visual studio 2008\projects\mfcsamplee\mfcsamplee\mfcsampleedlg.cpp(190) : error C2065: 'm_currentColor' : undeclared identifier
c:\documents and settings\danielle\my documents\visual studio 2008\projects\mfcsamplee\mfcsamplee\mfcsampleedlg.cpp(192) : error C2065: 'm_currentColor' : undeclared identifier
c:\documents and settings\danielle\my documents\visual studio 2008\projects\mfcsamplee\mfcsamplee\mfcsampleedlg.cpp(193) : error C3861: 'DrawBitmapWithColor': identifier not found
Build log was saved at "file://c:\Documents and Settings\Danielle\My Documents\Visual Studio 2008\Projects\MFCSamplee\MFCSamplee\Debug\BuildLog.htm"
MFCSamplee - 5 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


I'd appreciate any light you can shead on this for me

>>I'm using Visual Studio 2008 and referencing a book called "MFC Programming with Visual C++ 6"


Get a newer book because MFC changed a lot between VC++ 6.0 and VC++ 2008. The two are not compatible, although you could make it work if you already know MFC well enough. Since you are just starting it would be a lot easier if you just bought a newer book.

Yeah I had that realization as well, it's just a problem of getting to a book store and finding a book that works, this was sort of a last attempt before going and doing just that. Thanks for the reply, any suggestions on a good book to purchase?

Search www.amazon.com for mfc c++ books and pay close attention to when they were published, also check the reviews. Those published within the past two years should be ok.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.