I am trying to change the focus of a CDialog controls from a CFormView by using PostMessage:
[CHelpView is inherited from CFormView. And m_wndDlg is a CSampleDlg(inherited from CDialog) object]
void CHelpView::OnEnterbutton()
{
pSplitterFrame->m_dlgPane->m_wndDlg->PostMessage(WM_KEYDOWN, 'r', 2);
}
BOOL CSampleDlg::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message >= WM_KEYFIRST && // for performance
pMsg->message <= WM_KEYLAST)
{
if (pMsg->wParam=='r' && pMsg->lParam==2){
NextDlgCtrl();
return TRUE;
}
}
}
The dialog receives the message but the NextDlgCtrl method doesn't change the focus. I realized that if I change the PreTranslateMessage method so that if the Return key is pressed, within the dialog, this NextDlgCtrl method properly changes the focus each time the user hit the return key(from the dialog). Yet this I couldn't achieve through another dialog.
Does anyone possibly know the reason behind it or any hints or workaround ?
Thanks.
EDIT:
Here's (part of)the log file for the dialog from SPY++.
<01128> 0016013E R WM_GETDLGCODE fuDlgCode:0000
<01129> 0016013E P WM_KEYDOWN nVirtKey:00726574 cRepeat:2 ScanCode:00 fExtended:0 fAltDown:0 fRepeat:0 fUp:0
<01130> 0016013E S WM_NEXTDLGCTL wCtlFocus:(null) (next control receives focus) fHandle:False
<01131> 0016013E R WM_NEXTDLGCTL
<01132> 0016013E S WM_GETDLGCODE
PostMessage
line? Put a breakpoint on it and tell us if the execution stops there. – sergiol