Skip to main content
GameDev.net gamedev.net
🔒 Locked

Beginner C++ help :(

Started by Liquid Darkness May 24, 2002 at 6:41 PM 10 replies 1.2k views
Original Post
Liquid Darkness
Liquid Darkness
I''ve started learning C++ about a week or so ago and I''m having a problem. I keep getting an error and I dont know why. Here''s the secion of code:
  
void CDay2Dlg::OnCkenblpgm() 
{
	//////////////

	// my code here fo0

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


	// Get the current values from the screen

	UpdateData(TRUE);

	// Is the Enable Message Action check box checked?

	if (m_bCkenblpgm == TRUE)
	{
		// Yes so enable all controls that have anything

		// to do with showing the user message

		GetDlgItem(IDC_RUNPGM)->EnableWindow(TRUE);
		GetDlgItem(IDC_PROGTORUN)->EnableWindow(TRUE);
		GetDlgItem(IDC_STATICPGM)->EnableWindow(TRUE);
	}
	else
	{
		// No, so disable all contrls that have anything

		// to do with showing the user message

		GetDlgItem(IDC_RUNPGM)->EnableWindow(FALSE);
		GetDlgItem(IDC_PROGTORUN)->EnableWindow(FALSE);
		GetDlgItem(IDC_STATICPGM)->EnableWindow(FALSE);
	}
}
  
The error I get is: error C2065: ''m_bCkenblpgm'' : undeclared identifier I did this same process with a seperate chek box and it works fine. I dont understand whats wrong with m_bCkenblpgm. Any help would be great...
=-=-=-=-=-=-=-=-=-=-=-=-----I am a signature virus. Please add me to your signature so that I may multiply.
Liquid Darkness
Liquid Darkness
Yeah sorry.. heres the rest of the code:


  
#include "stdafx.h"
#include "Day2.h"
#include "Day2Dlg.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()

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

// CDay2Dlg dialog


CDay2Dlg::CDay2Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CDay2Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDay2Dlg)

m_strMessage = _T("");
m_strProgToRun = _T("
");
m_bEnableMsg = FALSE;
m_bEnablePgm = FALSE;
m_bShowMsg = FALSE;
m_bShowPgm = FALSE;
//}}AFX_DATA_INIT

// Note that LoadIcon does not require a subsequent DestroyIcon in Win32

m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

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

DDX_Text(pDX, IDC_MSG, m_strMessage);
DDX_CBString(pDX, IDC_PROGTORUN, m_strProgToRun);
DDX_Check(pDX, IDC_CKENBLMSG, m_bEnableMsg);
DDX_Check(pDX, IDC_CKENBLPGM, m_bEnablePgm);
DDX_Check(pDX, IDC_CKSHWMSG, m_bShowMsg);
DDX_Check(pDX, IDC_CKSHWPGM, m_bShowPgm);
//}}AFX_DATA_MAP

}

BEGIN_MESSAGE_MAP(CDay2Dlg, CDialog)
//{{AFX_MSG_MAP(CDay2Dlg)

ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_EXIT, OnExit)
ON_BN_CLICKED(IDC_SHWMSG, OnShwmsg)
ON_BN_CLICKED(IDC_CLRMSG, OnClrmsg)
ON_BN_CLICKED(IDC_CKENBLMSG, OnCkenblmsg)
ON_BN_CLICKED(IDC_CKSHWMSG, OnCkshwmsg)
ON_BN_CLICKED(IDC_RUNPGM, OnRunpgm)
ON_BN_CLICKED(IDC_DFLTMSG, OnDfltmsg)
ON_BN_CLICKED(IDC_CKENBLPGM, OnCkenblpgm)
//}}AFX_MSG_MAP

END_MESSAGE_MAP()

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

// CDay2Dlg message handlers


BOOL CDay2Dlg::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




// Put default message in the message edit

m_strMessage = "
Place a message here";

// set all of the check boxes to checked

m_bShowMsg = TRUE;
m_bShowPgm = TRUE;
m_bEnableMsg = TRUE;
m_bEnablePgm = TRUE;

// Update the dialog with the values

UpdateData(FALSE);

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

}

void CDay2Dlg::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 CDay2Dlg::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(▭);
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 CDay2Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}

void CDay2Dlg::OnExit()
{

// exit the program

OnOK();


}

void CDay2Dlg::OnShwmsg()
{
// Update data with what the user entered

UpdateData(TRUE);

// Display the message for the user

MessageBox(m_strMessage,
"
Here''s your message!");

}

void CDay2Dlg::OnClrmsg()
{
// Clear the message

m_strMessage = "
";

// Update the screen

UpdateData(FALSE);

}

void CDay2Dlg::OnCkenblmsg()
{


// Get the current values from the screen

UpdateData(TRUE);

// Is the Enable Message Action check box checked?

if (m_bEnableMsg == TRUE)
{
// Yes so enable all controls that have anything

// to do with showing the user message

GetDlgItem(IDC_MSG)->EnableWindow(TRUE);
GetDlgItem(IDC_SHWMSG)->EnableWindow(TRUE);
GetDlgItem(IDC_DFLTMSG)->EnableWindow(TRUE);
GetDlgItem(IDC_CLRMSG)->EnableWindow(TRUE);
GetDlgItem(IDC_STATICMSG)->EnableWindow(TRUE);
}
else
{
// No, so disable all contrls that have anything

// to do with showing the user message

GetDlgItem(IDC_MSG)->EnableWindow(FALSE);
GetDlgItem(IDC_SHWMSG)->EnableWindow(FALSE);
GetDlgItem(IDC_DFLTMSG)->EnableWindow(FALSE);
GetDlgItem(IDC_CLRMSG)->EnableWindow(FALSE);
GetDlgItem(IDC_STATICMSG)->EnableWindow(FALSE);
}

}

void CDay2Dlg::OnCkshwmsg()
{

// Get the currecnt values from the screen

UpdateData(TRUE);

// Is the show message checbox action checked?

if (m_bShowMsg == TRUE)
{
// Yes, so sow all controls having to do

// with showing the user message

GetDlgItem(IDC_MSG)->ShowWindow(TRUE);
GetDlgItem(IDC_SHWMSG)->ShowWindow(TRUE);
GetDlgItem(IDC_DFLTMSG)->ShowWindow(TRUE);
GetDlgItem(IDC_CLRMSG)->ShowWindow(TRUE);
GetDlgItem(IDC_STATICMSG)->ShowWindow(TRUE);
}
else
{
// No, so hide all controls having to do

// do with showing the user message

GetDlgItem(IDC_MSG)->ShowWindow(FALSE);
GetDlgItem(IDC_SHWMSG)->ShowWindow(FALSE);
GetDlgItem(IDC_DFLTMSG)->ShowWindow(FALSE);
GetDlgItem(IDC_CLRMSG)->ShowWindow(FALSE);
GetDlgItem(IDC_STATICMSG)->ShowWindow(FALSE);
}

}

void CDay2Dlg::OnRunpgm()
{
// Get the current values from the screen

UpdateData(TRUE);

// Declair a local variable for holding the program name

CString strPgmName;

// copy the program name to the local variable

strPgmName = m_strProgToRun;

// make the program name all upercase

strPgmName.MakeUpper();

//Did user select to run the paint program?

if (strPgmName == "
PAINT")
//Yes run the paint program

WinExec("
pbrush.exe", SW_SHOW);

//Did user select to run the Notepad program?

if (strPgmName == "
NOTEPAD")
//Yes run the notepad program

WinExec("
notepad.exe", SW_SHOW);

//Did user select to run the Solitaire program?

if (strPgmName == "
SOLITAIRE")
//Yes run the solitaire program

WinExec("
sol.exe", SW_SHOW);

//Did user select to run the command prompt?

if (strPgmName == "
COMMAND")
//Yes run the command prompt

WinExec("
command.com", SW_SHOW);

}

void CDay2Dlg::OnDfltmsg()
{
// Clear the message

m_strMessage = "
Enter your message here";

// Update the screen

UpdateData(FALSE);

}

void CDay2Dlg::OnCkenblpgm()
{

// Get the current values from the screen

UpdateData(TRUE);

// Is the Enable Message Action check box checked?

if (m_bCkenblpgm == TRUE)
{
// Yes so enable all controls that have anything

// to do with showing the user message

GetDlgItem(IDC_RUNPGM)->EnableWindow(TRUE);
GetDlgItem(IDC_PROGTORUN)->EnableWindow(TRUE);
GetDlgItem(IDC_STATICPGM)->EnableWindow(TRUE);
}
else
{
// No, so disable all contrls that have anything

// to do with showing the user message

GetDlgItem(IDC_RUNPGM)->EnableWindow(FALSE);
GetDlgItem(IDC_PROGTORUN)->EnableWindow(FALSE);
GetDlgItem(IDC_STATICPGM)->EnableWindow(FALSE);
}


}

=-=-=-=-=-=-=-=-=-=-=-=-----I am a signature virus. Please add me to your signature so that I may multiply.
Pixel_Sticks
Pixel_Sticks
/me beats head against his desk

This sucks!! I must suck, this is a newbie question, it turns out that i am not even a newbie, i am a lower form of life.
I have no idea what is going on in that code. I am "Ultra Newb" my questions are all like, ugh ya, what is the syntax for cout?


"Poor is the pupil that does not surpass the master"
Pipo DeClown
Pipo DeClown
hahha
Me too!
Hey Guy you arent a newb!
That Guy2 just learns from a book!
A Win32 book!
Bet he doesnt know C++ like me and you! ;-)
Isnt that book: Teach yourself Visual C++ in 21 days, or 24 hours?

_________________________________________________________________________
Can someone be nice and help me on my way to be the next Hideo Kojima?
Thought So...
Pipo DeClown
Pipo DeClown
Or does he know everything? hmmmmmmmm...........

_________________________________________________________________________
Can someone be nice and help me on my way to be the next Hideo Kojima?
Thought So...
ACAC
ACAC
Youve been learning C++ for a week! WHOA YOU MUST BE EINTSIEN with that code, no wait? U got it from a book ahhhhhhh

just look in the code and find where its defined. Once you find that look what class its in, then find if its private or public, if its private only its class can access it.. unless u have an accessor function
Gee
Gee
That book certainly doesn''t set good examples of variable names...

I was able to get this out of it:

m_bCkenblpgm = bool Check enable program

I was just alittle supriced a book would use such a bad variable name instead of just m_bProgramEnabled or anything at least readable...

/G
---GUI Programming Division Manager at Wildfire Gamesworking on the 0 A.D. project
Liquid Darkness
Liquid Darkness

lol.. yeah I''m using Visual Studio 6 and learning from "Teach yourself Visual C++ in 21 Days".

I''ve been on gamedev for 2 years now but I hang out in the lounge. I''ve picked up some programming stuff here and there but really, I am a 2d/3d artist. I learned what the book has been teaching me but one of the exercises was to, on my own, write in the code to disable some controls on the window.

I did it just as I did to hide them in earlier code, but for some reason its not working. I really dont know why.
=-=-=-=-=-=-=-=-=-=-=-=-----I am a signature virus. Please add me to your signature so that I may multiply.
Alimonster
Alimonster
It''s probably just a typo - the compiler is saying "I don''t know of anything called m_b..." That either means you typed the name wrong or simply forgot to add that variable to your class.

Oh, and MFC is not a nice way to learn C++! I''d recommend basic console programs first as an easier way to learn (unless you''ve had experience with programming before, or have covered that in your book) or Borland C++ Builder for any GUI stuff. MFC is only good for... well, actually, I''ve not found a use for it yet. I''m sure it''s good for something (in much the same way as, say, the common cold is).
LockePick
LockePick
Wherever you''ve defined the "CDay2Dlg" class, it either a) does not have a variable m_bCkenblpgm, or b) you''ve typed the named wrong (couldn''t blame you =).

I have that book, raced through it and am too scared to look at it again XD
Don''t like how it was set up, overcomplicates everything and gives completely useless examples through most of it...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.