INTERNAL/REVIEW: Simple Example: How to Embed an ActiveX Control in an IDL Widget Hierarchy
Anonym
[Needs to be reviewed for Compliance and IP issues (i.e. .pro file included)]
The WIDGET_ACTIVEX function is used to embed a COM ActiveX control in an IDL widget hierarchy on Windows.
IDL already has its own slider widget, but for the purposes of this simple example we use a Microsoft slider control to illustrate the concepts of creating ActiveX control objects within IDL, embedding them in an IDL user interface, getting and setting properties and handling events.
The IDL Online Help contains similar examples that show how to embed a Microsoft calendar control and a Microsoft spreadsheet control within an IDL application.
Discussion
COM (Component Object Model) is a specification on the Windows platform for building software components that may be used to build programs or to add functionality to existing programs, regardless of the development language used. COM objects are able to be utilized in a program at run time without having to recompile the program.
ActiveX controls are COM objects that include a graphical-user interface. These can be purchased and added to a Windows application. There are a number of Microsoft controls that are included with the Windows operating system.
To take advantage of an ActiveX control in an IDL application, it is necessary to know certain information about the control. This information can be found using the Microsoft "OLE/COM Object Viewer," which is included with Visual Studio or can be downloaded at http://www.microsoft.com/com.
In this example, a Microsoft slider control will be added to an IDL widget. The first thing needed to accomplish this is the class ID of the COM object. This can be found by navigating to "Object Classes -> All Objects -> Microsoft Forms 2.0 ScrollBar" in the OLE viewer. The object can be added to a base widget (named tlb) as follows:
ax_slider = widget_activex (tlb, event_pro = 'onsliderchange', '{dfd181e0-5e2f-11ce-a449-00aa004a803d}',$
scr_xsize = 400, scr_ysize = 15, /sensitive)
Note that this object contains several interfaces. The IScrollbar interface will contain the methods that can be used to modify the scrollbar. Double click on "IScrollbar" to open the "Default Interface Viewer" which will open the "ITypeInfo Viewer". All of the methods for the scrollbar object can be found here. Information about a specific method can be obtained by clicking on that method in the list. Notice that in some cases the methods are doubled (Min, Max, Smallchange,...). In this case one is a SETPROPERTY method and the other a GETPROPERTY method (propget and propput respectively).
Examine the code below to see how, once the object is created, you can use the control's methods to get and set its properties within your IDL code. To test the example, compile the code in IDL and run the "test_widget_activex_slider" procedure.
Download 'test_widget_activex_slider.pro'
Example:
pro test_widget_activex_slider_event, event
widget_control, event.top, get_uvalue = state, /no_copy
; Get the slider object reference.
widget_control, event.id, get_value = oax_slider
; Get the current value of the slider.
oax_slider -> getproperty, value = temp
; Change the label widget to reflect the new slider value.
widget_control, state.label, set_value = strcompress(temp)
widget_control, event.top, set_uvalue = state, /no_copy
end
pro test_widget_activex_slider
tlb = widget_base(column = 1, title = "WIDGET_ACTIVEX Example")
label = widget_label(tlb, /dynamic_resize, value = '')
; Microsoft Forms 2.0 ScrollBar
ax_slider = widget_activex (tlb, $
'{dfd181e0-5e2f-11ce-a449-00aa004a803d}',$
scr_xsize = 400, scr_ysize = 15, /sensitive)
widget_control, tlb, /realize
; Getting the slider obeject reference
widget_control, ax_slider, get_value = oax_slider
; setting the MIN, MAX and VALUE prpoerties of the slider.
oax_slider -> setproperty, min = 90, max = 100, value = 95
widget_control, tlb, set_uvalue = {label:label}, /no_copy
xmanager, 'test_widget_activex_slider', tlb
end