Solved

VC++ Events

Posted on 1998-10-01
5
355 Views
Last Modified: 2008-02-01
How do I use events created using MFC ActiveX Control Wizard in applications?. I would like to user DoClick and FireMouseDown in my application. How do I use the Compile OCX file to call these events?.
Thanks
0
Comment
Question by:Venkata100198
[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
  • 3
  • 2
5 Comments
 
LVL 8

Accepted Solution

by:
Answers2000 earned 50 total points
ID: 1174225
You are creating an OCX which is suppoosed to fire these events right ?

1. Press Ctrl-W to bring up the class wizard
2. Switch to ActiveX events tab
3. Use Add Event function to indicate which events you want to fire.  These creates functions you can call to fire off events.  Some names are reserved (both those you list) for stock events (events used by most ActiveX controls)
4. In your code call these functions.  For example you will get a WM_LBUTTONDOWN message when the mouse is pressed over your control, and if you use the class wiz you can add a a handler for this message and in the handler call FireMouseDown.
5. For clicking, it's normally defined as mouse down and up inside the control (that's how windows push buttons work, therefore the sequence would be

i. Add a boolean flag to your control class, initially set to flash
ii. In WM_LBUTTONDOWN, (a) set the flag when you get this message, (b) SetCapture when you get this message
iii. In WM_LBUTTONUP, (a) If flag is set and up message is within the bounds of the control, ReleaseCapture, clear flag and FireDoClick, or (b) If flag is not set, then do nothing

0
 

Author Comment

by:Venkata100198
ID: 1174226
Yes, I am creating OCX file to fire events. When I switch to Active X Tab in ClassWizard, The Add Event is grayed out.

Are there any additional steps before I use Add events?.

Thanks
0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1174227
Class name field must have a class name selected which implements the ActiveX control.

This class is the one that derives from COleControl

If you use the App Wiz to generate the skeleton project, you will automatically get one class which is off this type.

If you are doing it manually one of your classes must derive of COleControl.

You can't add these events to a class that doesn't derive off COleControl.  If you need to fire these events from another class keep a pointer in that class which points to the COleControl object.  A good way to do this is to include the 2nd class a member of the main COleControl class and initialize it with a pointer back to the COleControl

In the control .h

class CSomeControl : public COleControl
{
 //etc
public:
   CSomeOtherClass * m_pOtherClass
 //etc

} ;

In the control's .cpp

// constructor
CSomeControl::CSomeControl()
{
 m_pOtherClass = new CSomeOtherClass(this) ;
}

// destructor
CSomeControl::~CSomeControl()
{
 delete m_pOtherClass ;
}

in the .h for the other class store a pointer back to the COleControl derived object :
CSomeOtherClass
{
//etc
public:
    CSomeControl * m_pControl ;

    CSomeOtherClass( COleControl * pControl )
//etc
}

In other class's .cpp

CSomeOtherClass::CSomeOtherClass( COleControl * pControl )
{
   m_pControl = pControl ;
}


Members of the 2nd class can then call the control object's members using

m_pControl->FireWhatever() ;


0
 

Author Comment

by:Venkata100198
ID: 1174228
I can create OCX file using MFC App ControlWizard. What is the procedure to use these in an application?.
0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1174229
To use in C++ create the EXE using AppWiz.  Make sure "ActiveX" (or "OCX") control container support is enabled.  You can then simply place the controls on your form (FormView or Dialogs)

In VB.  Right click on tools, make sure your controls description is checked.  The OCX/ActiveX then appears on the control palette.  Add it to your form.
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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

623 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