I have three fields in a dialog box, I want them to be combined into one string when I add a string to the list in the middle of the window:
Only the hours field goes into the list.Code:int hourlen = GetWindowTextLength(GetDlgItem(hwnd, IDC_HOURS)); int minutelen = GetWindowTextLength(GetDlgItem(hwnd, IDC_MINUTES)); int secondlen = GetWindowTextLength(GetDlgItem(hwnd, IDC_SECONDS)); if(hourlen > 0 && minutelen > 0 && secondlen > 0) { // Now we allocate, and get the string into our buffer int i; char* hours = ""; char* minutes = ""; char* seconds = ""; hours = (char*)GlobalAlloc(GPTR, hourlen + minutelen + secondlen + 1); GetDlgItemText(hwnd, IDC_HOURS, hours, hourlen + 1); GetDlgItemText(hwnd, IDC_MINUTES, minutes, minutelen + 1); GetDlgItemText(hwnd, IDC_SECONDS, seconds, secondlen + 1); strcat(hours, minutes); strcat(hours, seconds); // Now we add the string to the list box however many times // the user asked us to. //int index = SendDlgItemMessage(hwnd, IDC_LIST, LB_ADDSTRING, 0, (LPARAM)buf); SendDlgItemMessage(hwnd, IDC_LIST, LB_ADDSTRING, 0, (LPARAM)hours); // 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)hours); GlobalFree((HANDLE)minutes); GlobalFree((HANDLE)seconds); } else { MessageBox(hwnd, "You didn't enter enough information!", "Warning", MB_OK); } } else { MessageBox(hwnd, "Couldn't translate that number :(", "Warning", MB_OK); }



LinkBack URL
About LinkBacks


