class SimpleControl {
public:
SimpleControl(HWND hwndParent, int id) : _hWnd(GetDlgItem(hwndParent, id)) {}
void SetFocus() {
::SetFocus (_hwnd);
}
HWND Hwnd() const { return _hWnd; }
protected:
HWND _hWnd;
};
Ниже представлен пример элемента управления редактированием.
class Edit: public SimpleControl {
public:
Edit(HWND hwndParent, int id) : SimpleControl (hwndParent, id) {}
void SetString(char* buf) {
SendMessage(Hwnd(), WM_SETTEXT, 0, (LPARAM)buf);
}
// code is the HIWORD (wParam)
static BOOL IsChanged (int code) {
return code == EN_CHANGE;
}
int GetLen() {
return SendMessage(Hwnd(), WM_GETTEXTLENGTH, 0, 0);
}
void GetString(char* buf, int len) {
SendMessage(Hwnd(), WM_GETTEXT, (WPARAM)len, (LPARAM)buf);
}
void Select() {
SendMessage(Hwnd(), EM_SETSEL, 0, –1);
}