www.pudn.com > tongyongkongjianlei.rar > ControlBoxDlg.cpp
// ControlBoxDlg.cpp : implementation file
//
#include "stdafx.h"
#include "ControlBox.h"
#include "ControlBoxDlg.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()
/////////////////////////////////////////////////////////////////////////////
// CControlBoxDlg dialog
CControlBoxDlg::CControlBoxDlg(CWnd* pParent /*=NULL*/)
: CDialog(CControlBoxDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CControlBoxDlg)
m_Name = _T("");
m_Sex = 0;
m_Net1 = FALSE;
m_Net2 = FALSE;
m_Net3 = FALSE;
m_Net4 = FALSE;
m_Net5 = FALSE;
m_NetAge = 2;
//}}AFX_DATA_INIT
RecordNum=3;//预先已经存在的记录数
//初始化已经存在的记录
GName[0]="王明";GName[1]="李刚";GName[2]="李莎";
GSex[0]="男";GSex[1]="男";GSex[2]="女";
GGrade[0]="高一";GGrade[1]="高二";GGrade[2]="高三";
GAge[0]="14";GAge[1]="15";GAge[2]="16";
GNetAge[0]="5";GNetAge[1]="3";GNetAge[2]="1";
GIp[0]="11.145.45.34";GIp[1]="11.145.45.56";GIp[2]="11.145.45.39";
GHobby[0]="网络游戏";GHobby[1]="浏览网页";GHobby[2]="网络聊天";
GDate[0]="2005-12-3";GDate[1]="2005-12-23";GDate[2]="2006-1-12";
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CControlBoxDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CControlBoxDlg)
DDX_Control(pDX, IDC_LIST, m_list);
DDX_Control(pDX, IDC_TREE, m_tree);
DDX_Control(pDX, IDC_DATETIMEPICKER1, m_Time);
DDX_Control(pDX, IDC_GRADE, m_Grade);
DDX_Control(pDX, IDC_SLIDER1, m_Slider);
DDX_Control(pDX, IDC_IPADDRESS1, m_Ip);
DDX_Control(pDX, IDC_SPIN1, m_spin);
DDX_Text(pDX, IDC_NAME, m_Name);
DDX_Radio(pDX, IDC_RADIO1, m_Sex);
DDX_Check(pDX, IDC_CHECK1, m_Net1);
DDX_Check(pDX, IDC_CHECK2, m_Net2);
DDX_Check(pDX, IDC_CHECK3, m_Net3);
DDX_Check(pDX, IDC_CHECK4, m_Net4);
DDX_Check(pDX, IDC_CHECK5, m_Net5);
DDX_Text(pDX, IDC_NETAGE, m_NetAge);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CControlBoxDlg, CDialog)
//{{AFX_MSG_MAP(CControlBoxDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_HSCROLL()
ON_BN_CLICKED(IDC_SUBMIT, OnSubmit)
ON_BN_CLICKED(IDC_RESET, OnReset)
ON_NOTIFY(TVN_SELCHANGED, IDC_TREE, OnSelchangedTree)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CControlBoxDlg message handlers
BOOL CControlBoxDlg::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
m_Grade.AddString("高一"); //组合框中添加选项
m_Grade.AddString("高二");
m_Grade.AddString("高三");
m_Grade.SetCurSel(0); //设置组合框初始选项为选项1
GetDlgItem(IDC_NETAGE)->EnableWindow(false); //网龄编辑框无效
m_spin.SetRange(14,22); //设置微调按钮调节范围
m_spin.SetPos(16); //设置微调按钮的初始值
m_Slider.SetRange(1,10,false); //设置滑块控件的范围
m_Slider.SetPos(2); //设置滑块控件的初始值
m_Slider.SetTicFreq(1); //设置刻度的频度
m_Ip.SetAddress(127,0,0,1);//设定IP值
CString TreeHeader[2]={"按年级分类","按性别分类"};
HTREEITEM Item[2]; //树形控件的根项
for(int i=0;i<2;i++)
{
Item[i]=m_tree.InsertItem(TreeHeader[i],TVI_ROOT); //插入父项
m_tree.SetItemData(Item[i],(DWORD)(i+10)); //给父项设值
}
// HTREEITEM thePoint;
HTREEITEM Specifics=m_tree.InsertItem("高中一年级",Item[0]); //父项1插入子项
m_tree.SetItemData(Specifics,(DWORD)0); //子项赋值0
// thePoint=Specifics;
Specifics=m_tree.InsertItem("高中二年级",Item[0]); //父项1插入子项
m_tree.SetItemData(Specifics,(DWORD)1);//子项赋值1
Specifics=m_tree.InsertItem("高中三年级",Item[0]); //父项1插入子项
m_tree.SetItemData(Specifics,(DWORD)2); //子项赋值2
Specifics=m_tree.InsertItem("男学生",Item[1]); //父项2插入子项
m_tree.SetItemData(Specifics,(DWORD)3); //子项赋值3
Specifics=m_tree.InsertItem("女学生",Item[1]); //父项2插入子项
m_tree.SetItemData(Specifics,(DWORD)4); //子项赋值4
//m_tree.Select(thePoint,TVGN_CARET); //子项0为选定项
CString Field[8]={"姓名","性别","年级","年龄","网龄","IP","爱好","填表日期"}; //列表视的表头
for(int j=0;j<8;j++)
{
m_list.InsertColumn(j,Field[j],LVCFMT_LEFT,73); //插入表头标题
}
for(i=0;i