Solved

VC++ Events

Posted on 1998-10-01
5
340 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

920 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

14 Experts available now in Live!

Get 1:1 Help Now