I've made this program that shows the ACSII value and the character, heres a pic from the DOS version:
http://subsoap.com/ck/getintchar.PNG
NOTE: thats the old version that shows the line feed (10)
I'm learning WinAPI and I want to get this string from a edit box then put the string into a varaible then every char in the string I want to convert to a int, so that when theres a 'c' in the string it has it as '99'.
heres some of the code for it:
Code:
BOOL bSuccess;
int nTimes = GetDlgItemInt(hwnd, IDC_NUMBER, &bSuccess, FALSE);
if(bSuccess)
{
// Then we get the string they entered
// First we need to find out how long it is so that we can
// allocate some memory
int len = GetWindowTextLength(GetDlgItem(hwnd, IDC_TEXT));
if(len > 0)
{
// Now we allocate, and get the string into our buffer
int i,mychr;
str buf;
buf = (str)GlobalAlloc(GPTR, len + 1);
GetDlgItemText(hwnd, IDC_TEXT, buf, len + 1);
// Now we add the string to the list box however many times
// the user asked us to.
for(;*buf;){
int mychr=(int)*buf;
SendDlgItemMessage(hwnd, IDC_LIST, LB_ADDSTRING, 0, (LPARAM)mychr);
//SendDlgItemMessage(hwnd, IDC_LIST, LB_ADDSTRING, 0, (LPARAM)buf);
}
/*for(i = 0;i < nTimes; i++)
{
int index = SendDlgItemMessage(hwnd, IDC_LIST, LB_ADDSTRING, 0, (LPARAM)buf);
// Here we are associating the value nTimes with the item
// just for the heck of it, we'll use it to display later.
// Normally you would put some more useful data here, such
// as a pointer.
SendDlgItemMessage(hwnd, IDC_LIST, LB_SETITEMDATA, (WPARAM)index, (LPARAM)nTimes);
}*/
// Dont' forget to free the memory!
GlobalFree((HANDLE)buf);
}
else
{
MessageBox(hwnd, "You didn't enter anything!", "Warning", MB_OK);
}
//and the rest of the stuff..
}
I also need add a new item into the list that has the int number AND the char it belongs too*, don't know how I'll do this..
*the dos version of showing the int and the char:
Code:
int mychr;
while((mychr = getchar()) != 9) {
if (mychr != 10) printf("\n%i\t%c",mychr,mychr); else nl;
}
I want to see for this WinAPI prog if I can do basicly the same with the list box BUT with the WinAPI version it's a string not a intso I'll need to covert it and show it with the character.
HOPEFULLY this made sence/someone can help me.
I CAN post the other code if needed.
CK4R1 0U7