这个问题应该很简单,但是由于我对它不熟悉,都困扰了我好几天了,其代码如下:
CComboBox* comboctrl=(CComboBox*)GetDlgItem(IDC_COMBO1);
for(int i1=2000;i1<2051;i1++)
{
CString str_Item;
    str_Item.Format("%d",i1);
comboctrl->AddString(str_Item);
}
comboctrl->SetCurSel(0);
/////////////////////////////////////////////////////////////////
// Following for month
CComboBox* comboctr2=(CComboBox*)GetDlgItem(IDC_COMBO2);
for(int i2=1;i2<=18;i2++)
{
CString str_Item2;
str_Item2.Format("%d",i2);
comboctr2->AddString(str_Item2);
}
comboctr2->SetCurSel(0);
//Following for Day
CComboBox* comboctr3=(CComboBox*)GetDlgItem(IDC_COMBO3);
for(int i3=1;i3<29;i3++)
{
CString str_Item3;
str_Item3.Format("%d",i3);
comboctr3->AddString(str_Item3);
}
comboctr3->SetCurSel(0);
//Following for the hour
CComboBox* comboctr4=(CComboBox*)GetDlgItem(IDC_COMBO4);
for(int i4=0;i4<24;i4++)
{
CString str_Item4;
str_Item4.Format("%d",i4);
comboctr4->AddString(str_Item4);
}
comboctr4->SetCurSel(0);
//Following for minute
CComboBox* comboctr5=(CComboBox*)GetDlgItem(IDC_COMBO5);
for(int i5=0;i5<60;i5++)
{
CString str_Item5;
str_Item5.Format("%d",i5);
comboctr5->AddString(str_Item5);
}
comboctr5->SetCurSel(0);
//Following for seconv
CComboBox* comboctr6=(CComboBox*)GetDlgItem(IDC_COMBO6);
for(int i6=0;i6<60;i6++)
{
CString str_Item6;
str_Item6.Format("%d",i6);
comboctr6->AddString(str_Item6);
}
comboctr6->SetCurSel(0);
return TRUE;  // return TRUE  unless you set the focus to a control
}
由于要对用户所选的数据进行计算和处理,但是我们知道月有大小,二月有的28,有的29,肯定要根据恰面的年月来确定后面的Day,后面我还添加了如下代码,但是还不全,
void CMemoDlg::OnSelchangeCombo1() 
{
// TODO: Add your control notification handler code here
CComboBox* comboctrl=(CComboBox*)GetDlgItem(IDC_COMBO1);
int index=comboctrl->GetCurSel();
CString str_Sel;
comboctrl->GetLBText(index,str_Sel); 
//How can I disstill the value of str_Sel
// AfxMessageBox(str_Sel);
}void CMemoDlg::OnSelchangeCombo2() 
{
// TODO: Add your control notification handler code here
CComboBox* comboctr2=(CComboBox*)GetDlgItem(IDC_COMBO2);
int index=comboctr2->GetCurSel();
CString str_Sel2;
comboctr2->GetLBText(index,str_Sel2);
// AfxMessageBox(str_Sel2);
}
我知道用户所选的数据就是这里的str_Sel和ste_Sel2,是不是要把这里的str_Sel2带到前面的
CComboBox* comboctr3=(CComboBox*)GetDlgItem(IDC_COMBO3);
for(int i3=1;i3<29;i3++)
{
CString str_Item3;
str_Item3.Format("%d",i3);
comboctr3->AddString(str_Item3);
}
comboctr3->SetCurSel(0);
中来确定变量Day,但是怎么调?
请不要嫌我烦,遇到这样的事情我也很烦,由于对这东动还不熟悉,就是这样无赖.................
最好给出原代码,不盛感激!!!!!!!!!!!!!!!!!!

解决方案 »

  1.   

    可以增加两个 CMemoDlg 类的成员变量, 保存用户所选的月和年份, 再增加一个CMemoDlg 类的成员函数判断该月份的天数, 并return这个天数,在你要确定变量Day的地方调用这个函数得到该月份的天数;
      

  2.   


    int nDay;
    int nIndex = comboctr3->GetCurSel();// 1.直接取index+1
    if (CB_ERR != nIndex)
    {
        nDay = nIndex + 1;         // index从0开始的
    }// 2.取值后再转换
    LPTSTR pstr = new TCHAR(10);
    int GetLBText(nIndex, pstr);
    nDay = atoi(pstr);
      

  3.   

    xkyx_cn、xbq425200:你们应该知道void CMemoDlg::OnSelchangeCombo2()  
    返回值为void类型,而且你那里的return是怎么return的啊,请给出代码,而且文字解释,英文中文我都不怕,就怕没代码,更怕有了代码不知怎么安排她.....................................,所以还是要靠大家的力量了,请不要嫌我烦
      

  4.   

    class CMemoDlg : public CDialog
    {
    // Construction
    public:
            int MonthForDays();  //根据参数得到天数
    int m_iSelYear; //保存用户所选年
    int m_iSelMonth; //保存用户所选的月份
    .....
    }
    CMemoDlg::CMemoDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CMemoDlg::IDD, pParent)
    {
         m_iSelYear=1; //初始化为1
         m_iSelMonth=1;
    //{{AFX_DATA_INIT(CMemoDlg)
    // NOTE: the ClassWizard will add member initialization here
    //}}AFX_DATA_INIT
    }void CMemoDlg::OnSelchangeCombo1()  

    // TODO: Add your control notification handler code here 
    CComboBox* comboctrl=(CComboBox*)GetDlgItem(IDC_COMBO1); 
    int index=comboctrl-> GetCurSel();//CString str_Sel; 
    //comboctrl-> GetLBText(index,str_Sel);  
    //How can I disstill the value of str_Sel 
    // AfxMessageBox(str_Sel);//int nDay;
    //int nIndex = comboctr3->GetCurSel();// 1.直接取index+1
    if (CB_ERR != nIndex)
    {
        m_iSelYear = nIndex + 1;         // index从0开始的
    }// 2.取值后再转换
    LPTSTR pstr = new TCHAR(10);
    int GetLBText(nIndex, pstr);
    m_iSelYear = atoi(pstr); }//对于月份的保存也是一样的.....
    //根据参数得到天数
    int CMemoDlg::MonthForDays()
    {
    if (m_iSelMonth == 4 || m_iSelMonth == 6 || m_iSelMonth == 9 || m_iSelMonth == 11) 
    {
    return 30;
    }
    if ( m_iSelMonth == 2 )
    {
    if (m_iSelYear % 4 == 0 && (m_iSelYear % 100 != 0 || m_iSelYear % 400 ===0))
    {
    return 29;
    }
    else
    {
    return 28;
    }
    }
    return 31;
    }//在你要确定变量Day的地方调用MonthForDays函数得到该月份的天数;
    //借用了xkyx_cn的代码, 其他代码没经过调试, 有问题的话自己调试一下吧.
      

  5.   

    但是现在还有个问题,我知道上面的,str_Sel,str_Sel2都是用户选择的数据,我要利用这些数据,但是他的返回类型是VOID,我的同事告诉我说可以用指针或是全局变量,但是我记得VC中没有这样的特异功能啊,要怎么才知道用户选的数据是哪个,怎么调用?各位师傅,请发言哈,分少了我再加就是了
    谢谢!谢谢!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      

  6.   

    可以在对话框类的定义里面加上成员变量:class CMemoDlg : public CDialog
    {
       ……public:
        int m_nSelDay;
        int m_nSelMonth;   
        ……
    }// 调用
    int nIndex = comboctr3->GetCurSel();
    if (CB_ERR != nIndex)
    {
        m_nSelDay = nIndex + 1;         // index从0开始的
    }这样在类的函数里就可以直接引用 赋值了