DDX problem
//How to make Anya happy v0.01
#include
#include
#include "dialog.h"
#include "ids.h"
int cbstatus1=0, cbstatus2=0; //status of checkboxes
int rbstatus1=1, rbstatus2=0; //status of radio buttons
CMainWin::CMainWin()
{
Create(NULL, "How to make Anya happy v0.01", WS_OVERLAPPEDWINDOW, rectDefault,
NULL, "DialogMenu");
//accelerator table
if(!LoadAccelTable("DialogMenu"))
MessageBox("Cannot load accelerators", "Error");
}
//init app
BOOL CApp::InitInstance()
{
m_pMainWnd = new CMainWin;
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}
// apps message map
BEGIN_MESSAGE_MAP(CMainWin, CFrameWnd)
ON_COMMAND(IDM_DIALOG, OnDialog)
ON_COMMAND(IDM_STATUS, OnStatus)
ON_COMMAND(IDM_EXIT, OnExit)
ON_COMMAND(IDM_HELP, OnHelp)
END_MESSAGE_MAP()
//process IDM_DIALOG
afx_msg void CMainWin::OnDialog()
{
CSampleDialog diagOb("SampleDialog", this);
diagOb.m_check1Val = cbstatus1;
diagOb.m_check2Val = cbstatus2;
diagOb.m_radio1Val = rbstatus1;
diagOb.m_radio2Val = rbstatus2;
diagOb.DoModal (); //activate box
}
//process IDM_STATUS
afx_msg void CMainWin::OnStatus()
{
char str[255];
if(cbstatus1)
wsprintf(str, "Anya says, MMM I LOVE CHOCOLATE \n");
else
wsprintf(str, "Anya says, YOU DID NOT BUT ME SOMETHING SWEET!! \n");
if(cbstatus2)
strcat(str, "Anya says, FOO! I HATE TUNA! \n");
else
strcat(str, "Anya says, I AM A RABBIT!! \n");
if(rbstatus1)
strcat(str, "Anya says, I NEED MORE CANDY");
else
strcat(str, "Anya says, I STILL NEED MORE CANDY!!");
MessageBox(str, "Anya''s comments");
}
//process IDM_EXIT
afx_msg void CMainWin::OnExit()
{
int response;
response = MessageBox("Quit the program?", "Exit", MB_YESNO);
if(response == IDYES)
SendMessage(WM_CLOSE);
}
//Process IDM_HELP
afx_msg void CMainWin::OnHelp()
{
MessageBox("How to make Anya happy v0.001", "About");
}
//sample diags message map
BEGIN_MESSAGE_MAP(CSampleDialog, CDialog)
END_MESSAGE_MAP()
//transfer check box info
void CSampleDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Check(pDX, IDD_CB1, m_check1Val);
DDX_Check(pDX, IDD_CB2, m_check2Val);
//DDX_Radio(pDX, IDD_RB1, m_radio1Val);
//DDX_Radio(pDX, IDD_RB2, m_radio2Val);
}
// handle IDOK expl
afx_msg void CSampleDialog::OnOK()
{
CDialog::OnOK();
cbstatus1 = m_check1Val;
cbstatus2 = m_check2Val;
rbstatus1 = m_radio1Val;
rbstatus2 = m_radio2Val;
EndDialog(IDOK);
}
CApp App;
the problem is in the remed out part where the radio button data exchange occurs
//transfer check box info
void CSampleDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Check(pDX, IDD_CB1, m_check1Val);
DDX_Check(pDX, IDD_CB2, m_check2Val);
//DDX_Radio(pDX, IDD_RB1, m_radio1Val);
//DDX_Radio(pDX, IDD_RB2, m_radio2Val);
}
it crashes in this function.. I have no idea what to do
I treated the DDX_radio function just like the DDX_Check function
//transfer check box info
void CSampleDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Check(pDX, IDD_CB1, m_check1Val);
DDX_Check(pDX, IDD_CB2, m_check2Val);
//DDX_Radio(pDX, IDD_RB1, m_radio1Val);
//DDX_Radio(pDX, IDD_RB2, m_radio2Val);
}
it crashes in this function.. I have no idea what to do
I treated the DDX_radio function just like the DDX_Check function
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement