none
What is the name of the GraphicsWindow when writing an extension? RRS feed

  • Question

  • Here is my code:

    /// <summary>

    /// Provides methods for using Windows Aero APIs

    /// </summary> [SmallBasicType] public static class PlusPlusAero { public static void SetTaskbarProgressState(Primitive state) {             if (state == "None")             {                 //here I want to set the taskbar progress but it requires a Microsoft.Windows.Window window to set the progress for             }       } }

    I would like to add this function to my extension. Does anyone have any suggestions?      


    Monday, April 2, 2012 1:47 AM
    Answerer

Answers

  • Yes, just as it is in the LitDev source, put this code inside a public static function inside a public static class with [SmallBasicType] attribute, then add the XML for intellisense, the /// bits.  Or just copy all of the code from LDUtilities and delete all but one function and rename LDUtilities and the namespace (LitDev) to something you are using.  The key is get something going, then modify it.
    Tuesday, April 3, 2012 7:52 AM
    Moderator

All replies

  • You need to write and invoke a callback delegate to SmallBasicLibary.dll to access _window (a member of GraphicsWindow).  If this sounds like IT babble it is.  Check out the code for LDUtilities.Icon for example or do a search for _window in the LitDev source.

    Note you need at least (and possibly others)

    using System;
    using System.Windows;
    using System.Reflection;
    using Microsoft.SmallBasic.Library;
    using Microsoft.SmallBasic.Library.Internal;

    Monday, April 2, 2012 5:25 PM
    Moderator
  • I am still a little confused. I was studying your GW state class but I am a little confused about the delegate part in relation to SB. Could you please tell me what to do once I get here?

    [SmallBasicType]
    	public static class PlusPlusGraphicsWindow
        {
           public static void SetProgressState(Primitive state)
           {
               Type GraphicsWindowType = typeof(GraphicsWindow);
               Window _window = (Window)GraphicsWindowType.GetField("_window"BindingFlags.IgnoreCase | BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);
               InvokeHelper invokeHelper = delegate
               {
                   
               };
           }
        }

    Thanks!

    Monday, April 2, 2012 10:49 PM
    Answerer
  • You need all of it including the MethodInfo and Involke bits that get the delegate by reflection, eg:

    First try my code exactly, then modify when it works for the icon.

                    Type GraphicsWindowType = typeof(GraphicsWindow);
                    try
                    {
                        Window _window = (Window)GraphicsWindowType.GetField("_window", BindingFlags.IgnoreCase | BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);
                        InvokeHelper invokeHelper = delegate
                        {
                            try
                            {
                                _window.Icon = BitmapFrame.Create(new Uri(value), BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);
                            }
                            catch
                            {
                            }
                        };
                        MethodInfo method = GraphicsWindowType.GetMethod("Invoke", BindingFlags.IgnoreCase | BindingFlags.Static | BindingFlags.NonPublic);
                        method.Invoke(null, new object[] { invokeHelper });
                    }
                    catch
                    {
                    }
    

    Monday, April 2, 2012 11:14 PM
    Moderator
  • Sorry, but where do i put that code? Inside the function?
    Monday, April 2, 2012 11:53 PM
    Answerer
  • Yes, just as it is in the LitDev source, put this code inside a public static function inside a public static class with [SmallBasicType] attribute, then add the XML for intellisense, the /// bits.  Or just copy all of the code from LDUtilities and delete all but one function and rename LDUtilities and the namespace (LitDev) to something you are using.  The key is get something going, then modify it.
    Tuesday, April 3, 2012 7:52 AM
    Moderator
  • Thanks so much for the help! LitDev saves the day again =)
    Tuesday, April 3, 2012 11:05 PM
    Answerer