Tuesday, February 23, 2010

MFCCheckBoxDemo

#include
#include "resource.h"

class myDialog : public CDialog
{
protected:
int checkStatus1, checkStatus2;
public:
BOOL OnInitDialog()
{
CButton *myButton = (CButton *)GetDlgItem(IDC_CHECK1);
myButton->SetCheck(1);
checkStatus1 = 1;
checkStatus2 = 0;
return TRUE;
}

myDialog():CDialog(IDD_DIALOG1) //Creating Modal dialogbox
{
}

void OnOK()
{
char str[80];

if(checkStatus1)
wsprintf(str, "Check1 is checked.\n");
else
wsprintf(str, "Check1 is not checked.\n");

if(checkStatus2)
strcat(str, "Check2 is checked.");
else
strcat(str, "Check2 is not checked.");

MessageBox(str, "Check Status");

EndDialog(TRUE);
}
void OnCancel()
{
MessageBox("Cancel Clicked", "Model Dialogbox");
}

void OnClick1()
{
CButton *myButton = (CButton *)GetDlgItem(IDC_CHECK1);
checkStatus1 = myButton->GetCheck();
}
void OnClick2()
{
CButton *myButton = (CButton *)GetDlgItem(IDC_CHECK2);
checkStatus2 = myButton->GetCheck();
}
DECLARE_MESSAGE_MAP()
};

BEGIN_MESSAGE_MAP(myDialog, CDialog)
ON_COMMAND(IDOK, OnOK)
ON_COMMAND(IDCANCEL, OnCancel)
ON_COMMAND(IDCANCEL, OnCancel)
ON_BN_CLICKED(IDC_CHECK1, OnClick1)
ON_BN_CLICKED(IDC_CHECK2, OnClick2)

END_MESSAGE_MAP()

void DisplayDialog()
{
myDialog a;
a.DoModal();
}

class MyApp : public CWinApp
{
public:
BOOL InitInstance();
};


BOOL MyApp::InitInstance()
{
DisplayDialog();
return TRUE;
}

MyApp ApplicationObject;#include
#include "resource.h"

class myDialog : public CDialog
{
protected:
int checkStatus1, checkStatus2;
public:
BOOL OnInitDialog()
{
CButton *myButton = (CButton *)GetDlgItem(IDC_CHECK1);
myButton->SetCheck(1);
checkStatus1 = 1;
checkStatus2 = 0;
return TRUE;
}

myDialog():CDialog(IDD_DIALOG1) //Creating Modal dialogbox
{
}

void OnOK()
{
char str[80];

if(checkStatus1)
wsprintf(str, "Check1 is checked.\n");
else
wsprintf(str, "Check1 is not checked.\n");

if(checkStatus2)
strcat(str, "Check2 is checked.");
else
strcat(str, "Check2 is not checked.");

MessageBox(str, "Check Status");

EndDialog(TRUE);
}
void OnCancel()
{
MessageBox("Cancel Clicked", "Model Dialogbox");
}

void OnClick1()
{
CButton *myButton = (CButton *)GetDlgItem(IDC_CHECK1);
checkStatus1 = myButton->GetCheck();
}
void OnClick2()
{
CButton *myButton = (CButton *)GetDlgItem(IDC_CHECK2);
checkStatus2 = myButton->GetCheck();
}
DECLARE_MESSAGE_MAP()
};

BEGIN_MESSAGE_MAP(myDialog, CDialog)
ON_COMMAND(IDOK, OnOK)
ON_COMMAND(IDCANCEL, OnCancel)
ON_COMMAND(IDCANCEL, OnCancel)
ON_BN_CLICKED(IDC_CHECK1, OnClick1)
ON_BN_CLICKED(IDC_CHECK2, OnClick2)

END_MESSAGE_MAP()

void DisplayDialog()
{
myDialog a;
a.DoModal();
}

class MyApp : public CWinApp
{
public:
BOOL InitInstance();
};


BOOL MyApp::InitInstance()
{
DisplayDialog();
return TRUE;
}

MyApp ApplicationObject;

No comments:

Post a Comment