Previous Obsolete IDL Features: The IDLDrawWidget ActiveX Control Next


This functionality is obsolete. It should not be used in new IDL code.

Copying and Printing IDL Graphics

The VBCopyPrint example demonstrates how to use either the Windows clipboard or object graphics to print the contents of an IDLDrawWidget window.

This example illustrates the following concepts:

Opening the VBCopyPrint project

Select "Existing" from the Visual Basic New Project dialog. In the IDL distribution, change to the examples\docs\ActiveX\VBCopyPrint directory, and open the project VBCopyPrint.vbp, as shown in the following figure.

Figure 7-5: Opening the VBCopyPrint project

Figure 7-5: Opening the VBCopyPrint project

Running the VBCopyPrint Example

Select "Start" from the Run menu to run the example. You should see the graphic shown in the following figure.

Figure 7-6: VBCopyPrint example

Figure 7-6: VBCopyPrint example

Copying IDL Graphic to the Clipboard

To copy the graphic, click on "Copy". The code for "Copy" uses the CopyWindow method to copy the contents of the graphic to the Windows clipboard as shown in line 6 of the following table.

Table 7-4: Copy button Source Code

Table 7-4: Copy button Source Code
Visual Basic
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
Private Sub cmdCopy_Click()  
  'Copy the direct graphics window to the clipboard  
  Screen.MousePointer = vbHourglass  
  'Erase anything currently on the clipboard  
  Clipboard.Clear  
  'Copy the draw widget to the clipboard  
  IDLDrawWidget1.CopyWindow   
  Screen.MousePointer = vbDefault  
  MsgBox "Window copied to clipboard."  
End Sub  

Printing the IDL Graphic Using IDL Object Graphics

To print the graphic using IDL, click on "IDL Print". The "IDL Print" button uses IDL's object graphics to print the contents of the window by creating an image object and sending the image to a printer object through a user routine VBPrintWindow.

Table 7-5: IDL VBPrintWindow Code

Table 7-5: IDL VBPrintWindow Code
IDL
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
PRO VBPrintWindow, DrawId  
                  .  
                  .  
                  .  
  ;Get the window index of the drawable to be printed  
  WIDGET_CONTROL, DrawId, Get_Value=Index  
                  .  
                  .  
                  .  
  ;Create a Printer object and draw the graphic to it  
  oPrinter = OBJ_NEW ('IDLgrPrinter')  
   
  ;Display a print dialog box  
  Result = DIALOG_PRINTERSETUP(oPrinter)  
                  .  
                  .  
                  .  
  oPrinter->Draw, oView  
                  .  
                  .  
                  .  
END ;VBPrintWindow  

Executing IDL User Routines with Visual Basic

The VBCopyPrint example executes a user routine, written in IDL, to support the printing of the IDLDrawWidget window. This is done with the ExecuteStr method, as shown in line 4 below, by passing a string of the routine name along with the ID of the IDLDrawWidget.

Table 7-6: Print Button Source Code

Table 7-6: Print Button Source Code
Visual
 Basic
1  
2  
3  
4  
5  
6  
7  
8  
9  
Private Sub cmdPrintIDL_Click()  
  'Print the current drawable widget's window contents  
  'using IDL object graphics  
  Screen.MousePointer = vbHourglass  
  IDLDrawWidget1.ExecuteStr "VBPrintWindow," &  
    Str$(IDLDrawWidget1.DrawId)  
  Screen.MousePointer = vbDefault  
  MsgBox "Window sent to printer."  
End Sub  

Printing the IDL Graphic Using Visual Basic

The VBPrint command uses the Windows clipboard and Visual Basic printer support to print the IDL Graphic, as shown in the following table.

Table 7-7: VBPrint Command

Table 7-7: VBPrint Command
Visual Basic
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
Private Sub cmdPrintVB_Click()  
  CommonDialog1.CancelError = True  
    On Error GoTo ErrHandler  
    CommonDialog1.ShowPrinter  
'-- Copy the window's contents to the clipboard  
    'Erase anything currently on the clipboard  
    Clipboard.Clear  
    IDLDrawWidget1.CopyWindow   
  '-- Send the picture located on the clipboard,   
  'to the printer  
    Printer.PaintPicture Clipboard.GetData, 0, 0  
    Printer.EndDoc  'Send it to the printer  
Exit Sub  
ErrHandler:  
   
    Exit Sub  
End Sub  

  IDL Online Help (March 06, 2007)