0

Please observe the following code:

double rate=GetDlgItemInt(IDC_EDIT1,0,TRUE); double term=GetDlgItemInt(IDC_EDIT2,0,TRUE); double amount=GetDlgItemInt(IDC_EDIT3,0,TRUE); double final;

CString Content(_T("Thanks for using the calculator"));
if (CTaskDialog::IsSupported())
{
CString Heading(_T("Successfully calculated"));
CString Title(_T("Interest Calculator"));
CString Collapsed(_T("Collapsed Info"));
CString Expanded(_T("Expanded Info"));
CString Information(_T("Your information you want to calculate"));
CTaskDialog dia(Content,Heading,Title,TDCBF_OK_BUTTON);

final=amount*pow((1+rate),term);
SetDlgItemInt(IDC_EDIT4,final,FALSE);
dia.SetMainIcon(TD_ERROR_ICON);
dia.DoModal();
}

}

What I have tried to do is to create a GUI for a calculator which calculates the future value of a fund. I want to have all the variables as doubles. But the part of the code "GetDlgItemInt" is clearly meant for integers and I do not know how to alter it to get a double. Please help me with this. Thanks in advance.

user81883
  • 123
  • 2
  • 8

2 Answers2

1

An equivalent function that returns a double could be:

double GetDlgItemDouble(HWND hWnd, UINT uId)
{
    TCHAR tchBuf[80];
    GetDlgItemText(hWnd, uId, tchBuf, 80);
    return _ttof(tchBuf);
}

You may want to add error checking in case the string contains non-numeric characters, etc.

Jonathan Potter
  • 36,172
  • 4
  • 64
  • 79
0

Isn't it better storing those values as CTaskDialog members?
(Sorry forgot what G(S)etDlgItem did)

You can do

float myFloat = 3.2;

CString text;
text.Format( L"%f", myFloat );

SetDlgItemText( yourID, text );
Niyaz Ivanov
  • 657
  • 5
  • 6