Click here to Skip to main content
11,719,753 members (87,056 online)
Click here to Skip to main content

Add a WTL MDI window into an ATL Control

, 11 Sep 2003 54.6K 1.4K 20
Rate this:
Please Sign up or sign in to vote.
This article will show you how to make MDI window of WTL into ATL control by using a real world example.
<!-- Article image -->

Sample Image - MdiControl.jpg

<!-- Add the rest of your HTML here -->

Introduction

The acticle will tell you how to easily add a WTL MDI window into an ATL Control.

Background

I found that there are no articles about MDI in ActiveX using ATL/WTL. In VS.NET , I also could not find a Wizard for it, so I decided to share my idea about MDI in ActiveX  with you.

How to Do it

Step 1

Create ATL Control Project - MdiControl  and Create MdiEx Control

Step 2

Create WTL MDI Application - MdiControlMdiWnd

Step 3

Copy MdiControlMdiWnd res folder and the files what you want to  MdiControl folder


Step 4

Add MdiControlMdiWnd.rc and Resource.h of MdiControlMdiWnd into  the MdiControl folder

Step 5

Copy my classes Yf_Control.h, YF_Module.cpp and YF_Module.h into  MdiControl folder

Step 6

Open MdiControl project and add all of files that you copied into MdiControl folder

Step 7

Open stdafx.h and modify based on the following.

//#define _ATL_NO_AUTOMATIC_NAMESPACE
...
#include "resource.h"
#include <atlbase.h>
//...
// if you use VC7
//-------------------------------------
#include "YF_Module.h"

//-------------------------------------
//....

#include <atlcom.h>
#include <atlhost.h>
#include <atlwin.h>
#include <atlctl.h>
#include <atlapp.h>
#include <atlframe.h>
#include <atlctrls.h>
#include <atlctrlw.h>
#include <mshtml.h>
#include <exdisp.h>
#include <shlguid.h>
...

Step 8

Open MdiControl.cpp and modify based on the following.

...
/*
class CMdiControlModule : public CAtlDllModuleT< CMdiControlModule >
{
public :
 DECLARE_LIBID(LIBID_MdiControlLib)
 DECLARE_REGISTRY_APPID_RESOURCEID(IDR_MDICONTROL, 
    "{DA155D37-087A-4865-BD60-A88A95F21C4B}")
};
CMdiControlModule _AtlModule;
*/

YF_DECLARE_LIBID(LIBID_MdiControlLib)
YF_DECLARE_REGISTRY_APPID_RESOURCEID(IDR_MDICONTROL, 
    "{DA155D37-087A-4865-BD60-A88A95F21C4B}")

#define _AtlModule _Module
...

Step 9

Open MdiEx.h and modify based on the following.

...
#include "YF_Control.h"
...
class ATL_NO_VTABLE CMdiEx : 
...
 public IOleObjectImpl_YF<CMdiEx>,
...
 public CComControl_YF<CMdiEx>,
...
...
 CMdiEx()
 {
  m_bWindowOnly = TRUE;
 }
...
BEGIN_MSG_MAP(CMdiEx)
...
 CHAIN_MSG_MAP(CComControl_YF<CMdiEx>)
...
END_MSG_MAP()

.....

 STDMETHOD(TranslateAccelerator)(LPMSG pMsg)
 {
  CComControl_YF<CMdiEx>::PreTranslateMessage(pMsg);

  return S_OK;
 }
...

Step 10

Create MdiEx Event Interface

[id(1), helpstring("method OnClose")] HRESULT OnClose(void);

Step 11

Open MainFrm.h and modify based on the following in OnCreate Method.

.....
 // register object for message filtering and idle updates
 //CMessageLoop* pLoop = _Module.GetMessageLoop();
 //ATLASSERT(pLoop != NULL);
 //pLoop->AddMessageFilter(this);
 //pLoop->AddIdleHandler(this);
....

Done! You had an ActiveX with MDI, that can be shown in IE.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Zhang YanFeng
Web Developer
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

 
Questionwhen i run demo by IE it show only ATL 3.0 : MdiEx. Why? Pin
safety_ruk6-Sep-06 19:03
membersafety_ruk6-Sep-06 19:03 
QuestionHow to use the MESSAGE_HANDLER on this project? Pin
Ted Lin28-Mar-05 22:03
memberTed Lin28-Mar-05 22:03 
GeneralIt doesn't work in a MFC application based on dialog Pin
MasterFan31-May-04 21:50
memberMasterFan31-May-04 21:50 
Generalbugs! Pin
penghong18-May-04 22:10
memberpenghong18-May-04 22:10 
GeneralAdding Support for Browser Controls Pin
davem110-Jan-04 6:41
memberdavem110-Jan-04 6:41 
QuestionIn FormView How to host ActiveX? Pin
nextmu1-Nov-03 21:26
membernextmu1-Nov-03 21:26 
QuestionHow can I remake it by VC6? Pin
lsk735118-Sep-03 19:58
memberlsk735118-Sep-03 19:58 
AnswerRe: How can I remake it by VC6? Pin
Zhang YanFeng19-Sep-03 23:45
sussZhang YanFeng19-Sep-03 23:45 
if you use VC6, you also can do it base on my steps, but, you don't need to modify your CComModule. please ignore step8 and only add the following in setp7.

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
...


AnswerRe: How can I remake it by VC6? Pin
Aneeshsm13-Oct-03 2:53
memberAneeshsm13-Oct-03 2:53 
GeneralIt's wired, but it's great Pin
tong_du12-Sep-03 3:32
membertong_du12-Sep-03 3:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150901.1 | Last Updated 12 Sep 2003
Article Copyright 2003 by Zhang YanFeng
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid