|
IDL Connectivity Bridges: Using ActiveX Controls in IDL |
|
This example uses an ActiveX control that displays a spreadsheet interface. The control, contained in the file msowc.dll, is installed along with a typical installation of Microsoft Office. If the control is not present on your system (you'll know the control is not present if the example code fails when trying to realize the widget hierarchy), the example will not run.
The spreadsheet control has the program ID:
OWC.Spreadsheet.9
and the class ID:
{0002E510-0000-0000-C000-000000000046}
| Note The spreadsheet control used in this example is included with older versions of Microsoft Office; it is discussed in Microsoft Knowledge Base Article 248822. Newer versions of Microsoft Office may include spreadsheet controls with updated program and class IDs. |
Information about the spreadsheet control's properties and methods was gleaned from Microsoft Excel 97 Visual Basic Step by Step by Reed Jacobson (Microsoft Press, 1997) and by inspection of the control's interface using the OLE/COM Object Viewer application provided by Microsoft. It is beyond the scope of this manual to describe the spreadsheet control's interface in detail.
| Example Code The following section develops an IDL routine called ActiveXExcel that illustrates use of the spreadsheet ActiveX control within an IDL widget hierarchy. The complete .pro file is included in the examples\doc\bridges\COM subdirectory of the IDL distribution as ActiveXExcel.pro. |
FUNCTION excel_getSelection, oExcel, aData
oExcel->GetProperty, SELECTION=oSel
oSel->GetProperty, COUNT=nCells
IF (nCells LT 1) THEN BEGIN OBJ_DESTROY, oSel RETURN, 0 ENDIF
oSel->GetProperty, COLUMNS=oCols, ROWS=oRows
oCols->GetProperty, COUNT=nCols OBJ_DESTROY, oCols oRows->GetProperty, COUNT=nRows OBJ_DESTROY, oRows
aData = FLTARR(nCols, nRows, /NOZERO);
FOR i=1, nCells DO BEGIN oSel->GetProperty, ITEM=oItem, i oItem->GetProperty, VALUE=vValue aData[i-1] = vValue OBJ_DESTROY, oItem ENDFOR
OBJ_DESTROY, oSel
RETURN, 1 END
PRO excel_setData, oExcel
nX = 20
oExcel->GetProperty, ActiveSheet=oSheet
oSheet->GetProperty, CELLS=oCells
im = BESELJ(DIST(nX))
FOR i=0, nX-1 DO BEGIN FOR j=0, nX-1 DO BEGIN oCells->GetProperty, ITEM=oItem, i+1, j+1 oItem->SetProperty, VALUE=im(i,j) OBJ_DESTROY, oItem ENDFOR ENDFOR
OBJ_DESTROY, oSheet OBJ_DESTROY, oCells END
PRO ActiveXExcel_event, ev
WIDGET_CONTROL, ev.TOP, GET_UVALUE=sState, /NO_COPY
IF (ev.DISPID EQ 1513) THEN BEGIN
excel_getSelection function defined above. Check to make sure that the function returns a success value (one) before proceeding.IF (excel_getSelection(sState.oExcel, aData) NE 0) THEN BEGIN
szData = SIZE(aData)
IF (szData[0] GT 1 AND szData[1] GT 1 AND szData[2] GT 1) $ THEN SURFACE, aData $ ELSE $ PLOT, aData ENDIF ENDIF
WIDGET_CONTROL, ev.TOP, SET_UVALUE=sState, /NO_COPY END
PRO ActiveXExcel !EXCEPT=0 ; Ignore floating-point underflow errors.
wBase = WIDGET_BASE(COLUMN=1, $ TITLE="IDL ActiveX Spreadsheet Example")
wAx=WIDGET_ACTIVEX(wBase, $
'{0002E510-0000-0000-C000-000000000046}', $
SCR_XSIZE=600, SCR_YSIZE=400)
WIDGET_CONTROL, wBase, /REALIZE
WIDGET_CONTROL, wAx, GET_VALUE=oExcel
oExcel->SetProperty, DisplayTitleBar=0
excel_setData function defined above.excel_setData, oExcel
WIDGET_CONTROL, wBase, SET_UVALUE={oExcel:oExcel}
XMANAGER,'ActiveXExcel', wBase, /NO_BLOCK END
Running the ActiveXExcel procedure display widgets that look like the following:
![]() |
IDL Online Help (March 06, 2007)