Click here to Skip to main content
15,898,920 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am stuck to compete my project in just reaching a CRecordView derived class which is a child class on the main CFrameWnd class - from a modal CDialog derived class -. The purpose of this is when the user clicks on the OK button from the modal dialog, a public function on that CRecordView derived class should be called.
I tried all possible functions to access that CRecordView derived class, which are:
::AfxGetMainWnd()->GetDescendantWindow(nID);
::FindWindow(LPCTSTR lpClassName, LPCTSTR lpWindowName);
::GetWindow(HWND hWnd, UINT uCmd);


nothing is working :(

Is there any other tricks to do that?

Help me please :((
Posted

The CRecordView window will be a child of its parent frame window. You are most likely getting the parent frame. Once you get that, call GetActiveView and cast the CView* to CRecordView*, and that should do it.
 
Share this answer
 
v2
Comments
Mr. Tomay 9-Feb-11 8:24am    
Nice thinking ;)
Nish Nishant 9-Feb-11 8:56am    
:-)
Mr. Tomay 10-Feb-11 9:30am    
I found a little problem: GetActiveView doesn't always return my CRecordView when no active view is focused
Nish Nishant 10-Feb-11 9:39am    
That indicates some other issue since the frame window should always have one active view?
Mr. Tomay 10-Feb-11 18:04pm    
I have did some changes: I have added a splitter window that contains my CRecordView and another CFormView.
If CRecordView is derived from CWnd (which I'm pretty sure it is), you can pass on the pointer to the modal dialog extending your dialog's constructor as suggested by eugen or by messaging to it (since CDialogs are also CWnd). To message to a CWnd, use its pointer to access PostMessage() or use the extended PostMessage with the hwnd.

See CWnd::PostMessage() for details on how to use it. Remember that anything derived from a base class can be recast as the base class in order to use its methods. For example...

CRecordView *recview;
CWnd *p_cwnd = (CWnd *) recview;

So now you can make calls such as p_cwnd->PostMessage(). Just make sure that you have the appropriate messages defined the CWnd's message map that's supposed to receive them (or CWnd derived class's message map).
 
Share this answer
 
Comments
Albert Holguin 12-Feb-11 13:40pm    
whoever voted this down doesn't understand the MFC framework... just saying :)
Espen Harlinn 17-Mar-11 10:44am    
My 5 - http://msdn.microsoft.com/en-us/library/ws8s10w4(VS.80).aspx
Your could extend the dialog constructor:
class CYourDialog : public CDialog
{
  CRecordView* m_pcView;
..

public:
  CYourDialog(CRecordView* pcView, CWnd* pcParent)
    : CDialog(pcParent, CYourDialog::IDD), m_pcView(pcView) {};

..
  virtual void OnOK()
  {
    if (pcView->GetSafeHwnd()) {
      //..
    }
  }
..
};

..or, as Carlo said, use the OK event at the parent side:
void CMainFrame::OnRecordViewConfig()
{
  CYourDialog cDlg(this);
  if (IDOK == cDlg.DoModal()) {
    if (m_pcRecordView->GetSafeHwnd()) {
      //..
    }
  }
}

:)
 
Share this answer
 
v2
Usually the OK button closes the modal dialog and the parent window can handle such a event.
:)
 
Share this answer
 
Comments
Mr. Tomay 8-Feb-11 5:35am    
that's right. But my CRecordView class was created using an SDI app project & I don't know how to get a pointer to it :(
CPallini 8-Feb-11 6:11am    
The trick is providing access by the class that created it or, alternatively, let the latter know about the 'OK' button event (for instance you may post a message).
Mr. Tomay 8-Feb-11 6:20am    
can you explain how ?
Try AfxGetApp()->m_pMainWnd, casting it as appropriate to your window class.
 
Share this answer
 
Comments
Mr. Tomay 9-Feb-11 8:31am    
AfxGetApp()->m_pMainWnd will return the main frame window not the view one.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900