?
Solved

CWnd derived class in ATL object

Posted on 2001-08-17
8
Medium Priority
?
618 Views
Last Modified: 2013-11-25
I have a control that I've written with MFC, and I would like to make it accessible to VB (and anything else) as an ActiveX control.  I knocked out a demo ATL object (never used it before now), but I can't work out how to host my CWnd derived control within the ActiveX control.

Could I have some advice about a strategy to do this - I don't really want detailed example code (although a few pointers would be nice).  
0
Comment
Question by:IainHere
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 4

Author Comment

by:IainHere
ID: 6396563
BTW:  I don't want to use the MFC ActiveX control wizard - I want to write this control using ATL (as a learning exercise), but I need to learn how to do it.  For instance, should I derive my control from CWindow instead of CWnd, and how would this help me house it.  What problems am I likely to encounter?

Thanks.
0
 
LVL 9

Accepted Solution

by:
ShaunWilde earned 400 total points
ID: 6396895
CWindow is the ATL eqivalent of MFCs CWnd so yes use CWindow if you want to go ATL only - however ATL dlls can also use MFC in them quite easily (use the wizard options)

then create an ATL object - I generally use Full Control - and base the control on CEdit (this member object is normally replaced by my custom window) the generated code will then provide you with mosty of the hooks to get going eg you create you window in the OnCreate method
0
 
LVL 4

Author Comment

by:IainHere
ID: 6405568
OK.  Using the CEdit method, I want to replace the member control that is the edit with my own control:

     CContainedWindow m_ctlEdit;
     

     CMyControl() :    
          m_ctlEdit(_T("Edit"), this, 1)
     {
          m_bWindowOnly = TRUE;
     }

I guess I replace this code with:

     CContainedWindow m_ctlMine;   etc...
     
But how do I get the "LPTSTR lpszClassName" for the CContainedWindow constructor?  How do I find out what that is - do I have to register the class with something?

Thanks.
0
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 
LVL 9

Expert Comment

by:ShaunWilde
ID: 6405996
I'd try just replacing it completely ? eg use CMyWindow rather than CContaindWindow
0
 
LVL 4

Author Comment

by:IainHere
ID: 6407049
OK, that sounds good, but I need to pass a CWnd* to the Create() function in my control (which is of course passed on to the CWnd::Create() function).

Do you know how I would get that from the control I've made in the way you describe above?

>(this member object is normally replaced by my custom window)

I guess you have this problem too, or do you do something else?
0
 
LVL 9

Expert Comment

by:ShaunWilde
ID: 6407190
CWindow or CWnd ?? use the HWND and pass that around -

what does your control look like? - just .h file will suffice - it might speed thingsup :)
0
 
LVL 4

Author Comment

by:IainHere
ID: 6410290
Thanks for the help Shaun.  To be honest, after having spent a bit longer looking at these things, I've decided to write it as an MFC ActiveX control for now.

Perhaps I'll have time to do the ATL thing another day :-)
0
 
LVL 9

Expert Comment

by:ShaunWilde
ID: 6411310
:)
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

719 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