none
How to show my icon in Exp Visutal Stufo StatusBar(SvsStatusbar) RRS feed

  • Question

  • I want to show in Exp VisualStudio StatusBar my custom bitmap.

    This Sample i found at MSDN:
     IVsStatusbar statusBar = (IVsStatusbar)GetService(typeof(SVsStatusbar));
              
               object icon =(short)Microsoft.VisualStudio.Shell.Interop.Constants.SBAI_General;

                // Display the animated Visual Studio icon in the Animation region.

               statusBar.Animation(1, ref icon);

                System.Windows.Forms.MessageBox.Show(
                    "Click OK to end status bar animation.");

                statusBar.Animation(0, ref icon);
    //-----------------------------------------
    But what about my custom Picture,
    I tried following
    1. object icon=Resource.Image - nothing ;
    2. object icon=new Bitmap("c:\\mybitmap.bmp") - nothing ;

    I suppose that have to be solution for this issue , if somebody knows Resharper they put in right corner alert icon.

    Thanks.
    Wednesday, August 26, 2009 9:53 PM

Answers

  • Hi,

    You have two options about the second parameter. Please pay special attention to the "If the VARIANT is a VT_I2, it refers to the SBAI_Index of predefined animated icons. If this parameter is a VT_I4, it refers to an HBITMAP containing the filmstrip image for animation, whose width should be a multiple of its height." setence in the MSDN. You parameter can't satisfy of neither the options, so you can't success in this problem.

    We have to choose the second type of parameter, this parameter requres the handle of your HBITMAP. So you must use the umanaged code to finish the task, I have written some sample code for you, it shows below
    IVsStatusbar statusBar = (IVsStatusbar)GetService(typeof(SVsStatusbar));
    
                Bitmap b = new Bitmap(@"Resources\MyMap.bmp");
                IntPtr hdc = IntPtr.Zero;
                hdc = b.GetHbitmap(b);
    
                statusBar.Animation(1, ref hdc);
                statusBar.Animation(0, ref hdc);
                DeleteObject(hdc);
    And you finish your task remember to delete the space it mallocs.
     [System.Runtime.InteropServices.DllImport("gdi32.dll")]
            public static extern bool DeleteObject(IntPtr hObject);
    If you have something unclear, Please let me know.
    • Marked as answer by Dima.Zev Friday, August 28, 2009 8:56 AM
    Thursday, August 27, 2009 7:52 AM
  • Thanks a lot.
    Only one fix i had to do, Animation method required assignable veriable so the finall code looks :

                Bitmap b = new Bitmap(@"c:\test.bmp");
                IntPtr hdc = IntPtr.Zero;
                hdc = b.GetHbitmap();
              
                object hdcObject=(object)hdc;

                statusBar.Animation(1, ref hdcObject);

                System.Windows.Forms.MessageBox.Show(
                   "Click OK to end status bar animation.");

                statusBar.Animation(0, ref hdcObject);
                DeleteObject(hdc);
    • Marked as answer by Dima.Zev Friday, August 28, 2009 8:56 AM
    Friday, August 28, 2009 8:56 AM

All replies

  • Hi,

    You have two options about the second parameter. Please pay special attention to the "If the VARIANT is a VT_I2, it refers to the SBAI_Index of predefined animated icons. If this parameter is a VT_I4, it refers to an HBITMAP containing the filmstrip image for animation, whose width should be a multiple of its height." setence in the MSDN. You parameter can't satisfy of neither the options, so you can't success in this problem.

    We have to choose the second type of parameter, this parameter requres the handle of your HBITMAP. So you must use the umanaged code to finish the task, I have written some sample code for you, it shows below
    IVsStatusbar statusBar = (IVsStatusbar)GetService(typeof(SVsStatusbar));
    
                Bitmap b = new Bitmap(@"Resources\MyMap.bmp");
                IntPtr hdc = IntPtr.Zero;
                hdc = b.GetHbitmap(b);
    
                statusBar.Animation(1, ref hdc);
                statusBar.Animation(0, ref hdc);
                DeleteObject(hdc);
    And you finish your task remember to delete the space it mallocs.
     [System.Runtime.InteropServices.DllImport("gdi32.dll")]
            public static extern bool DeleteObject(IntPtr hObject);
    If you have something unclear, Please let me know.
    • Marked as answer by Dima.Zev Friday, August 28, 2009 8:56 AM
    Thursday, August 27, 2009 7:52 AM
  • Thanks a lot.
    Only one fix i had to do, Animation method required assignable veriable so the finall code looks :

                Bitmap b = new Bitmap(@"c:\test.bmp");
                IntPtr hdc = IntPtr.Zero;
                hdc = b.GetHbitmap();
              
                object hdcObject=(object)hdc;

                statusBar.Animation(1, ref hdcObject);

                System.Windows.Forms.MessageBox.Show(
                   "Click OK to end status bar animation.");

                statusBar.Animation(0, ref hdcObject);
                DeleteObject(hdc);
    • Marked as answer by Dima.Zev Friday, August 28, 2009 8:56 AM
    Friday, August 28, 2009 8:56 AM