Click to See Complete Forum and Search --> : MultiLine Edit Box Problem


RJK
May 29th, 2010, 09:24 AM
I am creating a betting program, basically what it does it it calculates the bet and outputs it into a Multi Line Edit Box, but it only allows a certain amount of characters:


char szNum[20], szBet[20], szPrice1[4], szTotal[20], szReturns[20], szOutput[MAX_PATH];
char *cPrice1[1];
stringstream strBet, strPrice1, strOutput;
int nAdd;
float fReturns, fTot, fRet;

GetWindowText(GetDlgItem(hwnd, IDC_STAKE), szNum, MAX_PATH);
GetWindowText(GetDlgItem(hwnd, IDD_BETDD), szBet, MAX_PATH);
GetWindowText(GetDlgItem(hwnd, IDC_PRICE1), szPrice1, MAX_PATH);

strBet.str(szBet);

if (strlen(szNum) == 0)
{
MessageBox(NULL, "Please Enter a Stake", "Error", MB_OK | MB_ICONWARNING);
} else if (strlen(szBet) == 0) {
MessageBox(NULL, "You have not selected a Bet Type", "Error", MB_OK | MB_ICONWARNING);
} else if (strBet.str() == "Single"){


cPrice1[0] = strtok(szPrice1, "\\");
cPrice1[1] = strtok(NULL, "\\");

fTot = atof(szNum) / atof(cPrice1[1]);

nAdd = atoi(cPrice1[0]) + atoi(cPrice1[1]);

fReturns = fTot * nAdd;

GetWindowText(GetDlgItem(hwnd, IDC_PRICE1), szPrice1, MAX_PATH);
GetWindowText(GetDlgItem(hwnd, IDC_OUTPUT), szOutput, MAX_PATH);

strOutput.str(szOutput);

for (int i = 0; i < strlen(szNum); i++)
{
if (!isdigit(szNum[i])) {
MessageBox(NULL, "Invalid Character, Returns = £0", "Error", MB_OK | MB_ICONWARNING);
fReturns = 0;
SetWindowText(GetDlgItem(hwnd, IDC_STAKE), "Error");
i = strlen(szNum);
}
}

strBet << strOutput.str() << "Single Bet: £" << szNum << " @ " << szPrice1 << " Returns: £" << fReturns << "\r\n";

SetWindowText(GetDlgItem(hwnd, IDC_OUTPUT), strBet.str().c_str());
GetWindowText(GetDlgItem(hwnd, IDC_RETURNS), szReturns, MAX_PATH);

fRet = atof(szReturns) + fReturns;

sprintf(szReturns, "%.2f", fRet);

SetWindowText(GetDlgItem(hwnd, IDC_RETURNS), szReturns);

}


This is the code when the user clicks the 'Calculate Bet' button.

Note: I am learning WinAPI so if there are problems or any better ways of doing things that i have done, please feel free to say.

If i click the button loads of times (for testing) it only allows a certain amount of characters:

http://img444.imageshack.us/img444/8153/problemx.png

You can see that once it gets to a certain line it just adds onto it and i cant go down any further.

Can anyone provide a solution.

Thanks in advance,

RJK

cosmicvoid
May 29th, 2010, 07:19 PM
char *cPrice1[1];
... snip ...
cPrice1[0] = strtok(szPrice1, "\\");
cPrice1[1] = strtok(NULL, "\\");
... snip ...
I haven't analyzed your code logic, but I do see one error:
you declare an array of one element. and then put two entries in it (index overflow).

I'm guessing you meant: char *cPrice1[2];

RJK
May 30th, 2010, 08:27 AM
Hey thanks for the info, i thought that when you declared an array [1] would be [0] & [1].

And if needed here is how i do my Multi Line Edit Box, if this error could be in there:



HWND hTxtOutput = CreateWindow("Edit", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | ES_MULTILINE | ES_AUTOHSCROLL| ES_WANTRETURN | WS_VSCROLL, 10, 10, 400, 300, hwnd, (HMENU) IDC_OUTPUT, NULL, NULL);



Thanks.