Solved

VC++ Events

Posted on 1998-10-01
5
337 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
  • 3
  • 2
5 Comments
 
LVL 8

Accepted Solution

by:
Answers2000 earned 50 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

763 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now