2017年3月17日 星期五

[VC]How To DoDataExchange, BEGIN_MESSAGE_MAP

 

目的:

VC物件( edit, combo, radio)可自動偵測變化, 如修改文字,拉捲軸等

透過VC的宣告及DoDataExchangeBEGIN_MESSAGE_MAP方法

 

 

 

1.宣告(.h)

 

 

protected:

        //物件

        CEdit               m_EDIT_FLASHID0

        CLabel             m_STATIC_ERRCODE[4]; // calble物件宣告,在DoDataExchange綁定後,可直接存取物件資料,如下"ps1-1, ps1-2"

        CButton m_CHECK_AUTO;// calble物件宣告,在DoDataExchange綁定後,可直接存取物件資料,如下"ps1-1, ps1-2"

 

        //自動執行程式

        afx_msg void OnRadioToggle1();

        afx_msg void OnSelChangeComboCardSize();

        afx_msg void OnUpdateEditFLASHID0();

 

private:

        int           m_RadioSelectIniMode;//radio單選物件

 

 

 

 

2.程式執行(.cpp)

 

//DoDataExchange 綁定物件名 DDX_Control()DDX_Radio()

 

void CDlgBinGrade::DoDataExchange(CDataExchange* pDX)

{

        CDialog::DoDataExchange(pDX);

 

        DDX_Radio(pDX, IDC_RADIO_AUTO, m_RadioSelectIniMode);           //物件名IDC_RADIO_AUTO

        DDX_Control(pDX, IDC_EDIT_FLASHID_0, m_EDIT_FLASHID0);      // 物件名IDC_EDIT_FLASHID_0

 

        DDX_Control(pDX, , m_EDIT_FLASHID0);     

        DDX_Control(pDX, IDC_STATIC_TITLE_PORT2, m_STATIC_TITLE_PORT[1]);               

    DDX_Control(pDX, IDC_STATIC_BB0, m_STATIC_BB[0]);

   

 

    DDX_Control(pDX, IDC_STATIC_ERRCODE_PORT1, m_STATIC_ERRCODE[0]);//ps1-1

    DDX_Control(pDX, IDC_CHECK_AUTO, m_CHECK_AUTO);   //ps1-1,

 

 

 

 

3.加進BEGIN_MESSAGE_MAP

 

//-------------------------------------------------------------------------------------------------

BEGIN_MESSAGE_MAP(CdlgSettingPage2, CDialog)

        ON_BN_CLICKED(IDC_RADIO_TOGGLE1, OnRadioToggle1) //物件名IDC_RADIO_TOGGLE1

        ON_CBN_SELCHANGE(IDC_COMBO_CARDSIZE, OnSelChangeComboCardSize) //物件名IDC_COMBO_CARDSIZE

        ON_EN_UPDATE(IDC_EDIT_FLASHID_0, OnUpdateEditFLASHID0) //物件名IDC_EDIT_FLASHID_0

        //}}AFX_MSG_MAP

END_MESSAGE_MAP()  

 

 

 

 

4.程式執行

 

//-------------------------------------------------------------------------------------------------

void CdlgSettingPage2::OnUpdateEditFLASHID0()

{

    this->m_EDIT_FLASHID0.GetWindowText(m_SPLIT_FLASH_ID.s_ID0);

        //this->m_EDIT_FLASHID0.SetWindowText("0");

}

 

 

 

//-------------------------------------------------------------------------------------------------

void CdlgSettingPage2::OnSelChangeComboCardSize()

{

        CComboBox     *pComboBox;

    int           CurSel;

    //int              nIndex;

    CString       sTmp, str;

 

    pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_CARDSIZE);

    CurSel = pComboBox->GetCurSel();

    if (CurSel == CB_ERR) {

        return;

    }

        pComboBox->GetLBText(CurSel, str);

        this->m_RDTSetting.Card_Size = atoi(str);

}

 

 

 

//-------------------------------------------------------------------------------------------------

void CdlgSettingPage2::OnRadioToggle1()

{

    GetDlgItem(IDC_COMBO_TOGGLE1)->EnableWindow(TRUE);

    GetDlgItem(IDC_COMBO_TOGGLE2)->EnableWindow(FALSE);

        this->OnSelChangeComboToggle1();

}

 

 

 

//-------------------------------------------------------------------------------------------------

void CDlgBinGrade::ShowErrorCode(IN int ItemIndex, IN int ErrorCode)//ps1-2

{

        char      Buffer[16];

        ::sprintf(Buffer, "%.4d", ErrorCode);

 

    this->m_STATIC_ERRCODE[ItemIndex].SetText(Buffer);    

}

 

 

void CDlgBinGrade::init_BinGradeEnv()//ps1-2

{

    this->m_CHECK_AUTO.SetCheck(true);

}

 

 

 

 

 

 

Best regards,

Rex Wu

Tel. (03) 552-6568#1181

Solid State System Co., Ltd.

________________________________________ 3S CONFIDENTIALITY NOTICE: This message and all attachments may contain legally privileged and confidential information. Any unauthorized review, use or distribution by anyone other than the intended recipient is strictly prohibited. If you are not the intended recipient, please contact the sender immediately by replying to the message and delete all copies. Thank you.

沒有留言:

張貼留言