How to read event definitions behind ActiveX controls with VBA code?

Thomko

Registered User.
Local time
Today, 07:25
Joined
Jul 15, 2008
Messages
50
Here the scenario:

I want to analyze forms via VBA code and see which controls have events behind them and of what type they are (Event Procedure, Macro or Expression).

Now the problem:

I have code for the standard controls like Text Boxes, Option Buttons etc. that works fine.

Code:
EventDefinition = Control.Properties("<Name of Event>")
or a bit more real life:
Code:
sEventDefinition = MyForm!txtTextBox.Properties("OnDblClick")
This throws (a catchable) run time error if the event does not exist for the control in question. If it exists, sEventDefinition will contain an empty string, the Expression, the Macro name or the term "[Event Procedure]". This way I can find out in VBA code if a theoretically possible event is in use for that control and what it does.

The approach above does only partially work for ActiveX controls like Tree Views. Some Events (like OnClick, OnKeyPress etc.) cannot be read that way. They are also not detectable by enumerating the control properties (only five events commmon to all ActiveX controls are listed, but not all).

So I am looking for VBA code that can read ALL event definitions of ActiveX controls.

Anyone, any thoughts?
Thomas
 
Hello Tony,

thank you for your reply. As you point out in your video, there are five events easily accessible that are common to all ActiveX components (OnEnter, OnExit, OnGotFocus, OnLostFocus, OnUpdated) but the others are not. I tried all variations of your tip (class wrapper) I could think of but to no avail. Googling up and down the Internet brought also no solutions :-(( .
Do you remember where you saw it? A forum, a news group, a book? Can you recommend google terms that might bring up the source that you have in mind (maybe after some digging)?

I start considering ugly workarounds, but there MUST be a solution. The IDE also knows, what events are available and in use ...
 
I'm searching....

from Access Help.... (Copied here cause I'll never find it again)

Access Developer Reference
The ActiveX Control's Custom Properties Dialog Box
Show All
Hide All

Some of the content in this topic may not be applicable to some languages.

When setting the properties of an ActiveX control (ActiveX control: A control, such as a check box or button that offers options to users or runs macros or scripts that automate a task. You can write macros for the control in Microsoft Visual Basic for Applications or scripts in Microsoft Script Editor.), you may need or prefer to use the control's custom properties dialog box (custom properties dialog box: A custom property sheet that allows users to set properties for an ActiveX control.). This custom properties dialog box provides an alternative to the list of properties in the Microsoft Access property sheet (property sheet: A window that is used to view or modify the properties of various objects such as tables, queries, fields, forms, reports, data access pages, and controls.) for setting ActiveX control properties in Design view (Design view: A window that shows the design of these database objects: tables, queries, forms, reports, macros, and data access pages. In Design view, you can create new database objects and modify the design of existing ones.).

Note
This information only applies to ActiveX controls in a Microsoft Access database (database: A collection of data related to a particular subject or purpose. Within a database, information about a particular entity, such as an employee or order, is categorized into tables, records, and fields.) environment.

Two Ways to Set Properties
The reason for the custom properties dialog box is that not all applications that use ActiveX controls provide a property sheet like the one in Microsoft Access. The custom properties dialog box provides an interface for setting key control properties regardless of the interface supplied by the hosting application.

For some ActiveX control properties, you can choose either of these two locations to set the property:

The Microsoft Access property sheet.
The ActiveX control's custom properties dialog box.
In some cases, the custom properties dialog box is the only way to set a property in Design view. This is usually the situation when the interface needed to set a property doesn't work inside the Microsoft Access property sheet. For example, the GridFont property for the Calendar control has a number of arguments; you can't set more than one argument per property in the Microsoft Access property sheet.

Finding the Custom Properties Dialog Box
Not all ActiveX controls provide a custom properties dialog box. To see whether a control provides this custom properties dialog box, look for the Custom property in the Microsoft Access property sheet for this control. If the list of properties contains the name Custom, then the control provides the custom properties dialog box.

Using the Custom Properties Dialog Box
After you click the Custom property box in the Microsoft Access property sheet, click the Build button to the right of the property box to display the control's custom properties dialog box, often presented as a tabbed dialog box. Choose the tab that contains the interface for setting the properties that you want to set.

After you make changes on one tab, you can often apply those changes immediately by clicking the Apply button (if provided). You can click other tabs to set other properties as needed. To approve all changes made in the custom properties dialog box, click the OK button. To return to the Microsoft Access property sheet without changing any property settings, click the Cancel button.

You can also view the custom properties dialog box by clicking the Properties subcommand of the ActiveX control Object command (for example, Calendar Control Object) on the Edit menu, or by clicking this same subcommand on the shortcut menu (shortcut menu: A menu that shows a list of commands relevant to a particular item. To display a shortcut menu, right-click an item or press SHIFT+F10.) for the ActiveX control. In addition, some properties in the Microsoft Access property sheet for the ActiveX control, like the GridFontColor property of the Calendar control, have a Build button to the right of the property box. When you click the Build button, the custom properties dialog box is displayed, with the appropriate tab selected (for example, Colors).
 
>>> So I am looking for VBA code that can read ALL event definitions of ActiveX controls <<<

Would you be happy with just the events that were being used?
 
Visual C++® 6 Unleashed
by Mickey Williams; David Bennett
http://www.informit.com/library/library.aspx?b=Visual_C_PlusPlus
Publisher: Sams
Pub Date: July 24, 2000
Print ISBN-10: 0-672-31241-7
Print ISBN-13: 978-0-672-31241-0
Pages: 1000

From this Chapter: Chapter 28. ActiveX Controls

Extract:
ActiveX Controls > ActiveX Control Architecture
ActiveX Control Architecture

The beauty of ActiveX controls is that they are programmable and reusable. They expose themselves to the outside world and can be used in a variety of environments. ActiveX controls are similar to embedded object servers, in that they are embedded in a container and are responsible for providing a user interface. ActiveX controls also are expected to expose functionality through interfaces, which often are derived from IDispatch to take advantage of automation. ActiveX controls take advantage of the capability to send events to their container; this capability to send events separates ActiveX controls from other in-process OLE servers.

ActiveX controls communicate with the outside world in three ways:

Properties

Methods

Events

Properties
Properties are named attributes or characteristics of an ActiveX control. Properties may be marked as read-only, but typically these properties can be set or queried. Some examples of properties are color, font, and number.

Usually, ActiveX controls provide access to their properties through property sheets. Property sheets are exposed via automation. Property sheets are not limited to design/compile time but can be displayed at runtime to allow the user to manipulate the control's properties, events, or methods. Property sheets are user-interface components that basically are tabbed dialog boxes. Automation provides the mechanism by which ActiveX controls communicate with their property sheets.

ActiveX controls have access to what are called stock properties. These are properties common to all ActiveX controls. MFC enables you to take advantage of these stock properties because they already are built in. Table 28.1 lists all the stock properties supported by MFC.

Table 28.1. Stock Properties for ActiveX Controls Supported by MFC
Stock Property Get/Set Stock Method Enables You To…
Appearance void SetAppearance (short sAppear) short GetAppearance( ) Set the appearance of an ActiveX control to flat or 3D.
BackColor OLE_COLOR GetBackColor ( ) void SetBackColor (OLE_COLOR dwBkColor) Set the background colors of the control.
Border Style short GetBorderStyle ( ) void SetBorderStyle(short sBorderStyle) Set the border style of the control to normal or none.
Caption BSTR GetText( ) void SetText(LPCTSTR pszText) Set the caption of the ActiveX control.
Enabled BOOL GetEnabled( ) void SetEnabled(BOOL bEnabled) Enable or disable the control.
Font LPFONTDISP GetFont( ) void SetFont(LPFONTDISP pFontDisp) Set the font properties used by the control.
Fore Color OLE_COLOR GetForeColor( ) void SetForeColor(OLE_COLOR dwForeColor) Set the forecolors of the control.
hWnd OLE_HANDLE GetHwnd( ) Hold the control's window handle.
Ready State long GetReadyState( ) Get or set the ready state of the control with the following values: READYSTATE_UNINITIALIZED READYSTATE_LOADING READYSTATE_LOADED READYSTATE_INTERACTIVE READYSTATE_COMPLETE
Text const CString& InternalGetText( ) Get and set the control's text. This property is the same as Caption.

You can include the stock properties in your ActiveX controls by using the ClassWizard. Choose View, ClassWizard or press Ctrl+W. After the ClassWizard appears, select the Automation tab (see Figure 28.1).

Figure 28.1. Using the ClassWizard to access stock properties.



Click the Add Property button to invoke the Add Property dialog box. If you use the External Name combo box, you can select which stock properties you want your control to have (see Figure 28.2).

Figure 28.2. You can select stock properties to support by using the External Name combo box.



MFC and Visual C++ 6.0 also provide stock property sheets to add to our user interface so that users can set stock properties. These are General (see Figure 28.3), Fonts (see Figure 28.4), Colors (see Figure 28.5), and Pictures properties.

Figure 28.3. The default General Properties page.



Figure 28.4. The stock Fonts Properties page.



Figure 28.5. The stock Colors Properties page.



Note
Although the General property page is added to your control by default, it doesn't contain any controls. You must add the controls for this page yourself.

I also found the following about half way down this page:::

Visual Basic Private Interfaces
These component categories are for components that specifically support the Visual Basic environment. Controls or containers that use these categories can support alternative methods. This capability is useful if a container encounters a control—or a control encounters a container—that does not support the Visual Basic private interface categories. The GUID for this component category is
 
Hello Tony,

thank you very much for the info. I now have another idea or two how it may work. I will need to study more (and learn more about the inside of activex controls). Your links will be a great help. E.g this snippet from one of the pages sounds promising:

IProvideClassInfo2 Provides quick access to an object's Interface ID (IID) for its event set. An extension to IProvideClassInfo.

Seems that some low-level programming is required. Yeah, looks like fun :-)

I will let you know if I finally find a way. If you stumble over some related material in the near future please do not hesitate to post also that in this thread. This is nagging me for months and I would be surprised if I find a quick solution.

Bye for now
Thomas
 
Hi Thomas,

A couple of months ago I took Safari Books Online free trial offer. I was so impressed that I signed up for full access, I think it costs about $40.00 a month, say he £30.00 a month.

You have access to around 9000 books, I believe about 800 of those are in video format. There is a range of subjects, mostly programming, business-related, and the like.

I wasn't 100% sure I’d done the right thing, but searching for information to help you with your question, I realize it was the “searching” that is one of the best features of the Safari site, you search instantly through all the 9000 odd titles.

I’ve got two stacks of computer related books in my office, both stacks getting on for 2 feet high. I seldom read them, and I’ve only read a handful from cover to cover. Thinking about the cost of these books I think it would be fair to say that I spend about £30.00 a month on average, on books I hardly ever reader except for one or two interesting chapters.

If I want to find anything out, I usually resort to the Internet, you can find out most things; however it takes quite a bit of time weeding out the trash to find the good stuff.

That’s the beauty of Safari Online Books, there’s no trash! I can access the books on any computer with Internet access, and I can also access them through my mobile phone. It’s an excellent service, and I recommend it to anyone. As I’m self employed, I’m sure that I can get the cost attributed to my business, I’m going to talk about it to my accountant when I’ve got the time.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom