Click here to Skip to main content
11,643,493 members (69,252 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ MFC dialog convert GUI
Hello The Code Project Community,

I'm new to writing code for Visual C++ GUI's. I'm trying to make an application to convert Horsepower to Kilowatts and vise versa.

I am able to convert it when I instantiate horsePower into a random number like 300 (double horsePower = 300.0) but what I wanted is that when I press the button.. it would take the value in the edit control box and convert that and display it into the results box. Picture provided below.

I had many errors beforehand experimenting from what I searched online and it included converting double into CStrings and vice versa and LPCTSTR and whatnot.

Help would be appreciated.

void CTry_4Dlg::OnBnClickedButton1()
{
{
	// TODO: Add your control notification handler code here
	UpdateData(true);
	double horsePower = 0.0;
	CString hP;							
	horsePower = horsePower * 0.745699872;	// conversion to kilowatts
	hP.Format(_T("%f"),horsePower);
	m_inputVariable.SetWindowText(hP);
	UpdateData(false);
}
 
void CTry_4Dlg::OnBnClickedButton3()
{
    // TODO: Add your control notification handler code here
    UpdateData(true);
    double kiloWatts = 0;                  // initialize kiloWatts
    CString kW;                             
    kiloWatts = kiloWatts * 1.34102209;     // conversion to horsepower
    kW.Format(_T("%f"),kiloWatts);
    m_inputVariable.SetWindowText(kW);
    UpdateData(false);
}
 
}

<img src="http://i53.tinypic.com/29lifc7.png"></img>
Posted 1-Nov-10 10:25am
Edited 1-Nov-10 10:28am
v3

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You need to add member variables for the two EDIT boxes, and set them to be of type double. Now in your button's click function, call UpdateData(TRUE) and the variables will update to the correct values (and will be of type double).

In VS 2010, adding a member variable is as simple as right clicking on the edit control in the designer and selecting Add Variable.
  Permalink  
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 530
1 jyo.net 484
2 DamithSL 353
3 Afzaal Ahmad Zeeshan 253
4 Sergey Alexandrovich Kryukov 230
0 OriginalGriff 795
1 DamithSL 611
2 Mika Wendelius 494
3 jyo.net 484
4 Afzaal Ahmad Zeeshan 404


Advertise | Privacy | Mobile
Web01 | 2.8.150731.1 | Last Updated 1 Nov 2010
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100