Hi,
I’m making a “map maker” type program and I’m having some trouble getting information from Dialog Box edit controls. I know how to use EM_GETLINE to get text from an edit control (which I previously used to also work with numbers by using an atoi() call and changing the chars in to integers). Unfortunately I ran in to problems when only entering one character in to the edit control but everything worked fine for anything >= 10. I figured I would never have a map as small as 9x9 so it didn’t really matter… unfortunately now I need to be able to enter single digits for a different Dialog Box.
I’ve been searching for an EM_GETLINE type parameter to grab integers to but I’ve had no luck so I turned to where I usually turn when I hit a wall. I hope you guys can help.
Here’s my non-working code right now.
Code:
LRESULT CALLBACK SelectMission(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
int mission = 0;
WORD sizeOfInput;
DisplayInfo* Info = (DisplayInfo*)(DWORD_PTR)GetWindowLongPtr(hDlg, DWLP_USER);
HRESULT hr = -1;
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
SetWindowLongPtr(hDlg, DWLP_USER, static_cast<long>(lParam));
return TRUE;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDCANCEL:
EndDialog(hDlg, LOWORD(wParam));
break;
case IDOK:
sizeOfInput = (WORD) SendDlgItemMessage(hDlg,
IDC_MISSIONNUMBER,
EM_LINELENGTH,
(WPARAM) 0,
(LPARAM) 0);
if (sizeOfInput == 0)
{
MessageBox(hDlg,
"No characters entered for Mission.",
"Error",
MB_OK);
break;
}
//// Put the number of characters into first word of buffer.
//*((LPWORD)mission) = sizeOfInput;
// Get the characters.
SendDlgItemMessage(hDlg,
IDC_MISSIONNUMBER,
EM_GETLINE,
(WPARAM) 0, // line 0
(LPARAM) mission);
//// Null-terminate the string.
//height[sizeOfInput] = 0;
if(SUCCEEDED(hr))
EndDialog(hDlg, LOWORD(wParam));
break;
}
}
return FALSE;
}
There’s some stuff left over from when I was trying to convert character strings to integers and then remembered that it wouldn’t work. Right now this compiles fine but of course it crashes when it reaches the last SendDlgItemMessage() because of my LPARAM being an integer.
I’ve been looking through MSDN for an EM_ something that would help my problem but I haven’t found anything yet. Any help would be greatly appreciated.
Thanks,
-Peter