Cancel
Showing results for 
Search instead for 
Did you mean: 

Re: RE: Change Part or Assembly background color

Solution Partner Pioneer Solution Partner Pioneer
Solution Partner Pioneer

I think i have found a solution.

The internal view need to be repainted.

 

            Dim oWin As SolidEdgeFramework.Window
            oWin = doc.Windows(0)

            Dim oVStyle As SolidEdgeFramework.ViewStyle
            oVStyle = oWin.View.ViewStyle
            Const White = &HFFFFFFFF

            _SEApp.ScreenUpdating = False

            oVStyle.BackgroundType = SolidEdge.Framework.Interop.SeBackgroundType.seBackgroundTypeSolid
            oVStyle.SetGradientColor(1, White)
            oVStyle.SetGradientColor(2, White)
            oVStyle.BackgroundType = SolidEdge.Framework.Interop.SeBackgroundType.seBackgroundTypeGradient

            System.Threading.Thread.Sleep(50)
            RefreshWindow(oWin.hWnd) ''<---REPAINT THE INTERNAL WINDOW
            _SEApp.ScreenUpdating = True

 The RefreshWindow() itselt take care of the job invalidating the graphical region and forcing windows to perform a nice full repaint. Sorry for the p/invoke bloatware, the api is very simple indeed, just the RECT structure has been extended but i had no time to clean it up.

 

Module VbUtil

    <DllImport("user32.dll", CharSet:=CharSet.Auto)> _
    Private Function GetClientRect(ByVal hWnd As System.IntPtr, ByRef lpRECT As RECT) As Integer
        ' Leave function empty     
    End Function

    <DllImport("user32.dll")> _
    Private Function RedrawWindow(hWnd As IntPtr, <[In]()> ByRef lprcUpdate As RECT, hrgnUpdate As IntPtr, flags As RedrawWindowFlags) As Boolean
        ' Leave function empty     
    End Function

    <DllImport("user32.dll")> _
    Private Function RedrawWindow(hWnd As IntPtr, lprcUpdate As IntPtr, hrgnUpdate As IntPtr, flags As RedrawWindowFlags) As Boolean
        ' Leave function empty     
    End Function

    <StructLayout(LayoutKind.Sequential)> _
    Public Structure RECT
        Private _Left As Integer, _Top As Integer, _Right As Integer, _Bottom As Integer

        Public Sub New(ByVal Rectangle As Rectangle)
            Me.New(Rectangle.Left, Rectangle.Top, Rectangle.Right, Rectangle.Bottom)
        End Sub
        Public Sub New(ByVal Left As Integer, ByVal Top As Integer, ByVal Right As Integer, ByVal Bottom As Integer)
            _Left = Left
            _Top = Top
            _Right = Right
            _Bottom = Bottom
        End Sub

        Public Property X As Integer
            Get
                Return _Left
            End Get
            Set(ByVal value As Integer)
                _Right = _Right - _Left + value
                _Left = value
            End Set
        End Property
        Public Property Y As Integer
            Get
                Return _Top
            End Get
            Set(ByVal value As Integer)
                _Bottom = _Bottom - _Top + value
                _Top = value
            End Set
        End Property
        Public Property Left As Integer
            Get
                Return _Left
            End Get
            Set(ByVal value As Integer)
                _Left = value
            End Set
        End Property
        Public Property Top As Integer
            Get
                Return _Top
            End Get
            Set(ByVal value As Integer)
                _Top = value
            End Set
        End Property
        Public Property Right As Integer
            Get
                Return _Right
            End Get
            Set(ByVal value As Integer)
                _Right = value
            End Set
        End Property
        Public Property Bottom As Integer
            Get
                Return _Bottom
            End Get
            Set(ByVal value As Integer)
                _Bottom = value
            End Set
        End Property
        Public Property Height() As Integer
            Get
                Return _Bottom - _Top
            End Get
            Set(ByVal value As Integer)
                _Bottom = value + _Top
            End Set
        End Property
        Public Property Width() As Integer
            Get
                Return _Right - _Left
            End Get
            Set(ByVal value As Integer)
                _Right = value + _Left
            End Set
        End Property
        Public Property Location() As Point
            Get
                Return New Point(Left, Top)
            End Get
            Set(ByVal value As Point)
                _Right = _Right - _Left + value.X
                _Bottom = _Bottom - _Top + value.Y
                _Left = value.X
                _Top = value.Y
            End Set
        End Property
        Public Property Size() As Size
            Get
                Return New Size(Width, Height)
            End Get
            Set(ByVal value As Size)
                _Right = value.Width + _Left
                _Bottom = value.Height + _Top
            End Set
        End Property

        Public Shared Widening Operator CType(ByVal Rectangle As RECT) As Rectangle
            Return New Rectangle(Rectangle.Left, Rectangle.Top, Rectangle.Width, Rectangle.Height)
        End Operator
        Public Shared Widening Operator CType(ByVal Rectangle As Rectangle) As RECT
            Return New RECT(Rectangle.Left, Rectangle.Top, Rectangle.Right, Rectangle.Bottom)
        End Operator
        Public Shared Operator =(ByVal Rectangle1 As RECT, ByVal Rectangle2 As RECT) As Boolean
            Return Rectangle1.Equals(Rectangle2)
        End Operator
        Public Shared Operator <>(ByVal Rectangle1 As RECT, ByVal Rectangle2 As RECT) As Boolean
            Return Not Rectangle1.Equals(Rectangle2)
        End Operator

        Public Overrides Function ToString() As String
            Return "{Left: " & _Left & "; " & "Top: " & _Top & "; Right: " & _Right & "; Bottom: " & _Bottom & "}"
        End Function

        Public Overloads Function Equals(ByVal Rectangle As RECT) As Boolean
            Return Rectangle.Left = _Left AndAlso Rectangle.Top = _Top AndAlso Rectangle.Right = _Right AndAlso Rectangle.Bottom = _Bottom
        End Function
        Public Overloads Overrides Function Equals(ByVal [Object] As Object) As Boolean
            If TypeOf [Object] Is RECT Then
                Return Equals(DirectCast([Object], RECT))
            ElseIf TypeOf [Object] Is Rectangle Then
                Return Equals(New RECT(DirectCast([Object], Rectangle)))
            End If

            Return False
        End Function
    End Structure

    <Flags()> _
    Private Enum RedrawWindowFlags As UInteger
        ''' <summary>
        ''' Invalidates the rectangle or region that you specify in lprcUpdate or hrgnUpdate.
        ''' You can set only one of these parameters to a non-NULL value. If both are NULL, RDW_INVALIDATE invalidates the entire window.
        ''' </summary>
        Invalidate = &H1

        ''' <summary>Causes the OS to post a WM_PAINT message to the window regardless of whether a portion of the window is invalid.</summary>
        InternalPaint = &H2

        ''' <summary>
        ''' Causes the window to receive a WM_ERASEBKGND message when the window is repainted.
        ''' Specify this value in combination with the RDW_INVALIDATE value; otherwise, RDW_ERASE has no effect.
        ''' </summary>
        [Erase] = &H4

        ''' <summary>
        ''' Validates the rectangle or region that you specify in lprcUpdate or hrgnUpdate.
        ''' You can set only one of these parameters to a non-NULL value. If both are NULL, RDW_VALIDATE validates the entire window.
        ''' This value does not affect internal WM_PAINT messages.
        ''' </summary>
        Validate = &H8

        NoInternalPaint = &H10

        ''' <summary>Suppresses any pending WM_ERASEBKGND messages.</summary>
        NoErase = &H20

        ''' <summary>Excludes child windows, if any, from the repainting operation.</summary>
        NoChildren = &H40

        ''' <summary>Includes child windows, if any, in the repainting operation.</summary>
        AllChildren = &H80

        ''' <summary>Causes the affected windows, which you specify by setting the RDW_ALLCHILDREN and RDW_NOCHILDREN values, to receive WM_ERASEBKGND and WM_PAINT messages before the RedrawWindow returns, if necessary.</summary>
        UpdateNow = &H100

        ''' <summary>
        ''' Causes the affected windows, which you specify by setting the RDW_ALLCHILDREN and RDW_NOCHILDREN values, to receive WM_ERASEBKGND messages before RedrawWindow returns, if necessary.
        ''' The affected windows receive WM_PAINT messages at the ordinary time.
        ''' </summary>
        EraseNow = &H200

        Frame = &H400

        NoFrame = &H800
    End Enum

    Public Sub RefreshWindow(ByVal hWnd As System.IntPtr)
        Dim R As RECT

        GetClientRect(hWnd, R)
        RedrawWindow(hWnd, R, 0&, _
            RedrawWindowFlags.Erase Or RedrawWindowFlags.AllChildren Or _
            RedrawWindowFlags.UpdateNow Or RedrawWindowFlags.Invalidate Or _
            RedrawWindowFlags.Frame Or RedrawWindowFlags.EraseNow)
    End Sub

End Module

 

RedrawWindow can be reused to force a full repaint of any window giving it's hwnd handle.

 

Hope this helps,

 

Paolo Marani

Engineering PLM Solutions, Italy

 

Re: Change Part or Assembly background color

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

I know I am late on this post, but I gave once a solution to your problem on BBS Solid Edge Programming Forum. Here is the code again:

'----------------------------------------------------------------------
' PAR/ASM: Set the view background to either gradient or solid style
'----------------------------------------------------------------------
Const TopColor As Int32 = &H3F3F3F ' DarkGray (RGB)
Const BottomColor As Int32 = &HFFFFFF ' White (RGB)
'Const SolidColor As Int32 = &H99DDFF ' SkyBlue (RGB)
Const SolidColor As Int32 = &HFFFFFF ' White (RGB)

Dim bGradient As Boolean = False
Dim objDoc As SolidEdgeDocument = objApp.ActiveDocument
If objDoc.Type = DocumentTypeConstants.igDraftDocument Then Exit Sub
Dim objWin As Window = objDoc.Windows.Item(1)
Dim objStyle As ViewStyle = objWin.View.ViewStyle
If bGradient Then
  ' Change to GRADIENT background
  objStyle.BackgroundType = SeBackgroundType.seBackgroundTypeGradient
  objStyle.BackgroundImageFile = String.Format("$$grad_s_{0:x6}_{1:x6}$$", TopColor, BottomColor)
Else
  ' Change to SOLID background (simulate it using gradient with same top & bottom color)
  objStyle.BackgroundType = SeBackgroundType.seBackgroundTypeGradient
  objStyle.BackgroundImageFile = String.Format("$$grad_s_{0:x6}_{1:x6}$$", SolidColor, SolidColor)
End If
objWin.View.Update()