Reputation: 1210
I've a dialog, CFormView, which holds some buttons and a panel which holds Tabcontrol, radiobuttons, text input fields etc.
So, on my panel, the CWnd, I create my input fields like this:
pEdit = new CEdit();
pEdit->CreateEx(WS_EX_CLIENTEDGE, _T("EDIT"), NULL, WS_CHILD | WS_VISIBLE | WS_TABSTOP | nAttrMultiline | m_clRect, pclPanel, iID)
Where m_clRect is a CRect, pclPanel is my CWnd, and iID is just the controller ID.
I want to fill my CEdit
with text when a button is clicked, but somehow I can't get the controller who has focus.
My first attempt was to call GetFocus()
, cast it into a CEdit
and add the text, but this just changes the text on my button, of course.
Second attempt was to check for WM_SETFOCUS
with ON_WM_SETFOCUS()
and keep the previous wnd and cast it and add text, but that just changes the text on my dialog.
Third attempt was to move this to my CWnd but as far as I can see, WM_SETFOCUS
is never called.
Edit:
Tried ON_WM_ACTIVATE
with ::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
inside my CWnd.
But that's not being called either.
Anybody has an idea what to try next?
Upvotes: 1
Views: 840
Reputation: 4335
You just answered yourself. The correct way to do it is: on the function that handles the
ON_COMMAND(...)
of each button call
pEdit->SetWindowText(_T("text"));.
GetFocus()
is wrong, because it will return the button, as when you clicked it, you just finished to put the focus on it. You can get the edit using
CEdit* pEdit= ( CEdit*) GetDlgItem(ID_OF_EDIT);
where ID_OF_EDIT
is the value you passed to CreateEx
as iId
parameter.
Upvotes: 1