Solved

non-MFC MDI frame & MFC child

Posted on 1998-06-12
4
448 Views
Last Modified: 2013-11-20
I have a non-MFC MDI application where each type of MDI child is in DLL. EXE calls exported DLL function that creates MDI child window with window procedure inside this DLL.
I have been asked to create new MDI child type using MFC. I tried to derive new window from CWnd and with some corrections it seems to work OK. (I have changed CMyWnd::DefWindowProc to call ::DefMDIChildProc)

But if I want to use document/view inside this DLL it needs the MDI child frame window to be derived from CFrameWnd and I am not able to make it working.

Is it possible at all?
0
Comment
Question by:magnezko
  • 2
4 Comments
 
LVL 4

Expert Comment

by:piano_boxer
ID: 1317899
The frame for your views should be derived from CMDIChildWnd.
The main windows (CMainFrame) should be derived from CMDIFrameWnd.

0
 

Author Comment

by:magnezko
ID: 1317900
Main window is written using API without MFC and it is not desirable to make major changes to existing code...

0
 
LVL 2

Accepted Solution

by:
Belgarat earned 100 total points
ID: 1317901
Well... if you're going to continue with MFC-based extensions, maybe you should fool MFC with CFrameWnd instance attached to the main MDI frame window. If you attach (CWnd::Attach) the MFC object to an existing window, MFC will subclass it - as long as you will pass all messages unchanged to the previous window procedure, the application will behave the exactly same way as before.
You can put the pointer to the instance in e.g. some exported variable so the instance can be shared across another (in the future) DLLs - remember, you can Attach only one CWnd-descendant to a particular window.
It should be sufficient to Attach the CFrameWnd instance, but you have to fill CFrameWnd::m_hWndMDIClient member manually - with the handle of the MDI Client window residing in the frame. Then you should be able to create MDI child windows in the standard way.

0
 

Author Comment

by:magnezko
ID: 1317902
Great! It seems to be OK!
I had to force the newly created window to be MDI child, so I had to override PreCreateWindow function of my CFrameWnd derived class to set WS_EX_MDICHILD style and set my hClient handle as
hwndParent. (m_hWndMDIClient can't be used because it is not member of CFrameWnd but CMDIFrameWnd)

Next I overrode DefWindowProc function to call ::DefMDIChildProc.
WS_EX_MDICHILD style leads to a fault in a view creation. Somewhere in MFC code pContext parameter is loosing value of m_pNewViewClass member. So I saved correct value in LoadFramne function and restore it in OnCreate function and view is
created correctly. In addition there are some problems with main frame menu, so I had to manually set m_hMenuDefault to NULL and m_bAutoMenuEnable to FALSE.
Thanks much.

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

766 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question