1.获得编辑框中的文本信息
TCHAR tem[128]; HWND hEdit = ::GetDlgItem(m_hWnd, IDC_EDIT1); ::SendMessage(hEdit, WM_GETTEXT, 128, (LPARAM)&tem);
例:
struct Student { TCHAR id[10]; TCHAR name[10]; TCHAR sex[2]; TCHAR age[4]; TCHAR tel[20]; }; BOOL MyDialog::OnIDOK() { Student stu; ::SendMessage(::GetDlgItem(m_hWnd, IDC_EDIT1), WM_GETTEXT, 10, (LPARAM)stu.id); ::SendMessage(::GetDlgItem(m_hWnd, IDC_EDIT2), WM_GETTEXT, 10, (LPARAM)stu.name); ::SendMessage(::GetDlgItem(m_hWnd, IDC_COMBO1), WM_GETTEXT, 2, (LPARAM)stu.sex); ::SendMessage(::GetDlgItem(m_hWnd, IDC_EDIT3), WM_GETTEXT, 4, (LPARAM)stu.age); ::SendMessage(::GetDlgItem(m_hWnd, IDC_EDIT4), WM_GETTEXT, 20, (LPARAM)stu.tel); return 0; }
看红框内是不是读取数据成功了,
2.设置编辑框中的文本信息
TCHAR tem[] = L"你好编辑框!"; HWND hEdit = ::GetDlgItem(m_hWnd, IDC_EDIT1); ::SendMessage(hEdit, WM_SETTEXT, 0, (LPARAM)&tem);
例:
::SendMessage(::GetDlgItem(m_hWnd, IDC_EDIT1), WM_SETTEXT,0, (LPARAM)L"001"); ::SendMessage(::GetDlgItem(m_hWnd, IDC_EDIT2), WM_SETTEXT, 0, (LPARAM)L"李尖尖"); ::SendMessage(::GetDlgItem(m_hWnd, IDC_COMBO1), WM_SETTEXT, 0, (LPARAM)L"女"); ::SendMessage(::GetDlgItem(m_hWnd, IDC_EDIT3), WM_SETTEXT, 0, (LPARAM)L"23"); ::SendMessage(::GetDlgItem(m_hWnd, IDC_EDIT4), WM_SETTEXT, 0, (LPARAM)L"13200132");