This sample provides function to draw an object supporting ISymbol to a Device Context, a Window, an OLE Picture object, or a Bitmap file. Extensive use is made of Windows API calls. An optional gap can be supplied to the functions, using the lGap parameter, to create a blank border around the symbol.
The function DrawToWnd draws a Symbol directly to a window. Call this function by passing in a valid window handle, and an object supporting ISymbol:
If DrawToWnd(picMyPicture.hWnd, pSymbol) Then MsgBox "Success" End If
The function DrawToDC draws a Symbol directly to a device context. Call this function by passing in a valid device context, the required length and height dimensions, and an object supporting ISymbol:
If DrawToDC(picMyPicture.hDC, picMyPicture.ScaleWidth, picMyPicture.ScaleHeight, pSymbol) Then MsgBox "Success" End If
Note that the height and width specified in this function are the dimensions which will be drawn to within the device context, and are defined in pixels - here the ScaleMode of the PictureBox (picMyPicture) is pixels. Also, if drawing to a PictureBox, ensure the AutoRedraw property is False as all drawing goes directly to the window.
The function SaveSymbolToBitmapFile draws a Symbol to a new OLE Picture before saving this to a new bitmap file. Call this function by passing in a valid device context (the new Picture object is created based on this context), the required length and height dimensions, a file path, and an object supporting ISymbol
If SaveSymbolToBitmapFile(picMyPicture.hDC, pSymbol, picMyPicture.ScaleWidth, picMyPicture.ScaleHeight, txtFilePath.Text) Then MsgBox "Success" End If
The file path should be a full path and filename with a bmp extension. If the file already exists it will be overwritten.
The function CreatePictureFromSymbol creates a new OLE Picture object and draws a Symbol to this picture. Call this function by passing in a valid device context (the new Picture object is created based on this context), a variable declared as a Long (hBmpNew), the required length and height dimensions, and an object supporting ISymbol
If CreatePictureFromSymbol(picMyPicture.hDC, hBmpNew, m_pSymbol, picMyPicture.ScaleWidth, picMyPicture.ScaleHeight) Then MsgBox "Success" End If
Note that the CreatePictureFromSymbol function creates a Windows GDI bitmap which cannot be deleted within the scope of the function. The handle to this bitmap is returned by the hBmpNew variable, which is passed by reference. You should always call the WinAPI DeleteObject function (defined in the basWinAPIDec.bas module) passing in the hBmpNew parameter from CreatePictureFromSymbol, after the function has returned.
|basDrawSymbol.bas||Draw Symbol functions.|
|basMakeSymbols.bas||Utility functions used by the test application to create Symbol objects.|
|basWinAPIDec.bas||Windows API declarations used by Draw Symbol functions.|
|frmDrawSymbol.frm||VB form file for test application.|
|vbpDrawSymbol.vbp||VB Project file for test application.|
|DrawSymbol.exe||VB executable of test application.|