I know I made a post earlier relating to this, but I think it is full bad questions on my behalf. This is the cleaner better way to ask for help, I think.
The program asks the user for input. The input should be stored into the HWNDedit variable, I think. Yet I have no idea how I would save that data into that variable once the user writes it into the EDIT box.
Thanks for any help.
Much obliged John
for current Problem.
I'm posting the full code I have now. I'm having a problem when I read off the second EDIT TEXT BOX.
After debugging I saw that when I get to this line of code
What ever value was entered in the first EDIT TEXT BOX, the GetDlgItemTextA function is reading that same value and storring it into yield_buffer.
I traced the whole code and everything seems to be in the right place.
#include <windows.h>
#include <cstring>
#include <string>
#include "RetirementPlanner.h"
#define IDC_EDIT_CONTRIBUTION 1000
#define IDC_EDIT_YIELD 1000
#define IDC_EDIT_AGE 1000
#define IDC_EDIT_retirementAGE 1000
#define IDC_EDIT_INFLATION 1000
using namespace std;
RetirementPlanner savings;
double dContribute = 0;
double dInterest = 0;
int iAgeNow = 0;
int iAgeThen = 0;
double dInflate = 0;
LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);
HWND hWnd;
HWND hwndEdit;
HWND hwndTotPresentValue;
HWND hwndTotInterest;
HWND hwndContribution;
HWND hwndYield;
HWND hwndAge;
HWND hwndRetirementAge;
HWND hwndInflation;
HWND hwndButtonEnter;
HWND hwndButtonClear;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASS wc;
MSG msg;
wc.lpszClassName = "Window";
wc.lpfnWndProc = MainWndProc;
wc.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = " ";
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
RegisterClass(&wc);
hWnd = CreateWindow ("Window", "Retirement Planner",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
500,
400,
NULL,
NULL,
hInstance, NULL);
ShowWindow(hWnd,nCmdShow);
while (GetMessage(&msg, NULL, 0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return(int) msg.wParam;
}
LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
HWND hwndCtl = (HWND) lParam;
switch(msg)
{
HINSTANCE hInstance;
case WM_CREATE:
hwndContribution = CreateWindow ("EDIT", NULL, WS_VISIBLE |
WS_CHILD | WS_BORDER | ES_NUMBER,
100, 10, 90, 20, hWnd,
(HMENU)IDC_EDIT_CONTRIBUTION,
GetModuleHandle(NULL), NULL);
hwndYield = CreateWindow ("EDIT", NULL, WS_VISIBLE | WS_CHILD |
WS_BORDER | ES_NUMBER, 100, 35, 90, 20,
hWnd, (HMENU)IDC_EDIT_YIELD ,
GetModuleHandle(NULL), NULL);
hwndAge = CreateWindow ("EDIT", NULL, WS_VISIBLE | WS_BORDER |
|ES_NUMBER, 100, 60, 90, 20, hWnd,
(HMENU)IDC_EDIT_AGE,
GetModuleHandle(NULL), NULL);
hwndRetirementAge = CreateWindow ("EDIT", NULL, WS_VISIBLE |
WS_CHILD | WS_BORDER | ES_NUMBER,
100, 85, 90, 20, hWnd, (HMENU)
IDC_EDIT_retirementAGE ,
GetModuleHandle(NULL), NULL);
hwndInflation = CreateWindow ("EDIT", NULL, WS_VISIBLE | WS_CHILD |
WS_BORDER | ES_NUMBER, 100, 110, 90,
20, hWnd, (HMENU)IDC_EDIT_INFLATION,
GetModuleHandle(NULL), NULL);
hwndButtonEnter = CreateWindow ("BUTTON", "Enter", WS_VISIBLE |
WS_CHILD | BS_DEFPUSHBUTTON,
320, 240, 55, 30, hWnd,
NULL, hInstance, NULL);
hwndButtonClear = CreateWindow ("BUTTON", "Reset", WS_VISIBLE |
WS_CHILD | BS_DEFPUSHBUTTON,
256, 240, 55, 30, hWnd, NULL,
hInstance, NULL);
case WM_COMMAND:
switch(wParam)
{
case BN_CLICKED:
if(hwndCtl == hwndButtonEnter)
{
// setting up contribution
char contribution_buffer[32];
GetDlgItemTextA(hWnd,IDC_EDIT_CONTRIBUTION, contribution_buffer, 32);
double contribution = atoi(contribution_buffer);
savings.setContribution(contribution); //class
// setting up yield
char yield_buffer[32];
GetDlgItemTextA(hWnd, IDC_EDIT_YIELD, yield_buffer, 32);
double yield = atoi(yield_buffer);
char age_buffer[32];
GetDlgItemTextA(hWnd, IDC_EDIT_AGE, age_buffer, 32);
int age = atoi(age_buffer);
// back to string
_gcvt(contribution, 10, contribution_buffer);
_gcvt(yield, 10, yield_buffer);
_gcvt(age, 10, age_buffer);
hwndEdit = CreateWindow ("EDIT", contribution_buffer,
WS_VISIBLE | WS_CHILD | WS_BORDER |
ES_LEFT, 10, 260, 90, 20, hWnd,
NULL, hInstance, NULL);
hwndTotPresentValue = CreateWindow ("EDIT", yield_buffer,
WS_VISIBLE | WS_CHILD |
WS_BORDER | ES_LEFT, 10,
285, 90, 20, hWnd, NULL,
hInstance, NULL);
hwndTotInterest = CreateWindow ("EDIT", age_buffer, WS_VISIBLE
| WS_CHILD | WS_BORDER
|ES_LEFT, 10, 310, 90, 20,
hWnd, NULL, hInstance, NULL);
}
else
if(hwndCtl == hwndButtonClear)
{
SetWindowText(hwndEdit, "");
SetWindowText(hwndTotPresentValue, "");
SetWindowText(hwndTotInterest, "");
SetWindowText(hwndContribution, "");
SetWindowText(hwndYield, "");
SetWindowText(hwndAge, "");
SetWindowText(hwndRetirementAge, "");
SetWindowText(hwndInflation, "");
}
}
break;
case WM_DESTROY: PostQuitMessage(0);
return 0;
default: return DefWindowProc(hWnd, msg, wParam, lParam);
}
return 0;
}