CompuServe Thread

#SetFocus in CDialogBar

2 messages in this thread
#30395From: Charles BeaversJul 10, 1994 1:49 AM
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
#30408From: Steve McAdamsJul 10, 1994 8:33 AM
>> 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]