Solved

Make a ActiveX from a CWnd class

Posted on 2003-11-05
13
585 Views
Last Modified: 2013-11-20
I made a CWnd class tha it work in a Custom Control. Now i want to made an ActiveX with that class.

Do I have to rewrite most of the code????

There is a way to create that CWnd class inside the COleControl class and capture all message like OnLButtonDown.

Please do a example.

Thanks.-

PD: Sorry for my english. :)
0
Comment
Question by:DAE
[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
  • 7
  • 6
13 Comments
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9691786
>> Now i want to made an ActiveX with that class
You mean, u already created an ActiveX and want to load thru CWnd?
Rosh :)
0
 

Author Comment

by:DAE
ID: 9691979
No, I not create the activex because I'm looking for an easy way to create that CWnd class in to a activex.

Like subclassing or something like that.

But maybe load thru CWnd it what i want, what is load thru CWnd?

Thanks
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9692132
1). File Menu->New
2). Select MFC ActiveXControl Wizard
3). Select the Path for the Project and Enter a Name
4). Click "OK"
5). Press Next
6). Press Finish

Now you will get a new ActiveX Project, you can place the code that in the CWnd in the main class (a class

with Ctl siffix eg: CYourAxCtl.cpp,CYourAxCtl.h)

Is that what u need?

This link also give some idea about creating an ActiveX
http://www.codeproject.com/buttonctrl/mfc2ocx.asp - Creating an ActiveX button from a MFC owner-draw

button

Try these links also, this will give some ActiveX tutorials
http://www.codeguru.com/activex/activexTutorial.html  by Kapil Chaturvedi.
http://www.codeguru.com/activex/activex_tut.shtml by Navin Kohli.

Good Luck
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:DAE
ID: 9692339
No, is not what i need.

For example. I made a CWnd derived class called DumClass.

Wend i start a new activex proyect, I have to create that class in the constructor like:

DumClass Test = new DumClass();

And then in the OnDraw event put some thing like this:

void CActiveXControlCtrl::OnDraw(CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
       Test->Draw(pdc, rcBounds)
}

But my question is, there is other way to do this more easy. For example put some thing in the event PreCreateWindows?????????????????

Thanks roshmon for you dedication.
0
 
LVL 23

Accepted Solution

by:
Roshan Davis earned 500 total points
ID: 9692376
1). Do *NOTHING* in the function "OnDraw"
2). Comment all  the code that already created by the wizard like pDC->Ellipse() something like that
3). If your class is derived from CWnd, you need to create that window using "Create()" function
eg:
Put that create function code in your ActiveX control's OnCreate something like
make DumClass object as the class member of CUserManagerCtrl
i.e
in "UserManagerCtl.h", declare
DumClass m_oDumClass;

int CActiveXControlCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
      if (COleControl::OnCreate(lpCreateStruct) == -1)
            return -1;

      m_oDumClass.Create(NULL, "", WS_CHILD | WS_VISIBLE, CRect(0, 0, 20, 20), this, 1234);

      return 0;
}

And in your OnSize function (that you have to map WM_SIZE using class wizard(Ctrl+W))

void CActiveXControlCtrl::OnSize(UINT nType, int cx, int cy)
{
      COleControl::OnSize(nType, cx, cy);

      if( ::IsWindow(m_oDumClass.m_hWnd) )
            m_oDumClass.MoveWindow(0, 0, cx, cy);      
}

Good Luck
0
 

Author Comment

by:DAE
ID: 9692598
Yes, thats what i want. But it doesn´t works.

m_oDumClass don't draw, and
if( ::IsWindow(m_oDumClass.m_hWnd)) is FALSE.

In the original proyect than i want to pass to activex. I put a Custom Control in a CDialog, and then put :

void CTestDlg::DoDataExchange(CDataExchange* pDX)
{
      CDialog::DoDataExchange(pDX);
      //{{AFX_DATA_MAP(CTestDlg)
      DDX_Control(pDX, IDC_CUSTOMCONTROL, m_oDumClass);
      //}}AFX_DATA_MAP
}

And it work excellent.

I'm burning my brain here.

roshmon we are in the right path.

Thanks.
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9692611
What that "Create" function returns..?
- m_oDumClass.Create(NULL, "", WS_CHILD | WS_VISIBLE, CRect(0, 0, 20, 20), this, 1234);

Rosh :)


0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9692618
In your class "DumClass", is there any "Create" function ?
If yes, use that function instead of the above
Rosh:)
0
 

Author Comment

by:DAE
ID: 9692646
The function "Create" returns 1.
0
 

Author Comment

by:DAE
ID: 9692655
There is no overload create function in the class.
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9692697
>> m_oDumClass don't draw, and
>> if( ::IsWindow(m_oDumClass.m_hWnd)) is FALSE.

Check the same condition just after the "Create" function

Rosh :)
0
 

Author Comment

by:DAE
ID: 9692723
Thank Rosh. It work excellent.

Stay in touch. My ICQ number is: 40317575
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9692731
Thankx and Good Luck
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ODBC Connection Logging, ADO.NET 6 73
Process filename extension 3 218
format the code in java 6 117
wordappend challenge 8 249
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

751 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