vc6 控件 message map

1. 頭文件.h 關於afx_message 定義:

class CTest : public CDialog
{

public:

// Dialog Data
 //{{AFX_DATA(CTest)
 CTest(CWnd* pParent = NULL);   // standard constructor

     UINT m_time;  //④ 文本框 數字

     CString m_name; //④ 文本框 字符串

     CButton m_BtnDel;  //③列表框界面的按鈕
     CComboBox m_ComboSpeed;   //②下拉菜單

     CListCtrl m_ListTest;//③列表框

     CDateTimeCtrl m_timeStart; //⑤時間插件

     CSliderCtrl m_SliderSpeed;  //⑥滑動條 速度

     CButtonBMP m_btnTop;  // 7圖片按鈕 

     CTabCtrl m_tabCfg;  //⑧tab窗口

// Overrides
     // ClassWizard generated virtual function overrides
     //{{AFX_VIRTUAL(CTest)
protected:
     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
     //}}AFX_VIRTUAL

protected:

     // Generated message map functions
     //{{AFX_MSG(CTest)

     virtual BOOL OnInitDialog();  //初始化函數
     virtual void OnOK();
     virtual void OnCancel();
     afx_msg void OnButtonStart();
     afx_msg void OnButtonStop();
     afx_msg void OnButtonOn();
     afx_msg void OnButtonOff();
    afx_msg void OnButtonCall();
    afx_msg void OnButtonSet();
    afx_msg void OnButtonClear();
    afx_msg void OnButtonSave();  //① 按鈕

    afx_msg void OnSelchangeComboSpeed(); //②下拉菜單

    afx_msg void OnClickListTest(NMHDR* pNMHDR, LRESULT* pResult);  //③列表框

    afx_msg void OnReleasedcaptureSliderSpeed(NMHDR* pNMHDR, LRESULT* pResult); //⑥滑動條

    afx_msg void OnSelchangeTabRemotecfg(NMHDR* pNMHDR, LRESULT* pResult);    //⑧tab窗口
 //}}AFX_MSG
 DECLARE_MESSAGE_MAP()

};

2. 控件和消息關聯xx.cpp文件:

CTest::CTest(CWnd* pParent /*=NULL*/)
 : CDialog(CTest::IDD, pParent)
{
 m_btnTop.LoadBitmaps(IDB_TOP, IDB_TOPUP, IDB_TOPDOWN);
 //{{AFX_DATA_INIT(CTest)


 //}}AFX_DATA_INIT


}

 

static CHAR *cSpeedList[] = {"Full Speed", "1/2 Speed", "1/4 Speed", "1/8 Speed", NULL};

void CTest::DoDataExchange(CDataExchange* pDX)
{
 CDialog::DoDataExchange(pDX);
 //{{AFX_DATA_MAP(CTest)
 DDX_Control(pDX, IDC_BUTTON_DEL, m_BtnDel);
 DDX_Control(pDX, IDC_LIST_TEST, m_ListTest); //③列表框  變量和控件相關聯
 DDX_Control(pDX, IDC_COMBO_SPEED, m_ComboSpeed); //②下拉菜單 變量和控件相關聯
 DDX_Text(pDX, IDC_EDIT_TIME, m_time); //④ 文本框  變量和控件相關聯(DDV_MinMaxInt(pDX, m_time, 1, 255); DDV_MinMaxUInt(pDX, m_time, 0, 512);)

 DDX_Control(pDX, IDC_TIME_START, m_timeStart); //⑤時間插件

 DDX_Text(pDX, IDC_EDIT_NAME, m_name); //④ 文本框  變量和控件相關聯
 DDV_MaxChars(pDX, m_name, 30);
 DDX_Control(pDX, IDC_BUTTON_UP, m_btnTop);   // 7圖片按鈕 

 DDX_Control(pDX, IDC_TAB_CFG, m_tabCfg);  //⑧tab窗口

 

 //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CTest, CDialog)
 //{{AFX_MSG_MAP(CTest)
 ON_BN_CLICKED(IDC_BUTTON_START, OnButtonStart)
 ON_BN_CLICKED(IDC_BUTTON_ON, OnButtonOn)
 ON_BN_CLICKED(IDC_BUTTON_OFF, OnButtonOff)
 ON_BN_CLICKED(IDC_BUTTON_CALL, OnButtonCall)
 ON_BN_CLICKED(IDC_BUTTON_SET, OnButtonSet)
 ON_BN_CLICKED(IDC_BUTTON_CLEAR, OnButtonClear)
 ON_BN_CLICKED(IDC_BUTTON_SAVE, OnButtonSave)  //① 按鈕

 ON_CBN_SELCHANGE(IDC_COMBO_SPEED, OnSelchangeComboSpeed) //②下拉菜單

 ON_NOTIFY(NM_CLICK, IDC_LIST_TEST, OnClickListTest) //③列表框

 ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER_SPEED, OnReleasedcaptureSliderSpeed) //⑥滑動條

 ON_NOTIFY(TCN_SELCHANGE, IDC_TAB_CFG, OnSelchangeTabcfg)   //⑧tab窗口

 //}}AFX_MSG_MAP
END_MESSAGE_MAP()

3. 消息實現xx.cpp文件:

 

void CTest::OnButtonSave()  //① 按鈕
{
   // TODO: Add your control notification handler code here

   // UpdateData(TRUE);或UpdateData(FALSE};

....

}

void CTest::OnSelchangeComboSpeed()   //②下拉菜單
{
   // TODO: Add your control notification handler code here
   m_speed = m_ComboSpeed.GetCurSel();
    //將修改的值同步到窗體顯示
    this->UpdateData(FALSE);
}

void CTest::OnClickListTest(NMHDR* pNMHDR, LRESULT* pResult)  //③列表框
{
 // TODO: Add your control notification handler code here
 NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
 int nItem = pNMListView->iItem;
 m_Index = nItem;
 //設置控件是否可見
 if(-1 == nItem)
 {
  this->m_BtnDel.EnableWindow(FALSE);
  return ;
 }
 this->m_BtnDel.EnableWindow(TRUE);

 *pResult = 0;
}

BOOL CTest::OnInitDialog()
{
    CDialog::OnInitDialog();
 
     ::GSetItemFont(this); //統一字體
     // TODO: Add extra initialization here

     int i;
    char acBuf[32];
    m_ComboSpeed.ResetContent();
     for(i = 0; cSpeedList[i] != NULL; i++)
    {
        sprintf(acBuf,"%s", GetTxt(cSpeedList[i]));
        m_ComboSpeed.AddString(acBuf);
    }

    SYSTEMTIME stTime;
     this->m_timeStart.GetTime(&stTime);  //⑤時間插件
     stTime.wHour = schStart[0].hour;
     stTime.wMinute = schStart[0].minute;
     this->m_timeStart.SetTime(&stTime);

    this->m_timeStart.SetFormat("HH:mm");

    m_btnTop.OnSetMSG(TRUE);   //7 圖片按鈕

    i=1;

    this->m_tabCfg.InsertItem(i++, ::GetTxt("NewTab"));

   

    CRect rtDlg;
    CRect rtTab;
    RECT rect;
    this->m_tabCfg.GetClientRect(&rtDlg);      //⑧設置tab窗口大小位置,創建窗口
    this->m_tabCfg.GetItemRect(0, &rtTab);

    rect.left    = rtDlg.left+2;
    rect.right   = rtDlg.right-4;
    rect.top     = rtDlg.top+rtTab.Height()+4;
    rect.bottom  = rtDlg.bottom-8;

    m_dlgNewTab.Create(IDD_TAB, &m_tabCfg);
    m_dlgNewTab.MoveWindow(&rect, FALSE);

 

}

void CTest::OnReleasedcaptureSliderSpeed(NMHDR* pNMHDR, LRESULT* pResult)  //⑥滑動條
{
 // TODO: Add your control notification handler code here
 
// m_StcSpeed.Format("%d", m_SliderSpeed.GetPos());
// UpdateData(FALSE);
 *pResult = 0;
}

void CTest::OnSelchangeTabcfg(NMHDR* pNMHDR, LRESULT* pResult)  //⑧tab窗口
 {
 // TODO: Add your control notification handler code here
 m_OthersShowWindow(SW_HIDE);
 

 switch(this->m_tabCfg.GetCurSel())
 {
 case 0:
  m_dlg0.ShowWindow(SW_SHOW);
  break;
 case 1:
  m_dlg1.ShowWindow(SW_SHOW);
  break;
 case 2:
  m_dlg2.ShowWindow(SW_SHOW);
  break;
  default:
  break;
 }
 *pResult = 0;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章