[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 AMModerator
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 ThenobjBitmap = 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 againobjPicture = TransparentPicture.GetTransparentIPictureDispFromDLLResource(iSatelliteDLLHandle, iImageIndex)
objWindow.SetTabPicture(objPicture)
#
End IfWhere the functions for VS2008 are:
Friend Shared Function GetTransparentIPictureDispFromBitmapHandle(ByVal hIntPtr As IntPtr) As stdole.IPictureDispDim 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.IPictureDispDim iBitmapHandle As Integer
Dim objPicture As stdole.IPictureDispIf Not iDLLHandle.Equals(IntPtr.Zero) Then
iBitmapHandle = LoadBitmap(iDLLHandle, iResourceIndex) ' Win32 API Call
If iBitmapHandle <> 0 ThenobjPicture = GetTransparentIPictureDispFromBitmapHandle(
New IntPtr(iBitmapHandle)) End If End IfReturn objPicture
End Function
So, I am not sure why is not working in your case...