为MFC应用程序添加登录对话框界面

这里我们以之前的Fobsignup模板为例。

之前我们已经创建了一个应用程序,并完成了我们的算法要求。后因需求,我们需要为其添加一个登录界面。

下面简单介绍一下流程:

  1. 在原来的工程中,定义一个全局变量,默认值为false:BOOL g_bool_symbol = false;
  2. 添加新的对话框(Resourse View--Dialog--(右键) Insert Dialog);
  3. 为新的对话框添加控件:
  4. 为新对话框添加类,基类为:CDialogEx,新类名称为:LoginDlg,即:class LoginDlg : public CDialogEx;
  5. 添加成员变量: m_Edit1_userName--IDC_EDIT1,m_Edit2_passwords--IDC_EDIT2;
  6. 添加Virtual Functions: BN_Clicked_Login--IDC_BUTTON1,BN_Clicked_Exit--IDC_BUTTON2,BN_Clicked_showPwd--IDC_CHECK_BUTTON1.
  7. 编写函数:
  8.  1 void LoginDlg::BN_Clicked_Login()
     2 {
     3     // TODO: Add your control notification handler code here
     4     UpdateData(true);
     5     if (m_Edit1_userName.IsEmpty())
     6     {
     7         MessageBox(_T("Please enter your name."));
     8         GetDlgItem(IDC_EDIT1)->SetFocus();
     9         return;
    10     }
    11     if (m_Edit2_passwords.IsEmpty())
    12     {
    13         MessageBox(_T("Please enter your password."));
    14         GetDlgItem(IDC_EDIT2)->SetFocus();
    15         return;
    16     }
    17     if (m_Edit1_userName != "admin")
    18     {
    19         MessageBox(_T("user name is invalid."));
    20         GetDlgItem(IDC_EDIT1)->SetFocus();
    21         return;
    22     }
    23     else if (m_Edit2_passwords != "10010")
    24     {
    25         MessageBox(_T("passwords is invalid."));
    26         GetDlgItem(IDC_EDIT2)->SetFocus();
    27         return;
    28     }
    29     if (g_bool_symbol == false)
    30     {
    31         g_bool_symbol = true;
    32         LoginDlg::OnOK();
    33         CFobsignupDlg dlgApp;
    34         dlgApp.DoModal();
    35         g_bool_symbol = false;
    36     }
    37 }
    38 
    39 
    40 void LoginDlg::BN_Clicked_Exit()
    41 {
    42     // TODO: Add your control notification handler code here
    43     LoginDlg::OnOK();
    44 }
    45 
    46 
    47 void LoginDlg::BN_Clicked_showPwd()
    48 {
    49     // TODO: Add your control notification handler code here
    50     if (IsDlgButtonChecked(IDC_CHECK1) == BST_CHECKED)
    51     {
    52         UpdateData(true);
    53         CEdit *pEdit = (CEdit*)(this)->GetDlgItem(IDC_EDIT2);
    54         pEdit->SetPasswordChar(0);
    55         SetDlgItemText(IDC_EDIT2, m_Edit2_passwords);
    56         UpdateData(false);
    57     }
    58     else
    59     {
    60         UpdateData(true);
    61         CEdit *pEdit = (CEdit*)(this)->GetDlgItem(IDC_EDIT2);
    62         pEdit->SetPasswordChar('*');
    63         SetDlgItemText(IDC_EDIT2, m_Edit2_passwords);
    64         UpdateData(false);
    65     }
    66     GetDlgItem(IDC_EDIT2)->SetFocus();
    67 }
    View Code

     

  9. 在LoginDlg 类中添加重载函数:
    protected:
        virtual BOOL OnInitDialog();
        virtual BOOL PreTranslateMessage(MSG* pMsg);
    View Code

     

  10. 初始化函数处理默认密码输入以‘ * ’ 为字符输入,限制最大长度为16个字符:
    1 BOOL LoginDlg::OnInitDialog()
    2 {
    3     CEdit *pEdit = (CEdit*)(this)->GetDlgItem(IDC_EDIT2);
    4     pEdit->SetLimitText(16);
    5     pEdit->SetPasswordChar('*');
    6     return false;
    7 }

     

  11. 键盘输入处理函数,取消键入ESC键与回车键退出对话框功能:
     1 BOOL LoginDlg::PreTranslateMessage(MSG* pMsg)
     2 {
     3     if (pMsg->message == WM_KEYDOWN)
     4     {
     5         switch (pMsg->wParam)
     6         {
     7         case VK_ESCAPE:
     8         {
     9                           return true;
    10                           break;
    11         }
    12         case VK_RETURN:
    13         {
    14                           return true;
    15                           break;
    16         }
    17         default:
    18             break;
    19         }
    20     }
    21     return CDialog::PreTranslateMessage(pMsg);
    22 }

     

  12. 同样,在原来的对话框中,我们也同样定义键盘输入处理函数,取消键入ESC键和回车键退出对话框功能函数:
    BOOL CFobsignupDlg::PreTranslateMessage(MSG *pMsg)
    {
        if (pMsg->message == WM_KEYDOWN)
        {
            switch (pMsg->wParam)
            {
            case VK_ESCAPE:
            {
                              return true;
                              break;
            }
            case VK_RETURN:
            {
                              return true;
                              break;
            }
            default:
                break;
            }
        }
        return CDialog::PreTranslateMessage(pMsg);
    }
    View Code

     

  13. 最后,我们将主函数在初始化时,关闭主对话框,进入登录对话框:在 BOOL CFobsignupDlg::OnInitDialog() 函数添加如下代码:
    1     if (g_bool_symbol == false)
    2     {
    3         CFobsignupDlg::OnOK();
    4         LoginDlg loginDlg;
    5         loginDlg.DoModal();
    6     }
    7     return TRUE;  // return TRUE  unless you set the focus to a control

     

  14. 源码:
    // LoginDlg.cpp : implementation file
    //
    
    #include "stdafx.h"
    #include "Fobsignup.h"
    #include "LoginDlg.h"
    #include "FobsignupDlg.h"
    #include "afxdialogex.h"
    
    extern BOOL g_bool_symbol;
    // LoginDlg dialog
    
    IMPLEMENT_DYNAMIC(LoginDlg, CDialogEx)
    
    LoginDlg::LoginDlg(CWnd* pParent /*=NULL*/)
        : CDialogEx(LoginDlg::IDD, pParent)
        , m_Edit1_userName(_T(""))
        , m_Edit2_passwords(_T(""))
    {
    
    }
    
    LoginDlg::~LoginDlg()
    {
    }
    
    void LoginDlg::DoDataExchange(CDataExchange* pDX)
    {
        CDialogEx::DoDataExchange(pDX);
        DDX_Text(pDX, IDC_EDIT1, m_Edit1_userName);
        DDX_Text(pDX, IDC_EDIT2, m_Edit2_passwords);
    }
    
    
    BEGIN_MESSAGE_MAP(LoginDlg, CDialogEx)
        ON_BN_CLICKED(IDC_BUTTON1, &LoginDlg::BN_Clicked_Login)
        ON_BN_CLICKED(IDC_BUTTON2, &LoginDlg::BN_Clicked_Exit)
        ON_BN_CLICKED(IDC_CHECK1, &LoginDlg::BN_Clicked_showPwd)
    END_MESSAGE_MAP()
    
    
    // LoginDlg message handlers
    
    
    BOOL LoginDlg::PreTranslateMessage(MSG* pMsg)
    {
        if (pMsg->message == WM_KEYDOWN)
        {
            switch (pMsg->wParam)
            {
            case VK_ESCAPE:
            {
                              return true;
                              break;
            }
            case VK_RETURN:
            {
                              return true;
                              break;
            }
            default:
                break;
            }
        }
        return CDialog::PreTranslateMessage(pMsg);
    }
    
    BOOL LoginDlg::OnInitDialog()
    {
        CEdit *pEdit = (CEdit*)(this)->GetDlgItem(IDC_EDIT2);
        pEdit->SetLimitText(16);
        pEdit->SetPasswordChar('*');
        return false;
    }
    
    void LoginDlg::BN_Clicked_Login()
    {
        // TODO: Add your control notification handler code here
        UpdateData(true);
        if (m_Edit1_userName.IsEmpty())
        {
            MessageBox(_T("Please enter your name."));
            GetDlgItem(IDC_EDIT1)->SetFocus();
            return;
        }
        if (m_Edit2_passwords.IsEmpty())
        {
            MessageBox(_T("Please enter your password."));
            GetDlgItem(IDC_EDIT2)->SetFocus();
            return;
        }
        if (m_Edit1_userName != "admin")
        {
            MessageBox(_T("user name is invalid."));
            GetDlgItem(IDC_EDIT1)->SetFocus();
            return;
        }
        else if (m_Edit2_passwords != "10010")
        {
            MessageBox(_T("passwords is invalid."));
            GetDlgItem(IDC_EDIT2)->SetFocus();
            return;
        }
        if (g_bool_symbol == false)
        {
            g_bool_symbol = true;
            LoginDlg::OnOK();
            CFobsignupDlg dlgApp;
            dlgApp.DoModal();
            g_bool_symbol = false;
        }
    }
    
    
    void LoginDlg::BN_Clicked_Exit()
    {
        // TODO: Add your control notification handler code here
        LoginDlg::OnOK();
    }
    
    
    void LoginDlg::BN_Clicked_showPwd()
    {
        // TODO: Add your control notification handler code here
        if (IsDlgButtonChecked(IDC_CHECK1) == BST_CHECKED)
        {
            UpdateData(true);
            CEdit *pEdit = (CEdit*)(this)->GetDlgItem(IDC_EDIT2);
            pEdit->SetPasswordChar(0);
            SetDlgItemText(IDC_EDIT2, m_Edit2_passwords);
            UpdateData(false);
        }
        else
        {
            UpdateData(true);
            CEdit *pEdit = (CEdit*)(this)->GetDlgItem(IDC_EDIT2);
            pEdit->SetPasswordChar('*');
            SetDlgItemText(IDC_EDIT2, m_Edit2_passwords);
            UpdateData(false);
        }
        GetDlgItem(IDC_EDIT2)->SetFocus();
    }
    LoginDlg.cpp
    #pragma once
    #include "afxwin.h"
    
    
    // LoginDlg dialog
    
    class LoginDlg : public CDialogEx
    {
        DECLARE_DYNAMIC(LoginDlg)
    
    public:
        LoginDlg(CWnd* pParent = NULL);   // standard constructor
        virtual ~LoginDlg();
    
    // Dialog Data
        enum { IDD = IDD_DIALOG1 };
    
    protected:
        virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
        virtual BOOL OnInitDialog();
        virtual BOOL PreTranslateMessage(MSG* pMsg);
    
        DECLARE_MESSAGE_MAP()
    public:
        afx_msg void BN_Clicked_Login();
        CString m_Edit1_userName;
        CString m_Edit2_passwords;
        afx_msg void BN_Clicked_Exit();
        afx_msg void BN_Clicked_showPwd();
    };
    LoginDlg.h
    // FobsignupDlg.cpp : implementation file
    //
    
    #include "stdafx.h"
    #include "Fobsignup.h"
    #include "FobsignupDlg.h"
    #include "LoginDlg.h"
    #include "afxdialogex.h"
    
    #ifdef _DEBUG
    #define new DEBUG_NEW
    #endif
    typedef int(*PFUN)(const unsigned int        fobIdLen
        , const unsigned int        maxPepArrayLen
        , const unsigned int        maxRkeArrayLen
        , const unsigned char    *encryptedFobId
        , unsigned int            *actualPepArrayLen
        , unsigned int            *actualRkeArrayLen
        , unsigned char            *dtEncryptedPepArray
        , unsigned char            *dtEncryptedRkeArray);
    
    typedef void(*AESFUN)(unsigned char *pskey, unsigned char *blk);
    //e.g, input="123456"--(length=6)-->output={0x12,0x34,0x56}
    typedef int(*C2HFUN)(char*input, unsigned char *output, int length);
    
    unsigned char dll_key_fob[16] = { 0x56, 0x38, 0x97, 0x3f, 0x56, 0x70, 0x22, 0x88, 0x3b, 0x52, 0xfe, 0x5a, 0x01, 0x32, 0x08, 0x49 };
    unsigned char dll_key_PEP[16] = { 0x13, 0xff, 0x13, 0x84, 0x43, 0x86, 0x43, 0x4a, 0x23, 0x53, 0xe6, 0x54, 0xd3, 0x02, 0x00, 0x34 };
    unsigned char dll_key_RKE[16] = { 0x15, 0x42, 0x71, 0x73, 0x6a, 0x41, 0xe3, 0x45, 0xde, 0x40, 0xba, 0x34, 0x42, 0x82, 0xaa, 0xe2 };
    
    unsigned char bcm_key_PEP[16] = { 0x18, 0x92, 0x14, 0x81, 0x89, 0xf2, 0x4f, 0xa4, 0x92, 0x52, 0xfe, 0x5a, 0x4e, 0x32, 0xcc, 0x3d };
    unsigned char bcm_key_RKE[16] = { 0x12, 0x52, 0x63, 0x54, 0x25, 0x4b, 0xc3, 0x4b, 0x23, 0x00, 0xdd, 0xbb, 0xc3, 0x82, 0xfd, 0xf4 };
    //CRC-8 for ATM HEC (x8+x2+x+1)
    unsigned char cal_crc(unsigned char *vptr, unsigned char len)
    {
        const unsigned char *data = vptr;
        unsigned int crc = 0;
        int i, j;
        for (j = len; j; j--, data++)
        {
            crc ^= (*data << 8);
            for (i = 8; i; i--)
            {
                if (crc & 0x8000)
                    crc ^= (unsigned int)(0x1070 << 3);
                crc <<= 1;
            }
        }
        return (unsigned char)(crc >> 8);
    }
    BOOL g_bool_symbol = false;
    
    // CAboutDlg dialog used for App About
    
    class CAboutDlg : public CDialogEx
    {
    public:
        CAboutDlg();
    
    // Dialog Data
        enum { IDD = IDD_ABOUTBOX };
    
        protected:
        virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    
    // Implementation
    protected:
        DECLARE_MESSAGE_MAP()
    };
    
    CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD)
    {
    }
    
    void CAboutDlg::DoDataExchange(CDataExchange* pDX)
    {
        CDialogEx::DoDataExchange(pDX);
    }
    
    BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
    END_MESSAGE_MAP()
    
    
    // CFobsignupDlg dialog
    
    
    
    CFobsignupDlg::CFobsignupDlg(CWnd* pParent /*=NULL*/)
        : CDialogEx(CFobsignupDlg::IDD, pParent)
        , m_Edit1(_T(""))
        , m_Edit2(_T(""))
        , m_Edit3(_T(""))
        , m_Edit4(_T(""))
        , m_Edit5(_T(""))
        , m_Edit6(_T(""))
        , m_Edit7(_T(""))
        , m_Edit8(_T(""))
        , m_Edit9(_T(""))
    {
        m_hIcon = AfxGetApp()->LoadIcon(IDI_ICON1); //IDR_MAINFRAME
    }
    
    void CFobsignupDlg::DoDataExchange(CDataExchange* pDX)
    {
        CDialogEx::DoDataExchange(pDX);
        DDX_Text(pDX, IDC_EDIT1, m_Edit1);
        DDX_Text(pDX, IDC_EDIT2, m_Edit2);
        DDX_Text(pDX, IDC_EDIT3, m_Edit3);
        DDX_Text(pDX, IDC_EDIT4, m_Edit4);
        DDX_Text(pDX, IDC_EDIT5, m_Edit5);
        DDX_Text(pDX, IDC_EDIT6, m_Edit6);
        DDX_Text(pDX, IDC_EDIT7, m_Edit7);
        DDX_Text(pDX, IDC_EDIT8, m_Edit8);
        DDX_Text(pDX, IDC_EDIT9, m_Edit9);
        //  DDX_Control(pDX, IDC_MSCOMM1, m_mscom);
    }
    
    BEGIN_MESSAGE_MAP(CFobsignupDlg, CDialogEx)
        ON_WM_SYSCOMMAND()
        ON_WM_PAINT()
        ON_WM_QUERYDRAGICON()
        ON_BN_CLICKED(IDC_BUTTON1, &CFobsignupDlg::create_BN_CLICKED)
        ON_BN_CLICKED(IDC_BUTTON2, &CFobsignupDlg::Clear_BN_CLICKED)
    //    ON_BN_CLICKED(IDC_BUTTON3, &CFobsignupDlg::OnBnClickedButton3)
    ON_BN_CLICKED(IDC_BUTTON3, &CFobsignupDlg::write_BN_CLICKED)
    ON_BN_CLICKED(IDC_BUTTON4, &CFobsignupDlg::Open_Close_BN_CLICKED)
    ON_BN_CLICKED(IDC_CHECK1, &CFobsignupDlg::checkBox1_BN_CLICKED)
    ON_BN_CLICKED(IDC_CHECK2, &CFobsignupDlg::checkBox2_BN_CLICKED)
    ON_BN_CLICKED(IDC_CHECK3, &CFobsignupDlg::checkBox3_BN_CLICKED)
    ON_BN_CLICKED(IDC_CHECK4, &CFobsignupDlg::checkBox4_BN_CLICKED)
    ON_BN_CLICKED(IDC_CHECK5, &CFobsignupDlg::checkBox5_BN_CLICKED)
    ON_BN_CLICKED(IDC_CHECK6, &CFobsignupDlg::checkBox6_BN_CLICKED)
    ON_BN_CLICKED(IDC_CHECK7, &CFobsignupDlg::checkBox7_BN_CLICKED)
    ON_BN_CLICKED(IDC_CHECK8, &CFobsignupDlg::checkBox8_BN_CLICKED)
    END_MESSAGE_MAP()
    
    
    // CFobsignupDlg message handlers
    BOOL CFobsignupDlg::PreTranslateMessage(MSG *pMsg)
    {
        if (pMsg->message == WM_KEYDOWN)
        {
            switch (pMsg->wParam)
            {
            case VK_ESCAPE:
            {
                              return true;
                              break;
            }
            case VK_RETURN:
            {
                              return true;
                              break;
            }
            default:
                break;
            }
        }
        return CDialog::PreTranslateMessage(pMsg);
    }
    BOOL CFobsignupDlg::OnInitDialog()
    {
        CDialogEx::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)
        {
            BOOL bNameValid;
            CString strAboutMenu;
            bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
            ASSERT(bNameValid);
            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
        CEdit *pEdit = (CEdit*)(this)->GetDlgItem(IDC_EDIT1);
        pEdit->SetLimitText(24);
        CComboBox* pct = (CComboBox *)this->GetDlgItem(IDC_COMBO1);
        CComboBox* pport = (CComboBox *)this->GetDlgItem(IDC_COMBO2);
        CComboBox* pbaud = (CComboBox *)this->GetDlgItem(IDC_COMBO3);
        pct->SetCurSel(0);
        pport->SetCurSel(1);
        pbaud->SetCurSel(2);
        if (g_bool_symbol == false)
        {
            CFobsignupDlg::OnOK();
            LoginDlg loginDlg;
            loginDlg.DoModal();
        }
        return TRUE;  // return TRUE  unless you set the focus to a control
    }
    
    void CFobsignupDlg::OnSysCommand(UINT nID, LPARAM lParam)
    {
        if ((nID & 0xFFF0) == IDM_ABOUTBOX)
        {
            CAboutDlg dlgAbout;
            dlgAbout.DoModal();
        }
        else
        {
            CDialogEx::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 CFobsignupDlg::OnPaint()
    {
        if (IsIconic())
        {
            CPaintDC dc(this); // device context for painting
    
            SendMessage(WM_ICONERASEBKGND, reinterpret_cast<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
        {
            CDialogEx::OnPaint();
        }
    }
    
    // The system calls this function to obtain the cursor to display while the user drags
    //  the minimized window.
    HCURSOR CFobsignupDlg::OnQueryDragIcon()
    {
        return static_cast<HCURSOR>(m_hIcon);
    }
    
    
    
    void CFobsignupDlg::create_BN_CLICKED()
    {
        // TODO: Add your control notification handler code here
        char buf[50];
        unsigned char chr_buf[12];
        unsigned char fob_buf[16];
        unsigned char pep_buf[16];
        unsigned char rke_buf[16];
        unsigned char message_buf[49];
        //unsigned char key_buf[16];
        int i, k, result;
        unsigned int peplen = 0, rkelen = 0;
        unsigned int index;
        CString str;
        CString str_show(fob_buf);
        CButton*pbutton;
        TCHAR chCurDir[MAX_PATH] = { 0 };
        GetCurrentDirectory(MAX_PATH, chCurDir);
        SetCurrentDirectory(_T("C:\\Windows"));
        HMODULE hModule = ::LoadLibrary(_T("AES_DLL.dll"));
        //get context from edit1
        UpdateData(true);
        GetDlgItem(IDC_EDIT1)->GetWindowText(str);
        strcpy(buf, str);
        C2HFUN ToChar = (C2HFUN)::GetProcAddress(hModule, "char_to_hex");
        if (!ToChar(buf, fob_buf, 24))
        {
            AfxMessageBox(_T("data invalid."));
        }
        else
        {
            fob_buf[12] = 0;
            fob_buf[13] = 0;
            fob_buf[14] = 0;
            fob_buf[15] = 0;
            m_Edit1 = "";
            for (i = 0,index=0; i < 12; i++)
            {
                if (IsDlgButtonChecked(IDC_CHECK1) == BST_CHECKED)
                {
                    message_buf[index++] = fob_buf[11-i] ^ 0x38;
                    str_show.Format("%X", fob_buf[11-i]);
                }
                else
                {
                    message_buf[index++] = fob_buf[i] ^ 0x38;
                    str_show.Format("%X", fob_buf[i]);
                }
                chr_buf[i] = fob_buf[i];
                k = strlen(str_show);
                if (k == 0)
                {
                    m_Edit1 = "00";
                }
                else if (k == 1)
                {
                    m_Edit1 += "0";
                    m_Edit1 += str_show;
                }
                else
                {
                    m_Edit1 += str_show;
                }
            }
            if (IsDlgButtonChecked(IDC_CHECK1) == BST_CHECKED)
            {
                for (i = 0; i < 12; i++)
                {
                    fob_buf[i] = chr_buf[11 - i];
                }
                pbutton = (CButton*)GetDlgItem(IDC_CHECK1);
                pbutton->SetCheck(false);
            }
            if (IsDlgButtonChecked(IDC_CHECK2) == BST_CHECKED)
            {
                pbutton = (CButton*)GetDlgItem(IDC_CHECK2);
                pbutton->SetCheck(false);
            }
            if (IsDlgButtonChecked(IDC_CHECK3) == BST_CHECKED)
            {
                pbutton = (CButton*)GetDlgItem(IDC_CHECK3);
                pbutton->SetCheck(false);
            }
            if (IsDlgButtonChecked(IDC_CHECK4) == BST_CHECKED)
            {
                pbutton = (CButton*)GetDlgItem(IDC_CHECK4);
                pbutton->SetCheck(false);
            }
            if (IsDlgButtonChecked(IDC_CHECK5) == BST_CHECKED)
            {
                pbutton = (CButton*)GetDlgItem(IDC_CHECK5);
                pbutton->SetCheck(false);
            }
            if (IsDlgButtonChecked(IDC_CHECK6) == BST_CHECKED)
            {
                pbutton = (CButton*)GetDlgItem(IDC_CHECK6);
                pbutton->SetCheck(false);
            }
            if (IsDlgButtonChecked(IDC_CHECK7) == BST_CHECKED)
            {
                pbutton = (CButton*)GetDlgItem(IDC_CHECK7);
                pbutton->SetCheck(false);
            }
            if (IsDlgButtonChecked(IDC_CHECK8) == BST_CHECKED)
            {
                pbutton = (CButton*)GetDlgItem(IDC_CHECK8);
                pbutton->SetCheck(false);
            }
            AESFUN m_ase = (AESFUN)::GetProcAddress(hModule, "AesEncrypt");
            m_ase(dll_key_fob, fob_buf);
            m_Edit2 = m_Edit3 = m_Edit4 = m_Edit5 = m_Edit6 = m_Edit7 = m_Edit8 = m_Edit9 = "";
            for (i = 0; i < 16; i++)
            {
                str_show.Format("%X", fob_buf[i]);
                k = strlen(str_show);
                if (k == 0)
                {
                    m_Edit2 = "00";
                }
                else if (k == 1)
                {
                    m_Edit2 += "0";
                    m_Edit2 += str_show;
                }
                else
                {
                    m_Edit2 += str_show;
                }
            }
            hModule = ::LoadLibrary(_T("LaMotta FOB Signup_1.1_REL.dll"));
            PFUN m_dll = (PFUN)::GetProcAddress(hModule, "FobSignup");
            result = m_dll(16, 16, 16, fob_buf, &peplen, &rkelen, pep_buf, rke_buf);
            if (result == 0)
            {
                for (i = 0; i < 16; i++)
                {
                    str_show.Format("%X", pep_buf[i]);
                    k = strlen(str_show);
                    if (k == 0)
                    {
                        m_Edit3 = "00";
                    }
                    else if (k == 1)
                    {
                        m_Edit3 += "0";
                        m_Edit3 += str_show;
                    }
                    else
                    {
                        m_Edit3 += str_show;
                    }
                    str_show.Format("%X", rke_buf[i]);
                    k = strlen(str_show);
                    if (k == 0)
                    {
                        m_Edit4 = "00";
                    }
                    else if (k == 1)
                    {
                        m_Edit4 += "0";
                        m_Edit4 += str_show;
                    }
                    else
                    {
                        m_Edit4 += str_show;
                    }
                }
                hModule = ::LoadLibrary(_T("AES_DLL.dll"));
                m_ase = (AESFUN)::GetProcAddress(hModule, "ContraryAesEncrypt");
                m_ase(dll_key_PEP, pep_buf);
                m_ase(dll_key_RKE, rke_buf);
                for (i = 0; i < 16; i++)
                {
                    str_show.Format("%X", pep_buf[i]);
                    k = strlen(str_show);
                    if (k == 0)
                    {
                        m_Edit5 = "00";
                    }
                    else if (k == 1)
                    {
                        m_Edit5 += "0";
                        m_Edit5 += str_show;
                    }
                    else
                    {
                        m_Edit5 += str_show;
                    }
                    str_show.Format("%X", rke_buf[i]);
                    k = strlen(str_show);
                    if (k == 0)
                    {
                        m_Edit6 = "00";
                    }
                    else if (k == 1)
                    {
                        m_Edit6 += "0";
                        m_Edit6 += str_show;
                    }
                    else
                    {
                        m_Edit6 += str_show;
                    }
                }
                m_ase(bcm_key_PEP, pep_buf);
                m_ase(bcm_key_RKE, rke_buf);
                for (i = 0; i < 16; i++)
                {
                    message_buf[index++] = pep_buf[i] ^ 0x38;
                    str_show.Format("%X", pep_buf[i]);
                    k = strlen(str_show);
                    if (k == 0)
                    {
                        m_Edit7 = "00";
                    }
                    else if (k == 1)
                    {
                        m_Edit7 += "0";
                        m_Edit7 += str_show;
                    }
                    else
                    {
                        m_Edit7 += str_show;
                    }
                    message_buf[index + 15] = rke_buf[i] ^ 0x38;
                    str_show.Format("%X", rke_buf[i]);
                    k = strlen(str_show);
                    if (k == 0)
                    {
                        m_Edit8 = "00";
                    }
                    else if (k == 1)
                    {
                        m_Edit8 += "0";
                        m_Edit8 += str_show;
                    }
                    else
                    {
                        m_Edit8 += str_show;
                    }
                }
                index += 16;
                message_buf[index] = cal_crc(message_buf, index) ^ 0x83;
                for (i = 0; i < int(index + 1); i++)
                {
                    str_show.Format("%X", message_buf[i]);
                    k = strlen(str_show);
                    if (k == 0)
                    {
                        m_Edit9 = "00";
                    }
                    else if (k == 1)
                    {
                        m_Edit9 += "0";
                        m_Edit9 += str_show;
                    }
                    else
                    {
                        m_Edit9 += str_show;
                    }
                }
                CComboBox* pct = (CComboBox *)this->GetDlgItem(IDC_COMBO1);
                if (pct->GetCurSel() == 2)
                {
                    m_Edit9 += "315MHz";
                }
                else if (pct->GetCurSel() == 1)
                {
                    m_Edit9 += "433MHz";
                }
                else if (pct->GetCurSel() == 0)
                {
                    m_Edit9 += "Scaner";
                }
                else
                {
                    m_Edit9 += "Scaner";
                }
            }
        }
        UpdateData(false);
        SetCurrentDirectory(chCurDir);
        ::FreeLibrary(hModule);
    }
    
    void CFobsignupDlg::Clear_BN_CLICKED()
    {
        // TODO: Add your control notification handler code here
        DWORD DADA = 5631;
        CString str;
        m_Edit2 = m_Edit3 = m_Edit4 = m_Edit5 = m_Edit6 = m_Edit7 = m_Edit8 = m_Edit9 = "";
        UpdateData(false);
    }
    BEGIN_EVENTSINK_MAP(CFobsignupDlg, CDialogEx)
        ON_EVENT(CFobsignupDlg, IDC_MSCOMM1, 1, CFobsignupDlg::OnCommMscomm1, VTS_NONE)
    END_EVENTSINK_MAP()
    
    
    void CFobsignupDlg::OnCommMscomm1()
    {
        // TODO: Add your message handler code here
        long len, i;
        BYTE rxdata[64];                                    //rx buffer
        VARIANT variant_inp;
        COleSafeArray safearray_inp;
        CButton*pt = (CButton*)GetDlgItem(IDC_CHECK1);
        CMscomm1 *pcom = (CMscomm1*)this->GetDlgItem(IDC_MSCOMM1); 
        if (pcom->get_CommEvent() == 2)
        {
            variant_inp = pcom->get_Input();                //read rx buffer
            safearray_inp = variant_inp;                    //VARIANT to COleSafeArray calss
            len = safearray_inp.GetOneDimSize();            //get the active length of data byte
            if (len != 30)
                return;
            if (IsDlgButtonChecked(IDC_CHECK1) == BST_CHECKED)
            {
                pt->SetCheck(false);
            }
            m_Edit1 = "";
            for (i = 0; i<(len - 2); i++)                    //ignore '\r\n' symbol
            {
                safearray_inp.GetElement(&i, rxdata + i);
                if ((i+1)%5 == 0);                            //ignore space symbols
                else
                {
                    m_Edit1 += rxdata[i];
                }
            }
            UpdateData(false);
        }
    }
    
    
    void CFobsignupDlg::write_BN_CLICKED()
    {
        // TODO: Add your control notification handler code here
        CMscomm1 *pcomm = (CMscomm1 *)this->GetDlgItem(IDC_MSCOMM1);
        if (pcomm->get_PortOpen()==false)
        {
            MessageBox(_T("Serial Port DID NOT Open."));
        }
        else if (m_Edit9 == "")
        {
            MessageBox(_T("No message Write."));
        }
        else
        {
            pcomm->put_Output(COleVariant(m_Edit9));
        }
    }
    
    
    void CFobsignupDlg::Open_Close_BN_CLICKED()
    {
        // TODO: Add your control notification handler code here
        CMscomm1 *pcm = (CMscomm1 *)this ->GetDlgItem(IDC_MSCOMM1);
        CComboBox* pFreq = (CComboBox *)this->GetDlgItem(IDC_COMBO1);
        CComboBox* pport = (CComboBox *)this->GetDlgItem(IDC_COMBO2);
        CComboBox* pbaud = (CComboBox *)this->GetDlgItem(IDC_COMBO3);
        if (pcm->get_PortOpen() == false)
        {
            pcm->put_CommPort(pport->GetCurSel());
            if (pbaud->GetCurSel() == 0)
            {
                pcm->put_Settings(_T("2400,n,8,1"));
            }
            else if (pbaud->GetCurSel() == 1)
            {
                pcm->put_Settings(_T("4800,n,8,1"));
            }
            else if (pbaud->GetCurSel() == 2)
            {
                pcm->put_Settings(_T("9600,n,8,1"));
            }
            else if (pbaud->GetCurSel() == 3)
            {
                pcm->put_Settings(_T("38400,n,8,1"));
            }
            else if (pbaud->GetCurSel() == 4)
            {
                pcm->put_Settings(_T("115200,n,8,1"));
            }
            else
            {
                pcm->put_Settings(_T("9600,n,8,1"));
            }
            pcm->put_InputMode(1);                //1: read data by binary checking
            pcm->put_RThreshold(30);            //onComm event trigger when N byte in input buffer
            pcm->put_InputLen(0);                //set input length 0.
            pcm->put_PortOpen(true);
        }
        else
        {
            pcm->put_PortOpen(false);
        }
        if (pcm->get_PortOpen() == false)
        {
            SetDlgItemText(IDC_BUTTON4, _T("Open"));
            pport->EnableWindow(true);
            pbaud->EnableWindow(true);
            pFreq->EnableWindow(true);
        }
        else
        {
            SetDlgItemText(IDC_BUTTON4, _T("Close"));
            pport->EnableWindow(false);
            pbaud->EnableWindow(false);
            pFreq->EnableWindow(false);
        }
    }
    
    
    void CFobsignupDlg::checkBox1_BN_CLICKED()
    {
        // TODO: Add your control notification handler code here
        char buf[50];
        int i, k;
        unsigned char fob_buf[16];
        CString str;
        CString str_show(fob_buf);
        CButton*pt = (CButton*)GetDlgItem(IDC_CHECK1);
        //get context from edit1
        UpdateData(true);
        GetDlgItem(IDC_EDIT1)->GetWindowText(str);
        if (IsDlgButtonChecked(IDC_CHECK1) == BST_CHECKED)
        {
            if (str.GetLength() == 0)
            {
                pt->SetCheck(false);
                AfxMessageBox(_T("zero length"));
                return;
            }
        }
        else if (str.GetLength() == 0)
        {
            return;
        }
        strcpy(buf, str);
        TCHAR chCurDir[MAX_PATH] = { 0 };
        GetCurrentDirectory(MAX_PATH, chCurDir);
        SetCurrentDirectory(_T("C:\\Windows"));
        HMODULE hModule = ::LoadLibrary(_T("AES_DLL.dll"));
        C2HFUN ToChar = (C2HFUN)::GetProcAddress(hModule, "char_to_hex");
        if (!ToChar(buf, fob_buf, 24))
        {
            pt->SetCheck(false);
            AfxMessageBox(_T("data invalid."));
        }
        else
        {
            fob_buf[12] = 0;
            fob_buf[13] = 0;
            fob_buf[14] = 0;
            fob_buf[15] = 0;
            m_Edit1 = "";
            for (i = 0; i < 12; i++)
            {
                str_show.Format("%X", fob_buf[11 - i]);
                k = strlen(str_show);
                if (k == 0)
                {
                    m_Edit1 = "00";
                }
                else if (k == 1)
                {
                    m_Edit1 += "0";
                    m_Edit1 += str_show;
                }
                else
                {
                    m_Edit1 += str_show;
                }
            }
        }
        UpdateData(false); 
        SetCurrentDirectory(chCurDir);
        ::FreeLibrary(hModule);
    }
    
    
    void CFobsignupDlg::checkBox2_BN_CLICKED()
    {
        // TODO: Add your control notification handler code here
        char buf[96];
        int i, k;
        unsigned char fob_buf[16];
        CString str;
        CString str_show(fob_buf);
        CButton*pt = (CButton*)GetDlgItem(IDC_CHECK2);
        //get context from edit1
        UpdateData(true);
        GetDlgItem(IDC_EDIT2)->GetWindowText(str);
        if (IsDlgButtonChecked(IDC_CHECK2) == BST_CHECKED)
        {
            if (str.GetLength() == 0)
            {
                pt->SetCheck(false);
                AfxMessageBox(_T("zero length"));
                return;
            }
        }
        else if (str.GetLength() == 0)
        {
            return;
        }
        strcpy(buf, str);
        TCHAR chCurDir[MAX_PATH] = { 0 };
        GetCurrentDirectory(MAX_PATH, chCurDir);
        SetCurrentDirectory(_T("C:\\Windows"));
        HMODULE hModule = ::LoadLibrary(_T("AES_DLL.dll"));
        C2HFUN ToChar = (C2HFUN)::GetProcAddress(hModule, "char_to_hex");
        if (!ToChar(buf, fob_buf, 32))
        {
            pt->SetCheck(false);
            AfxMessageBox(_T("data invalid."));
        }
        else
        {
            m_Edit2 = "";
            for (i = 0; i < 16; i++)
            {
                str_show.Format("%X", fob_buf[15 - i]);
                k = strlen(str_show);
                if (k == 0)
                {
                    m_Edit2 = "00";
                }
                else if (k == 1)
                {
                    m_Edit2 += "0";
                    m_Edit2 += str_show;
                }
                else
                {
                    m_Edit2 += str_show;
                }
            }
        }
        UpdateData(false);
        SetCurrentDirectory(chCurDir);
        ::FreeLibrary(hModule);
    }
    
    
    void CFobsignupDlg::checkBox3_BN_CLICKED()
    {
        // TODO: Add your control notification handler code here
        char buf[96];
        int i, k;
        unsigned char fob_buf[16];
        CString str;
        CString str_show(fob_buf);
        CButton*pt = (CButton*)GetDlgItem(IDC_CHECK3);
        //get context from edit1
        UpdateData(true);
        GetDlgItem(IDC_EDIT3)->GetWindowText(str);
        if (IsDlgButtonChecked(IDC_CHECK3) == BST_CHECKED)
        {
            if (str.GetLength() == 0)
            {
                pt->SetCheck(false);
                AfxMessageBox(_T("zero length"));
                return;
            }
        }
        else if (str.GetLength() == 0)
        {
            return;
        }
        strcpy(buf, str);
        TCHAR chCurDir[MAX_PATH] = { 0 };
        GetCurrentDirectory(MAX_PATH, chCurDir);
        SetCurrentDirectory(_T("C:\\Windows"));
        HMODULE hModule = ::LoadLibrary(_T("AES_DLL.dll"));
        C2HFUN ToChar = (C2HFUN)::GetProcAddress(hModule, "char_to_hex");
        if (!ToChar(buf, fob_buf, 32))
        {
            pt->SetCheck(false);
            AfxMessageBox(_T("data invalid."));
        }
        else
        {
            m_Edit3 = "";
            for (i = 0; i < 16; i++)
            {
                str_show.Format("%X", fob_buf[15 - i]);
                k = strlen(str_show);
                if (k == 0)
                {
                    m_Edit3 = "00";
                }
                else if (k == 1)
                {
                    m_Edit3 += "0";
                    m_Edit3 += str_show;
                }
                else
                {
                    m_Edit3 += str_show;
                }
            }
        }
        UpdateData(false);
        SetCurrentDirectory(chCurDir);
        ::FreeLibrary(hModule);
    }
    
    
    void CFobsignupDlg::checkBox4_BN_CLICKED()
    {
        // TODO: Add your control notification handler code here
        char buf[96];
        int i, k;
        unsigned char fob_buf[16];
        CString str;
        CString str_show(fob_buf);
        CButton*pt = (CButton*)GetDlgItem(IDC_CHECK4);
        //get context from edit1
        UpdateData(true);
        GetDlgItem(IDC_EDIT4)->GetWindowText(str);
        if (IsDlgButtonChecked(IDC_CHECK4) == BST_CHECKED)
        {
            if (str.GetLength() == 0)
            {
                pt->SetCheck(false);
                AfxMessageBox(_T("zero length"));
                return;
            }
        }
        else if (str.GetLength() == 0)
        {
            return;
        }
        strcpy(buf, str);
        TCHAR chCurDir[MAX_PATH] = { 0 };
        GetCurrentDirectory(MAX_PATH, chCurDir);
        SetCurrentDirectory(_T("C:\\Windows"));
        HMODULE hModule = ::LoadLibrary(_T("AES_DLL.dll"));
        C2HFUN ToChar = (C2HFUN)::GetProcAddress(hModule, "char_to_hex");
        if (!ToChar(buf, fob_buf, 32))
        {
            pt->SetCheck(false);
            AfxMessageBox(_T("data invalid."));
        }
        else
        {
            m_Edit4 = "";
            for (i = 0; i < 16; i++)
            {
                str_show.Format("%X", fob_buf[15 - i]);
                k = strlen(str_show);
                if (k == 0)
                {
                    m_Edit4 = "00";
                }
                else if (k == 1)
                {
                    m_Edit4 += "0";
                    m_Edit4 += str_show;
                }
                else
                {
                    m_Edit4 += str_show;
                }
            }
        }
        UpdateData(false);
        SetCurrentDirectory(chCurDir);
        ::FreeLibrary(hModule);
    }
    
    
    void CFobsignupDlg::checkBox5_BN_CLICKED()
    {
        // TODO: Add your control notification handler code here
        char buf[96];
        int i, k;
        unsigned char fob_buf[16];
        CString str;
        CString str_show(fob_buf);
        CButton*pt = (CButton*)GetDlgItem(IDC_CHECK5);
        //get context from edit1
        UpdateData(true);
        GetDlgItem(IDC_EDIT5)->GetWindowText(str);
        if (IsDlgButtonChecked(IDC_CHECK5) == BST_CHECKED)
        {
            if (str.GetLength() == 0)
            {
                pt->SetCheck(false);
                AfxMessageBox(_T("zero length"));
                return;
            }
        }
        else if (str.GetLength() == 0)
        {
            return;
        }
        strcpy(buf, str);
        TCHAR chCurDir[MAX_PATH] = { 0 };
        GetCurrentDirectory(MAX_PATH, chCurDir);
        SetCurrentDirectory(_T("C:\\Windows"));
        HMODULE hModule = ::LoadLibrary(_T("AES_DLL.dll"));
        C2HFUN ToChar = (C2HFUN)::GetProcAddress(hModule, "char_to_hex");
        if (!ToChar(buf, fob_buf, 32))
        {
            pt->SetCheck(false);
            AfxMessageBox(_T("data invalid."));
        }
        else
        {
            m_Edit5 = "";
            for (i = 0; i < 16; i++)
            {
                str_show.Format("%X", fob_buf[15 - i]);
                k = strlen(str_show);
                if (k == 0)
                {
                    m_Edit5 = "00";
                }
                else if (k == 1)
                {
                    m_Edit5 += "0";
                    m_Edit5 += str_show;
                }
                else
                {
                    m_Edit5 += str_show;
                }
            }
        }
        UpdateData(false);
        SetCurrentDirectory(chCurDir);
        ::FreeLibrary(hModule);
    }
    
    
    void CFobsignupDlg::checkBox6_BN_CLICKED()
    {
        // TODO: Add your control notification handler code here
        char buf[96];
        int i, k;
        unsigned char fob_buf[16];
        CString str;
        CString str_show(fob_buf);
        CButton*pt = (CButton*)GetDlgItem(IDC_CHECK6);
        //get context from edit1
        UpdateData(true);
        GetDlgItem(IDC_EDIT6)->GetWindowText(str);
        if (IsDlgButtonChecked(IDC_CHECK6) == BST_CHECKED)
        {
            if (str.GetLength() == 0)
            {
                pt->SetCheck(false);
                AfxMessageBox(_T("zero length"));
                return;
            }
        }
        else if (str.GetLength() == 0)
        {
            return;
        }
        strcpy(buf, str);
        TCHAR chCurDir[MAX_PATH] = { 0 };
        GetCurrentDirectory(MAX_PATH, chCurDir);
        SetCurrentDirectory(_T("C:\\Windows"));
        HMODULE hModule = ::LoadLibrary(_T("AES_DLL.dll"));
        C2HFUN ToChar = (C2HFUN)::GetProcAddress(hModule, "char_to_hex");
        if (!ToChar(buf, fob_buf, 32))
        {
            pt->SetCheck(false);
            AfxMessageBox(_T("data invalid."));
        }
        else
        {
            m_Edit6 = "";
            for (i = 0; i < 16; i++)
            {
                str_show.Format("%X", fob_buf[15 - i]);
                k = strlen(str_show);
                if (k == 0)
                {
                    m_Edit6 = "00";
                }
                else if (k == 1)
                {
                    m_Edit6 += "0";
                    m_Edit6 += str_show;
                }
                else
                {
                    m_Edit6 += str_show;
                }
            }
        }
        UpdateData(false);
        SetCurrentDirectory(chCurDir);
        ::FreeLibrary(hModule);
    }
    
    
    void CFobsignupDlg::checkBox7_BN_CLICKED()
    {
        // TODO: Add your control notification handler code here
        char buf[96];
        int i, k;
        unsigned char fob_buf[16];
        CString str;
        CString str_show(fob_buf);
        CButton*pt = (CButton*)GetDlgItem(IDC_CHECK7);
        //get context from edit1
        UpdateData(true);
        GetDlgItem(IDC_EDIT7)->GetWindowText(str);
        if (IsDlgButtonChecked(IDC_CHECK7) == BST_CHECKED)
        {
            if (str.GetLength() == 0)
            {
                pt->SetCheck(false);
                AfxMessageBox(_T("zero length"));
                return;
            }
        }
        else if (str.GetLength() == 0)
        {
            return;
        }
        strcpy(buf, str);
        TCHAR chCurDir[MAX_PATH] = { 0 };
        GetCurrentDirectory(MAX_PATH, chCurDir);
        SetCurrentDirectory(_T("C:\\Windows"));
        HMODULE hModule = ::LoadLibrary(_T("AES_DLL.dll"));
        C2HFUN ToChar = (C2HFUN)::GetProcAddress(hModule, "char_to_hex");
        if (!ToChar(buf, fob_buf, 32))
        {
            pt->SetCheck(false);
            AfxMessageBox(_T("data invalid."));
        }
        else
        {
            m_Edit7 = "";
            for (i = 0; i < 16; i++)
            {
                str_show.Format("%X", fob_buf[15 - i]);
                k = strlen(str_show);
                if (k == 0)
                {
                    m_Edit7 = "00";
                }
                else if (k == 1)
                {
                    m_Edit7 += "0";
                    m_Edit7 += str_show;
                }
                else
                {
                    m_Edit7 += str_show;
                }
            }
        }
        UpdateData(false);
        SetCurrentDirectory(chCurDir);
        ::FreeLibrary(hModule);
    }
    
    
    void CFobsignupDlg::checkBox8_BN_CLICKED()
    {
        // TODO: Add your control notification handler code here
        char buf[96];
        int i, k;
        unsigned char fob_buf[16];
        CString str;
        CString str_show(fob_buf);
        CButton*pt = (CButton*)GetDlgItem(IDC_CHECK8);
        //get context from edit1
        UpdateData(true);
        GetDlgItem(IDC_EDIT8)->GetWindowText(str);
        if (IsDlgButtonChecked(IDC_CHECK8) == BST_CHECKED)
        {
            if (str.GetLength() == 0)
            {
                pt->SetCheck(false);
                AfxMessageBox(_T("zero length"));
                return;
            }
        }
        else if (str.GetLength() == 0)
        {
            return;
        }
        strcpy(buf, str);
        TCHAR chCurDir[MAX_PATH] = { 0 };
        GetCurrentDirectory(MAX_PATH, chCurDir);
        SetCurrentDirectory(_T("C:\\Windows"));
        HMODULE hModule = ::LoadLibrary(_T("AES_DLL.dll"));
        C2HFUN ToChar = (C2HFUN)::GetProcAddress(hModule, "char_to_hex");
        if (!ToChar(buf, fob_buf, 32))
        {
            pt->SetCheck(false);
            AfxMessageBox(_T("data invalid."));
        }
        else
        {
            m_Edit8 = "";
            for (i = 0; i < 16; i++)
            {
                str_show.Format("%X", fob_buf[15 - i]);
                k = strlen(str_show);
                if (k == 0)
                {
                    m_Edit8 = "00";
                }
                else if (k == 1)
                {
                    m_Edit8 += "0";
                    m_Edit8 += str_show;
                }
                else
                {
                    m_Edit8 += str_show;
                }
            }
        }
        UpdateData(false);
        SetCurrentDirectory(chCurDir);
        ::FreeLibrary(hModule);
    }
    Fobsignup.cpp
    // FobsignupDlg.h : header file
    //
    
    #pragma once
    #include "mscomm1.h"
    #include "afxcmn.h"
    
    
    // CFobsignupDlg dialog
    class CFobsignupDlg : public CDialogEx
    {
    // Construction
    public:
        CFobsignupDlg(CWnd* pParent = NULL);    // standard constructor
    
    // Dialog Data
        enum { IDD = IDD_FOBSIGNUP_DIALOG };
    
        protected:
        virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    
    
    // Implementation
    protected:
        HICON m_hIcon;
    
        // Generated message map functions
        virtual BOOL OnInitDialog();
        virtual BOOL PreTranslateMessage(MSG* pMsg);
        afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
        afx_msg void OnPaint();
        afx_msg HCURSOR OnQueryDragIcon();
        DECLARE_MESSAGE_MAP()
    public:
        CString m_Edit1;
        CString m_Edit2;
        CString m_Edit3;
        CString m_Edit4;
        CString m_Edit5;
        CString m_Edit6;
        CString m_Edit7;
        CString m_Edit8;
        afx_msg void create_BN_CLICKED();
        afx_msg void Clear_BN_CLICKED();
        CString m_Edit9;
    //    CMscomm1 m_mscom;
        DECLARE_EVENTSINK_MAP()
        void OnCommMscomm1();
    //    afx_msg void OnBnClickedButton3();
        CProgressCtrl m_progressCtl;
        afx_msg void write_BN_CLICKED();
        afx_msg void Open_Close_BN_CLICKED();
        afx_msg void checkBox1_BN_CLICKED();
        afx_msg void checkBox2_BN_CLICKED();
        afx_msg void checkBox3_BN_CLICKED();
        afx_msg void checkBox4_BN_CLICKED();
        afx_msg void checkBox5_BN_CLICKED();
        afx_msg void checkBox6_BN_CLICKED();
        afx_msg void checkBox7_BN_CLICKED();
        afx_msg void checkBox8_BN_CLICKED();
        afx_msg void checkBox9_BN_CLICKED();
    };
    Fobsignup.h

     

  15. 编译运行:

Thank you.

End.

posted on 2020-05-25 10:29  Milo_lu  阅读(1226)  评论(0编辑  收藏  举报

导航