简体   繁体   English

从对话框编辑控件读取双

[英]Reading double from dialog edit control

I'm currently working on a program (for fun, this is not an assignment) that has multiple functions. 我目前正在研究具有多个功能的程序(出于娱乐目的,这不是一项任务)。 I have never used Win32 prior to yesterday and so I am rather new. 昨天之前我从未使用过Win32,所以我很新。 I used TheForger's tutorials to get started. 我使用TheForger的教程开始学习。 Right now, I have a dialog form with four edit boxes on it, charge1, charge2, charge3, and distance between particles. 现在,我有一个对话框窗体,上面有四个编辑框,charge1,charge2,charge3和粒子之间的距离。 I am getting this information and plugging it into the formula to solve for the amount of force between the particles. 我正在获取此信息并将其插入公式中,以解决粒子之间的作用力大小​​。

When I get to the part where I am getting the data from the edit box, I am receiving 0. 当我到达要从编辑框中获取数据的部分时,我收到0。

Here is my current code: 这是我当前的代码:

case ID_SOLVE:
{
    ZeroMemory(coulombDisplay, sizeof(coulombDisplay));

    GetDlgItemText(g_hCoulombs, IDC_DISTANCE, value1, 10);
    coulombsDistance = atof(value1);

    GetDlgItemText(g_hCoulombs, IDC_CHARGE1, value2, 10);
    coulombsStrength1Base = atof(value2);

    GetDlgItemText(g_hCoulombs, IDC_CHARGE2, value3, 10);
    coulombsStrength2Base = atof(value3);

    if(coulombsDistance == 0.0)
    {
        MessageBox(NULL, "WHAT", "WHAT", MB_OK | MB_ICONEXCLAMATION);
        DestroyWindow(g_hCoulombs);
    }

    coulombsResult = (coulombsStrength1Base * coulombsStrength2Base);
    coulombsResult /= (pow(coulombsDistance, 2));
    coulombsResult *= kConstant;

    sprintf(coulombDisplay, "%g", coulombsResult);
    SendDlgItemMessage(g_hCoulombs, IDC_FORCE, WM_SETTEXT, 0, (LPARAM)(LPCSTR)coulombDisplay);
}
break;

value1 , value2 , value3 , and coulombDisplay are all char[] that have been zero'd value1value2value3coulombDisplay都是char[] ,它们已被零

coulombsResult , coulombsDistance , coulombsStrength1Base , coulombsStrength2Base are all double s coulombsResultcoulombsDistancecoulombsStrength1BasecoulombsStrength2Base都是double s

The MessageBox stating "WHAT" is popping up each and every time that I run the program. 每当我运行程序时,都会弹出MessageBox指出“ WHAT”。 I am using the multi-byte character set of VC++ 2010. 我正在使用VC ++ 2010的多字节字符集。

Any help would be greatly appreciated. 任何帮助将不胜感激。

STATUS_ACCESS_DENIED has a good point. STATUS_ACCESS_DENIED有一个好处。 If you look at the documentation for atof you'll see that a error condition will result in 0.0 being returned. 如果查看atof的文档,将会看到错误情况将导致返回0.0。 I'd recommend writing to a log file or something to see what the data is going into the atof function. 我建议写入日志文件或其他内容,以查看将什么数据输入到atof函数中。 I'm wondering if your allocated char buffer is big enough. 我想知道您分配的char缓冲区是否足够大。

Try GetDlgItemTextA instead of GetDlgItemText to make sure you're getting back 8-bit characters and not 16-bit characters. 尝试使用GetDlgItemTextA而不是GetDlgItemText来确保您获取的是8位字符而不是16位字符。 A 16-bit character will usually have a zero in the upper half, and will be interpreted as an empty 8-bit string. 16位字符的上半部通常为零,并将被解释为空的8位字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM