Hide Table of Contents
DrawToolbarButton Method (IEdmAddInDrawButton5)

Dynamically draws an add-in toolbar button.

Syntax

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 _
) 
C# 
void DrawToolbarButton( 
   System.int lCmdID,
   System.int hDC,
   ref EdmRect poDestRect,
   EdmButtonState eState,
   out System.int plRetBackgroundColor
)
C++/CLI 
void DrawToolbarButton( 
&   System.int lCmdID,
&   System.int hDC,
&   EdmRect% poDestRect,
&   EdmButtonState eState,
&   [Out] System.int plRetBackgroundColor
) 

Parameters

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

Example

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 PDM Professional):

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
Else
  '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
ErrHand:
Dim errnum As String
errnum = Err.Number
MsgBox "Error drawing toolbar button!" + vbLf + Err.Description + vbLf + errnum
End Sub

Remarks

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

Availability

Version 5.2 of SOLIDWORKS PDM Professional


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

 
*Email:  
Subject:   Feedback on Help Topics
Page:   DrawToolbarButton Method (IEdmAddInDrawButton5)
*Comment:  
*   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:



x

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
x

Web Help Content Version: API Help (English only) 2018 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.