Howto close a MDI CView from CMainFrame - mfc

How do I close (using code) the last created CView in my MDI app. from the CMainFrame class ?

Call OnCloseDocument on the associated CDocument (which you can get by calling GetDocument on the CView instance).

Related

MFC modeless dialog with style child

I have SDI structure program and I want to create CDialog with child style and use CFormView as its parent. Because I want to use CFormView as a "containter".
Now I encounter two problems.
I can not set setmunu to CDialog (because of the dialog style is child)
The dialog behave unnormal (the dialog has CEdit, but it can not input ...)
How can I resolve the problem?
I create dialog with style popup , after creation,repoint its parent to cformview and solve the above problems.
void CFuturePCMSView::DialogCreate()
{
m_pDlgUser = new CDlgUser(this);
m_pDlgUser->SetParent(this);
m_pDlgUser->ShowWindow(SW_SHOW);
}

Adding CDialog inside CDockablePane and application becomes unresponsive

I want to add a CDialog control inside CDockablePane. When I use CDialog.DoModal() to display the dialog window, it makes the MFC application unresponsive and waiting for the CDialog result.
How can I make the application display the dialog and continue running without waiting for the CDialog result?
You cannot use DoModal to display the dialog. That displays a modal dialog, which prevents interaction with any other windows in your application until the dialog has been dismissed. Just like a message box does.
To display a non-modal dialog, you call the Create member function. Use the instance of your CDockablePane as the dialog's parent. You will also need to ensure that the dialog itself is a child window, without a border.
It might be easier to use a class derived from CFormView or CPaneDialog.

Making a propertysheet as MDI child

I have a class derived from CPropertySheet in my MDI application. It is a model-less property sheet shown when a button is pressed in one of the views of application. I need to make the sheet as a child view of the application
How to do it?
You just need to change the parent of property sheet using SetParent, or when you instantiate the CPropertySheet-derived class object, you can pass the parent CWnd* reference to constructor of CPropertySheet.
Is this not working?

Adding event handler to user defined window classes

I am using MFC MDI. I create a window the main document window. I create another window(lets call it second window) as child of MDI Window View, then I create child window(third window) of second window. Again I need to create another window, child window of third window. I have a button on the ribbon and I want to call message handler in the third window to handle this command. I have added message map and all required stuff but it is not calling the message handler. If I define the message handler in MDI window view, it catches the event. If I dont delare the message handler in my main CWinApp class or MDI window View class the button appears disabled.
All my child view classes are inherited from CWnd and main MDI window is derived from CView. Please let me know what I am missing here.
Saba
I am at the loss here. You are using MFC; why using events? use command messages and command message handlers instead events.
Use MFC implemented and well working command routing.
MFC doesnt route messages generated by clicking Ribbon buttons to child windows. If we want to send messages to child windows of MDI windows we need to do it ourselves. Ribbon button's messages are either passed to active MDI window or CWinApp class.

Custom MFC control prevents dialog creation

I have a custom MFC control, subclassing CWnd. Other than providing OnPaint and PreSubclassWindow implementations, it overrides no default functionality and does nothing weird in construction except registering a window class in the constructor.
The control is added to the dialog using the dialog editor to add a custom control.
The dialog worked when it was a simple modal dialog deriving from CDialog, but we have code which calls CWnd::CreateDlgIndirect to instance dialogs and this fails with the custom control... but works if the custom control is removed from the resource template.
Found it!
I had the custom control register its window class in its own constructor. I had member in the dialog of this custom control type, so the ctor was being called when the dialog was created, as intended.
But, it turns out the base class I changed the dialog to derive from, instead of CDialog, was calling CreateDlgIndirect in its own ctor, before my new class' own initialisation was reached - so it was trying to create custom control before the window class was registered.
My (slightly messy solution) is to ensure the window class registration happens at application startup in the InitInstance method, before any dialog stuff happens.