yanglei3696 2020-01-26 07:58 采纳率: 0%
浏览 264

MFC listcontrol report样式存取一行数据并计算。

目的:使用MFC listcontrol report样式存取一行数据,并用这一行数据按照一个公式进行计算。
我的问题:输入不同数据后,调用后发现结构体数组里的值都一样。
第三MessageBox(damage[0].ZheSheLv);
MessageBox(damage[0].HouDu);
这两个值总显示一样的,问什么??????

操作:
1.在头文件里,建立了一个结构体,全局声明结构体数组,;
typedef struct damagePos
{
CString MianShu;
CString BanJing;
CString ZheSheLv;
CString HouDu;
};
static damagePos damage[50];
2.对话框初始化
DWORD dwStyle=m_store_items.GetExtendedStyle();
dwStyle|=LVS_EX_FULLROWSELECT;
dwStyle|=LVS_EX_GRIDLINES;

m_store_items.SetExtendedStyle(dwStyle);
m_store_items.InsertColumn(0,"光学面数",LVCFMT_LEFT,80);
m_store_items.InsertColumn(1, _T("半径"), LVCFMT_CENTER,100);
m_store_items.InsertColumn(2, _T("折射率"), LVCFMT_CENTER,100);
 m_store_items.InsertColumn(3, _T("厚度"), LVCFMT_CENTER,100);
m_edit_pos.ShowWindow(SW_HIDE);

2.添加edit控件,离焦事件函数,存取输入的数据
void CMy3Dlg::OnKillfocusEdit1()
{
// TODO: Add your control notification handler code here

CString str0;
m_edit_pos.GetWindowTextA((LPTSTR)(LPCTSTR)str0,-1);//获取输入框中的数据
m_store_items.SetItemText(m_ListRow,m_ListCol,str0);//设置选中框的字符为刚刚输入的值
//将输入的数据传递给结构体数组
//damagePos damage[50]

if(m_ListCol%3==0)
{
MessageBox("输入厚度");
MessageBox(str0);
damage[m_ListRow].HouDu=str0;
}

else if(m_ListCol%2==0)
{
   MessageBox("输入折射率");
   MessageBox(str0);
   //strcpy(damage[m_ListRow].ZheSheLv,str0);
   damage[m_ListRow].ZheSheLv=str0;
   //MessageBox(damage[m_ListRow].ZheSheLv);
}
else
{
     MessageBox("进入输入半径");
     MessageBox(str0);
    damage[m_ListRow].BanJing="半径";

}
3.建立button控件,添加事件,目的使用上面的结构体数组中的数据完成计算。

MessageBox(damage[0].ZheSheLv);
MessageBox(damage[0].HouDu);
return;
double num1,num2,num3,num4,num5;
CString str1;
char ch5[10];
str1=itoa(m_ListRow,ch5,10);
MessageBox(str1);
MessageBox(damage[m_ListRow].ZheSheLv);
CString str2;
char ch6[10];
str2=itoa(m_ListRow,ch6,10);
MessageBox(damage[m_ListRow].HouDu);
CString str3;
char ch7[10];
str3=itoa(m_ListRow,ch7,10);
MessageBox(damage[m_ListRow].BanJing);
return;
// TODO: Add your control notification handler code here
for(int i=0;i<m_ListRow+1;i++)
{
if(m_ListRow==0)
{
// MessageBox("niaho");
num1=10 /atof(damage[m_ListRow].BanJing);
num2=num1*(1/atof(damage[m_ListRow].HouDu)) ;
num3=num1-num2;
num4=atof(damage[m_ListRow].BanJing)+atof(damage[m_ListRow].BanJing)*num2/num3;
num5=num4-atof(damage[m_ListRow].HouDu);
CString str;
char ch4[10];
str=gcvt(num2,8,ch4);
MessageBox(str);

   }}
  • 写回答

1条回答 默认 最新

  • threenewbee 2020-01-26 23:34
    关注

    damage[m_ListRow].HouDu=str0;

    damage[m_ListRow].ZheSheLv=str0;
    都是str0

    是不是其中一个写错了。

    评论

报告相同问题?

悬赏问题

  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥15 python天天向上类似问题,但没有清零
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 C#调用python代码(python带有库)
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?