Hide Table of Contents
DrawToolbarButton Method (IEdmAddInDrawButton5)

Dynamically draws an add-in toolbar button.


Visual Basic (Declaration) 
Sub DrawToolbarButton( _
   ByVal lCmdID As System.Integer, _
   ByVal hDC As System.Integer, _
   ByRef poDestRect As EdmRect, _
   ByVal eState As EdmButtonState, _
   ByRef plRetBackgroundColor As System.Integer _
void DrawToolbarButton( 
   System.int lCmdID,
   System.int hDC,
   ref EdmRect poDestRect,
   EdmButtonState eState,
   out System.int plRetBackgroundColor
void DrawToolbarButton( 
&   System.int lCmdID,
&   System.int hDC,
&   EdmRect% poDestRect,
&   EdmButtonState eState,
&   [Out] System.int plRetBackgroundColor


Command ID passed to IEdmCmdMgr5::AddCmd during add-in registration
Handle of the device context to draw on
EdmRect structure; rectangle within which to draw
State of the button image to draw as defined in EdmButtonState
RGB-value of a transparent color; default background color is 192:192:192


Visual Basic sample code showing how to dynamically draw a toolbar button

  1. Add the toolbar button command in the IEdmAddIn5::GetAddInInfo implementation:

poCmdMgr.AddCmd 1000, "First command", EdmMenu_HasToolbarButton Or EdmMenu_OwnerDrawToolbarButton, "This is the first command", "First command", -1, -1

  1. At the top of your class implementation, add declarations of the Win32 GDI functions that you want to use (read more about this in the Visual Basic online help):

Private Declare Sub LineTo Lib "Gdi32" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long)

Private Declare Sub MoveToEx Lib "Gdi32" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long, ByVal OldPnt As Long)

Private Declare Sub Arc Lib "Gdi32" (ByVal hDC As Long, _
                                     ByVal x1 As Long, ByVal y1 As Long, _
                                     ByVal x2 As Long, ByVal y2 As Long, _
                                     ByVal xstart As Long, ByVal ystart As Long, _
                                     ByVal xend As Long, ByVal yend As Long)

  1. Implement IEdmAddInDrawButton5::DrawToolbarButton (called by SOLIDWORKS Enterprise PDM):

Private Sub IEdmAddInDrawButton5_DrawToolbarButton(ByVal lCmdID As Long, ByVal hDC As Long, poDestRect As EdmLib.EdmRect, ByVal eState As EdmLib.EdmButtonState, plRetBackgroundColor As Long)
On Error GoTo ErrHand

If eState = BState_Cold Then
  'Draw a cross using the default pen
  MoveToEx hDC, poDestRect.mlLeft, poDestRect.mlTop, 0
  LineTo hDC, poDestRect.mlRight, poDestRect.mlBottom
  MoveToEx hDC, poDestRect.mlLeft, poDestRect.mlBottom, 0
  LineTo hDC, poDestRect.mlRight, poDestRect.mlTop
  'Draw a circle using the default pen
  Arc hDC, poDestRect.mlLeft, poDestRect.mlTop, poDestRect.mlRight, poDestRect.mlBottom, _
  poDestRect.mlLeft + (poDestRect.mlRight - poDestRect.mlLeft) / 2, poDestRect.mlTop, _
  poDestRect.mlLeft + (poDestRect.mlRight - poDestRect.mlLeft) / 2, poDestRect.mlTop
End If

Exit Sub
Dim errnum As String
errnum = Err.Number
MsgBox "Error drawing toolbar button!" + vbLf + Err.Description + vbLf + errnum
End Sub


See the IEdmAddInDrawButton5 topic for more information.

Return codes:

  • S_OK: The method successfully executed.
  • S_FALSE: One of the arguments is invalid.

See Also


Version 5.2 of SOLIDWORKS Enterprise PDM

Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

Subject:   Feedback on Help Topics
Page:   DrawToolbarButton Method (IEdmAddInDrawButton5)
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:


We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again

Web Help Content Version: API Help (English only) 2015 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.