串口调试助手的源码分析,子对话框部分

 

中午分析的那篇博客的  子对话框程序:

// Management.cpp : implementation file
//

#include "stdafx.h"
#include "doorcontrol.h"
#include "Management.h"

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

/////////////////////////////////////////////////////////////////////////////
// CManagement dialog


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


void CManagement::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CManagement)
//    DDX_Control(pDX, IDC_BUN_DELET, m_btn_delet);
    DDX_Control(pDX, IDC_LIST, m_list);
    //}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CManagement, CDialog)
    //{{AFX_MSG_MAP(CManagement)
    ON_BN_CLICKED(IDC_BUTN_ADD, OnButnAdd)
    ON_BN_CLICKED(IDC_BUTN_MODIFY, OnButnModify)
    ON_BN_CLICKED(IDC_BUN_DELET, OnBunDelet)
    ON_BN_CLICKED(IDC_BUTN_SEARCH, OnButnSearch)
    ON_BN_CLICKED(IDC_BUTN_SAVE, OnButnSave)
    ON_BN_CLICKED(IDC_BUTN_CLOSE, OnButnClose)
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CManagement message handlers

BOOL CManagement::OnInitDialog() 
{
    CDialog::OnInitDialog();
    
    // TODO: Add extra initialization here
    m_list.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
    m_list.SetBkColor(RGB(247,247,255));
    m_list.SetTextColor(RGB(0,0,255));
    m_list.SetTextBkColor(RGB(247,247,255));
    m_list.InsertColumn(0, "卡号", LVCFMT_LEFT, 120);
    m_list.InsertColumn(1, "姓名", LVCFMT_LEFT, 90);
    m_list.InsertColumn(2, "权限", LVCFMT_LEFT, 180);
    m_list.InsertColumn(3, "最近使用时间", LVCFMT_LEFT, 200);

    m_list.InsertItem(0,"15870295");
    m_list.SetItemText(0,1,"小陈");
    m_list.SetItemText(0,2,"1,2,3,4,5");
    m_list.SetItemText(0,3,"2011,4,20 23:22:11");
    
    m_list.InsertItem(1,"02112126");
    m_list.SetItemText(1,1,"小论");
    m_list.SetItemText(1,2,"5,6,7");
    m_list.SetItemText(1,3,"2011,4,21 13:02:18");
    
    m_list.InsertItem(2,"18112125");
    m_list.SetItemText(2,1,"陈宏论");
    m_list.SetItemText(2,2,"5,9");
    m_list.SetItemText(2,3,"2011,4,21 21:22:00");
    
    m_list.InsertItem(3,"20888103");
    m_list.SetItemText(3,1,"Google");
    m_list.SetItemText(3,2,"1,2,9");
    m_list.SetItemText(3,3,"2010,4,20 02:24:41");

    m_btn_add.SubclassDlgItem(IDC_BUTN_ADD,this);
    m_btn_add.SetIcon(IDI_ICON_ADD);
    m_btn_add.SetColor(CButtonST::BTNST_COLOR_BK_OUT, RGB(208,208,208)); 
    m_btn_add.SetColor(CButtonST::BTNST_COLOR_BK_FOCUS, RGB(208,208,208));
    m_btn_add.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, 30);

    m_btn_close.SubclassDlgItem(IDC_BUTN_CLOSE,this);
    m_btn_close.SetIcon(IDI_ICON_CLOSE);
    m_btn_close.SetColor(CButtonST::BTNST_COLOR_BK_OUT, RGB(208,208,208)); 
    m_btn_close.SetColor(CButtonST::BTNST_COLOR_BK_FOCUS, RGB(208,208,208));
    m_btn_close.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, 30);

    m_btn_modify.SubclassDlgItem(IDC_BUTN_MODIFY,this);
    m_btn_modify.SetIcon(IDI_ICON_MODIFY);
    m_btn_modify.SetColor(CButtonST::BTNST_COLOR_BK_OUT, RGB(208,208,208)); 
    m_btn_modify.SetColor(CButtonST::BTNST_COLOR_BK_FOCUS, RGB(208,208,208));
    m_btn_modify.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, 30);

    m_btn_delet.SubclassDlgItem(IDC_BUN_DELET,this);
    m_btn_delet.SetIcon(IDI_ICON_DELET);
    m_btn_delet.SetColor(CButtonST::BTNST_COLOR_BK_OUT, RGB(208,208,208)); 
    m_btn_delet.SetColor(CButtonST::BTNST_COLOR_BK_FOCUS, RGB(208,208,208));
    m_btn_delet.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, 30);

    m_btn_save.SubclassDlgItem(IDC_BUTN_SAVE,this);
    m_btn_save.SetIcon(IDI_ICON_SAVE);
    m_btn_save.SetColor(CButtonST::BTNST_COLOR_BK_OUT, RGB(208,208,208)); 
    m_btn_save.SetColor(CButtonST::BTNST_COLOR_BK_FOCUS, RGB(208,208,208));
    m_btn_save.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, 30);

    m_btn_search.SubclassDlgItem(IDC_BUTN_SEARCH,this);
    m_btn_search.SetIcon(IDI_ICON_SEARCH);
    m_btn_search.SetColor(CButtonST::BTNST_COLOR_BK_OUT, RGB(208,208,208)); 
    m_btn_search.SetColor(CButtonST::BTNST_COLOR_BK_FOCUS, RGB(208,208,208));
    m_btn_search.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, 30);

    return TRUE;  // return TRUE unless you set the focus to a control
                  // EXCEPTION: OCX Property Pages should return FALSE
}

void CManagement::OnButnAdd() 
{
    // TODO: Add your control notification handler code here
    
}

void CManagement::OnButnModify() 
{
    // TODO: Add your control notification handler code here
    
}
//删除项目
void CManagement::OnBunDelet() 
{
    // TODO: Add your control notification handler code here
    POSITION pos = m_list.GetFirstSelectedItemPosition();
    m_nIndex = m_list.GetNextSelectedItem(pos);  // 得到项目索引
    
    if(m_nIndex==-1)
    {
        MessageBox("请选择一项在删除!","提示",MB_ICONINFORMATION);
        return;
    }
    
    m_list.DeleteItem(m_nIndex); 
    
    UINT flag = LVIS_SELECTED|LVIS_FOCUSED;
    m_list.SetItemState(m_nIndex-1, flag, flag);
}

void CManagement::OnButnSearch() 
{
    // TODO: Add your control notification handler code here
    
}
//保存数据
void CManagement::OnButnSave() 
{
    // TODO: Add your control notification handler code here
    CStdioFile sf;
    if(sf.Open("人员信息.txt",CFile::modeCreate | CFile::modeWrite))
    {
        CString strOut;
        strOut="\r\n卡号\t\t姓名\t\t权限\t\t最近使用时间\r\n";
        sf.WriteString(strOut);
        
        for(int i=0;i<m_list.GetItemCount();i++)
        {
            strOut=m_list.GetItemText(i,0) + "\t"+m_list.GetItemText(i,1)+"\t     "+m_list.GetItemText(i,2) +"\t       "+m_list.GetItemText(i,3)+"\r\n";
            sf.WriteString(strOut);
        }
        sf.Close();
        MessageBox("保存成功!","提示",MB_ICONINFORMATION);
    }
    
    else
        MessageBox("保存失败!","提示",MB_ICONINFORMATION);
}

void CManagement::OnButnClose() 
{
    // TODO: Add your control notification handler code here
    
}

 

posted @ 2015-12-30 00:01  星雷热忱  阅读(812)  评论(0编辑  收藏  举报