www.gusucode.com > 《C++高级语言程序设计》PPT及全书例子源代码-源码程序 > 《C++高级语言程序设计》PPT及全书例子源代码-源码程序/code/C++例题程序/第8章/s8_3/s8_3Dlg.cpp

    //Download by http://www.NewXing.com
// s8_3Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "s8_3.h"
#include "s8_3Dlg.h"

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

//增加用于进行语种选择的函数
CString SelectLanguage(BOOL bCheckEnglish, BOOL bCheckJapanese, BOOL bCheckFrench, BOOL bCheckGerman)
{
	CString strLanguage = "";
	if(bCheckEnglish)
	{
		strLanguage = strLanguage + "英语 ";
	}
	if(bCheckJapanese)
	{
		strLanguage = strLanguage + "日语 ";
	}
	if(bCheckFrench)
	{
		strLanguage = strLanguage + "法语 ";
	}
	if(bCheckGerman)
	{
		strLanguage = strLanguage + "德语";
	}
	return strLanguage;
}

/////////////////////////////////////////////////////////////////////////////
// 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()

/////////////////////////////////////////////////////////////////////////////
// CS8_3Dlg dialog

CS8_3Dlg::CS8_3Dlg(CWnd* pParent /*=NULL*/)
	: CDialog(CS8_3Dlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CS8_3Dlg)
	m_bCheckFrench = TRUE;
	m_bCheckGerman = FALSE;
	m_bCheckJapanese = FALSE;
	m_bCheckEnglish = FALSE;
	m_nRadioSexGroup = 0;
	m_nRadioBusinessGroup = 0;
	m_strEditBusiness = "工人";
	m_strEditLanguages = "英语";
	m_strEditSex = "男";
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CS8_3Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CS8_3Dlg)
	DDX_Check(pDX, IDC_CHECK_FRENCH, m_bCheckFrench);
	DDX_Check(pDX, IDC_CHECK_GERMAN, m_bCheckGerman);
	DDX_Check(pDX, IDC_CHECK_JAPANESE, m_bCheckJapanese);
	DDX_Text(pDX, IDC_EDIT_BUSINESS, m_strEditBusiness);
	DDX_Text(pDX, IDC_EDIT_LANGUAGES, m_strEditLanguages);
	DDX_Text(pDX, IDC_EDIT_SEX, m_strEditSex);
	DDX_Radio(pDX, IDC_RADIO_MALE, m_nRadioSexGroup);
	DDX_Radio(pDX, IDC_RADIO_WORKER, m_nRadioBusinessGroup);
	DDX_Check(pDX, IDC_CHECK_ENGLISH, m_bCheckEnglish);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CS8_3Dlg, CDialog)
	//{{AFX_MSG_MAP(CS8_3Dlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_CHECK_ENGLISH, OnCheckEnglish)
	ON_BN_CLICKED(IDC_CHECK_FRENCH, OnCheckFrench)
	ON_BN_CLICKED(IDC_CHECK_GERMAN, OnCheckGerman)
	ON_BN_CLICKED(IDC_CHECK_JAPANESE, OnCheckJapanese)
	ON_BN_CLICKED(IDC_RADIO_FEMALE, OnRadioFemale)
	ON_BN_CLICKED(IDC_RADIO_MALE, OnRadioMale)
	ON_BN_CLICKED(IDC_RADIO_STUDENT, OnRadioStudent)
	ON_BN_CLICKED(IDC_RADIO_TEACHER, OnRadioTeacher)
	ON_BN_CLICKED(IDC_RADIO_TRADER, OnRadioTrader)
	ON_BN_CLICKED(IDC_RADIO_WORKER, OnRadioWorker)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CS8_3Dlg message handlers

BOOL CS8_3Dlg::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 CS8_3Dlg::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 CS8_3Dlg::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 CS8_3Dlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}


void CS8_3Dlg::OnCheckEnglish() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_strEditLanguages = SelectLanguage(m_bCheckEnglish, m_bCheckJapanese, m_bCheckFrench, m_bCheckGerman);
	UpdateData(FALSE);
	
}

void CS8_3Dlg::OnCheckJapanese() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_strEditLanguages = SelectLanguage(m_bCheckEnglish, m_bCheckJapanese, m_bCheckFrench, m_bCheckGerman);
	UpdateData(FALSE);
	
}

void CS8_3Dlg::OnCheckFrench() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_strEditLanguages = SelectLanguage(m_bCheckEnglish, m_bCheckJapanese, m_bCheckFrench, m_bCheckGerman);
	UpdateData(FALSE);
	
}

void CS8_3Dlg::OnCheckGerman() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_strEditLanguages = SelectLanguage(m_bCheckEnglish, m_bCheckJapanese, m_bCheckFrench, m_bCheckGerman);
	UpdateData(FALSE);
	
}

void CS8_3Dlg::OnRadioWorker() 
{
	// TODO: Add your control notification handler code here
	m_nRadioBusinessGroup = 0;
	m_strEditBusiness = "工人";
	UpdateData(FALSE);
	
}

void CS8_3Dlg::OnRadioTeacher() 
{
	// TODO: Add your control notification handler code here
	m_nRadioBusinessGroup = 1;
	m_strEditBusiness = "教师";
	UpdateData(FALSE);
	
}

void CS8_3Dlg::OnRadioStudent() 
{
	// TODO: Add your control notification handler code here
	m_nRadioBusinessGroup = 2;
	m_strEditBusiness = "学生";
	UpdateData(FALSE);
	
}

void CS8_3Dlg::OnRadioTrader() 
{
	// TODO: Add your control notification handler code here
	m_nRadioBusinessGroup = 3;
	m_strEditBusiness = "商人";
	UpdateData(FALSE);
	
}

void CS8_3Dlg::OnRadioMale() 
{
	// TODO: Add your control notification handler code here
	m_nRadioSexGroup = 0;
	m_strEditSex = "男";
	UpdateData(FALSE);
	
}

void CS8_3Dlg::OnRadioFemale() 
{
	// TODO: Add your control notification handler code here
	m_nRadioSexGroup = 1;
	m_strEditSex = "女";
	UpdateData(FALSE);
	
}