Getting and setting window center and width Example for VB.NET

'LEADDICOM1 is a DICOM Dataset defined outside this method
Private Sub GettingAndSettingWindowCenterAndWidth()
   ' This example will add a new "Window Width" and
   ' "Window Center" to the dataset , or replace ' the existing one(s)

   Dim bAddWindow As Boolean
   Dim WindowAttributes As LTDICLib.LWindowAttributes
   Dim iRet As Short
   Dim lWindowCount As Short
   Dim lWindowIndex As Short
   Dim iBitsStored As Short

   lWindowCount = 0
   lWindowIndex = 0
   bAddWindow = True
   iBitsStored = 12

   lWindowCount = LEADDICOM1.WindowCount
   If (lWindowCount > 0) Then
      iRet = LEADDICOM1.GetWindowAttributes(0, 0)
      If (iRet <> 0) Then
         MessageBox.Show("error")
         Exit Sub
      End If
      WindowAttributes = LEADDICOM1.WindowAttributes

      ' Half the width for the first window
      WindowAttributes.WindowWidth = WindowAttributes.WindowWidth / 2
      WindowAttributes.WindowCenter = WindowAttributes.WindowCenter / 2
   Else
      ' This represents an identity VOI LUT transformation in the case
      ' where no Modality LUT is specified and the stored pixel data are
      ' iBitsStored bit unsigned integers.
      WindowAttributes = LEADDICOM1.WindowAttributes
      WindowAttributes.WindowWidth = 2 ^ iBitsStored
      WindowAttributes.WindowCenter = 2 ^ (iBitsStored - 1)
      WindowAttributes.WindowCWExplaination = ""
   End If
   lWindowIndex = lWindowCount
   If (bAddWindow = False) Then

      ' Delete the existing window(s)
      iRet = LEADDICOM1.DeleteWindow(0)
      If (iRet <> 0) Then
         MessageBox.Show("error")
         Exit Sub
      End If
      lWindowIndex = 0
   End If
   ' Add the new window
   iRet = LEADDICOM1.SetWindowAttributes(lWindowIndex, 0)
   If (iRet <> 0) Then
      MessageBox.Show("error")
      Exit Sub
   End If
End Sub