I'd like to set the focus in an edit box in a CDialogBar from my CFormView, but
I can't see how to get a pointer to the main frame from the view so I can call
GetDlgItem() and SetFocus().
Thanks for your help.
Chuck
>> but I can't see how to get a pointer to the main frame from the view <<
The following will, in general, get the main frame for you from anywhere:
CWnd* frame = AfxGetApp()->m_pMainWnd; // all you need in many cases
if (frame != NULL)
{
CWnd* temp = frame->GetParentFrame(); // in case set to view
if (temp != NULL) frame = temp;
}
There is more code that you need to be absolutely bulletproof from anywhere
under any conditions (such as when m_pMainWnd is NULL). If you ensure that
your frame is pointed to by m_pMainWnd (such as by specifically setting
m_pMainWnd in the frame's OnCreate handler) you only need the first line of the
above. -steve [McAdams Research]