这个问题应该很简单,但是由于我对它不熟悉,都困扰了我好几天了,其代码如下:
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,但是怎么调?
请不要嫌我烦,遇到这样的事情我也很烦,由于对这东动还不熟悉,就是这样无赖.................
最好给出原代码,不盛感激!!!!!!!!!!!!!!!!!!
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,但是怎么调?
请不要嫌我烦,遇到这样的事情我也很烦,由于对这东动还不熟悉,就是这样无赖.................
最好给出原代码,不盛感激!!!!!!!!!!!!!!!!!!
解决方案 »
- 获取网卡硬件物理地址的API有哪些?
- 删除记录失败,什么原因
- CStatusBar的size有默认最大宽度吗?取消它的size限制该怎么做呢?^_^
- 程序打包中的问题!紧急求救
- VC群:2774085
- 用installshield6.0打包我的程序,为什么要问你“是否重新启动计算机”?
- 基本功:在vc中能否运行命令行参数程序?
- 怎么实现树型的文件目录显示?有没有现成的控件或者类?
- 怎样创建一个相输入法窗口一样的无焦点窗口?
- 是有什么办法不用DLL而使用全局HOOK(或其他办法)把键盘、鼠标全部锁住
- 初学者,关于结构体的问题
- 请问该163图片上传工具是由什么框架?哪些窗体组成?应该如何实现?(附图)
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);
返回值为void类型,而且你那里的return是怎么return的啊,请给出代码,而且文字解释,英文中文我都不怕,就怕没代码,更怕有了代码不知怎么安排她.....................................,所以还是要靠大家的力量了,请不要嫌我烦
{
// 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的代码, 其他代码没经过调试, 有问题的话自己调试一下吧.
谢谢!谢谢!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
{
……public:
int m_nSelDay;
int m_nSelMonth;
……
}// 调用
int nIndex = comboctr3->GetCurSel();
if (CB_ERR != nIndex)
{
m_nSelDay = nIndex + 1; // index从0开始的
}这样在类的函数里就可以直接引用 赋值了