|
-
May 14th, 2010, 04:35 PM
#1
Assigning Text and Vairable to Text Field
Hey i need help, im still learning WinAPI, but i was wondering how do you set text and a variable to a textfield, so far ive got:
char cHours[5], cPay[5], cTotal[5];
float Hours, Pay, Total;
GetWindowText(GetDlgItem(hwnd, IDC_HOURS), cHours, MAX_PATH);
GetWindowText(GetDlgItem(hwnd, IDC_PAY), cPay, MAX_PATH);
Hours = atof(cHours);
Pay = atof(cPay);
Total = Hours * Pay;
sprintf(cTotal, "%.2f", Total);
SetWindowText(GetDlgItem(hwnd, IDC_TOTAL), cTotal);
It works, but i was wondering how do you set text, like i want it to say (when the user clickes the button) "Your Wage is:"
I was playing arounda little bit, trying of every solution i could think off, but to give you lot a better idea here is something (i know it doesnt work, kinda like pseudo code):
SetWindowText(GetDlgItem(hwnd, IDC_TOTAL), "You Wage is" + cTotal);
-
May 15th, 2010, 05:28 AM
#2
Re: Assigning Text and Vairable to Text Field
Maybe I don't understand your question but why not use
Code:
sprintf(cTotal, "Your Wage is %.2f", Total);
SetWindowText(GetDlgItem(hwnd, IDC_TOTAL), cTotal);
Since this requires that you're responsible for making sure that cTotal can hold enough characters you might prefer switching to use STL instead.
Code:
#include <sstream>
stringstream str;
str << "Your Wage is " << Total;
SetWindowText(GetDlgItem(hwnd, IDC_TOTAL), str.str().c_str());
-
May 15th, 2010, 05:49 AM
#3
Re: Assigning Text and Vairable to Text Field
Perfect Answer, thank you.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|