1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
// Message handler for the control dialog
INT_PTR CALLBACK ControlDlg(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
return (INT_PTR)TRUE;
case WM_COMMAND:
{
int dlgId = LOWORD(wParam);
switch (dlgId)
{
case IDOK:
{
int length = GetWindowTextLength(GetDlgItem(hDlg, IDC_EDIT));
if (length > 0)
{
HGLOBAL hDlgBuf = GlobalAlloc(GHND, length + 1);
LPWSTR buffer = (LPWSTR) hDlgBuf;
GetDlgItemText(hDlg, IDC_EDIT, buffer, length + 1);
SendDlgItemMessage(hDlg, IDC_LIST, LB_ADDSTRING, 0, (LPARAM)buffer);
GlobalFree(hDlgBuf); // This is where it errors
return (INT_PTR)TRUE;
}
else
{
MessageBox(hDlg, L"You didnt enter anything!", L"", MB_ICONINFORMATION | MB_OK);
return (INT_PTR)TRUE;
}
}
break; // case IDOK
case IDC_CLEAR:
SendDlgItemMessage(hDlg, IDC_LIST, LB_RESETCONTENT, 0, 0);
return (INT_PTR)TRUE;
break;
case IDCANCEL:
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
break;
}
}
break;
}
return (INT_PTR)FALSE;
}
|