Microsoft > Forums Home > Visual Studio Extensibility > [C# Add-in] Window2.SetTabPicture throw ArgumentException in VS2008

Answered [C# Add-in] Window2.SetTabPicture throw ArgumentException in VS2008

  • Friday, November 16, 2007 11:53 AM
     
     

     

    Hello,

     

    i hope any body can help me ;-)

     

    i develop a Visual Studio Add-in in C# and i work with Visual Studio 2005 and 2008. In Visua Studio 2005 i hafe createt a custom ToolWindow with the Method Windows2.CreateToolWindow2, After creating the ToolWindow and before i set the ToolWindow to visible = true, i set the tab picture with a 24-bit 16x16 Bitmap. In Visual Studio 2005 it will works fine but in VS20008 the method Window2.SetTabPicture throw a Argument Exception with the message "Value does not fall within the expected range".

     

    I know, the background color for the Bitmap in Visual Studio 2008 to 0,254,0 is different than Visual Studio 2005. But it will not work, in Visual Studio 2008.

     

    is this a bug in Visual Studio 2008 Beta2?

     

    Many thanks for all help!!!

     

    Thomas Mueller (www.tom-mue.de)

Answers

  • Monday, November 19, 2007 10:16 AM
    Moderator
     
     Answered

    For your description I guess that you already read this thread:

     

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1871235&SiteID=1

     

    The strange part is that with VS 2008 Beta2, if you use a 24-bit 16x16 bitmap with RGB=0,254,0 as background, it should work, as it worked in VS.NET 2002/2003, but not in VS 2005, when you have to use RGB=255,0,255 as background color.

     

    My MZ-Tools add-in uses a native resource Dll with 16x16 24-bit bitmaps with RGB=0,254,0 as background and I have notes in the code like this:

     

    iSatelliteDLLHandle = Me.LoadSatelliteDLL()

     

    #If VS_7_0 Or VS_7_1 Then

       objPicture = TransparentPicture.GetTransparentIPictureDispFromDLLResource(iSatelliteDLLHandle, iImageIndex)

       objWindow.SetTabPicture(objPicture)

    #ElseIf VS_8_0 Then

       objBitmap = TransparentPicture.GetTransparentBitmapUsingMagentaFromDLLResource(iSatelliteDLLHandle, iImageIndex)

       objWindow.SetTabPicture(objBitmap.GetHbitmap)

    #Else

    ' Using the technique of VS 2005 causes an exception (argument outside of expected range) so we use the VS.NET 2002/2003 approach again

       objPicture = TransparentPicture.GetTransparentIPictureDispFromDLLResource(iSatelliteDLLHandle, iImageIndex)

       objWindow.SetTabPicture(objPicture)

    #End If

     

    Where the functions for VS2008 are:

     

    Friend Shared Function GetTransparentIPictureDispFromBitmapHandle(ByVal hIntPtr As IntPtr) As stdole.IPictureDisp

     

       Dim objPicture As Object

       Dim objGuid As New Guid("00020400-0000-0000-C000-000000000046")

       Dim iResult As Integer

       Dim tPICTDESC As New PICTDESC(hIntPtr)

     

       iResult = OleCreatePictureIndirect(tPICTDESC, objGuid, 1, objPicture)

       Return CType(objPicture, stdole.IPictureDisp)

     

    End Function

     

    Friend Shared Function GetTransparentIPictureDispFromDLLResource(ByVal iDLLHandle As IntPtr, ByVal iResourceIndex As Integer) As stdole.IPictureDisp

     

       Dim iBitmapHandle As Integer

       Dim objPicture As stdole.IPictureDisp

     

       If Not iDLLHandle.Equals(IntPtr.Zero) Then

         iBitmapHandle = LoadBitmap(iDLLHandle, iResourceIndex)  ' Win32 API Call

         If iBitmapHandle <> 0 Then

            objPicture = GetTransparentIPictureDispFromBitmapHandle(New IntPtr(iBitmapHandle))

         End If

       End If

     

       Return objPicture

     

    End Function

     

    So, I am not sure why is not working in your case...