Exemplo n.º 1
0
 public void CreateMenu()
 {
     using (MenuHandle menu = ResourceMethods.CreateMenu())
     {
         menu.IsInvalid.Should().BeFalse();
     }
 }
Exemplo n.º 2
0
 public void AppendMenu()
 {
     using (MenuHandle menu = ResourceMethods.CreateMenu())
     {
         menu.IsInvalid.Should().BeFalse();
         ResourceMethods.AppendMenu(menu, "&File", 1000);
     }
 }
Exemplo n.º 3
0
 public void LoadString()
 {
     using (var handle = ModuleMethods.LoadLibrary(GetNativeTestLibraryLocation(),
                                                   LoadLibraryFlags.LOAD_LIBRARY_AS_IMAGE_RESOURCE | LoadLibraryFlags.LOAD_LIBRARY_AS_DATAFILE))
     {
         string resource = ResourceMethods.LoadString(handle, 101);
         resource.Should().Be("Test");
     }
 }
        /// <summary>
        ///     Get the string from resource.
        /// </summary>
        /// <param name="resourceId">String resource ID.</param>
        /// <returns>String.</returns>
        /// <exception cref="Win32Exception">Could not load resource DLL.</exception>
        public string LoadString(int resourceId)
        {
            Contract.Ensures(Contract.Result <string>() != null);

            var hInstance = GetInstanceHandle();

            var result = new StringBuilder(255);

            ResourceMethods.LoadString(hInstance, resourceId, result, result.Capacity);

            return(result.ToString());
        }
 /// <summary>
 ///     Get the handle of resource DLL.
 /// </summary>
 /// <returns>Instance handle for the resource DLL.</returns>
 /// <exception cref="Win32Exception">Could not load resource DLL.</exception>
 private IntPtr GetInstanceHandle()
 {
     if (this.instanceHandle == IntPtr.Zero)
     {
         this.instanceHandle = ResourceMethods.LoadLibraryEx(this.LibraryPath, ResourceMethods.LOAD_LIBRARY_AS_DATAFILE);
         if (this.instanceHandle == IntPtr.Zero)
         {
             throw new Win32Exception();
         }
     }
     return(this.instanceHandle);
 }
        /// <summary>
        ///     Get the icon from resource.
        /// </summary>
        /// <param name="resourceId">Icon resource ID.</param>
        /// <param name="size">Icon size.</param>
        /// <returns>Icon.</returns>
        /// <exception cref="Win32Exception">
        ///     <para>Could not load resource DLL.</para>
        ///     or
        ///     <para>Could not acquire the icon of the specified resource ID.</para>
        /// </exception>
        public ShellIcon LoadIcon(int resourceId, int size = 0)
        {
            Contract.Ensures(Contract.Result <ShellIcon>() != null);

            var hInstance = GetInstanceHandle();

            var resourceName = $"#{resourceId}";
            var hicon        = ResourceMethods.LoadIconImage(hInstance, resourceName, size, size, ResourceMethods.LR_DEFAULTCOLOR);

            if (hicon == IntPtr.Zero)
            {
                throw new Win32Exception();
            }
            return(new ShellIcon(hicon));
        }
Exemplo n.º 7
0
        public void LoadStringFromLongPath()
        {
            using (var cleaner = new TestFileCleaner())
            {
                string longPath = @"\\?\" + PathGenerator.CreatePathOfLength(cleaner.TempFolder, 500);
                FileHelper.CreateDirectoryRecursive(longPath);
                string longPathLibrary = Paths.Combine(longPath, "LoadStringFromLongPath.dll");
                FileMethods.CopyFile(GetNativeTestLibraryLocation(), longPathLibrary);

                using (var handle = ModuleMethods.LoadLibrary(longPathLibrary,
                                                              LoadLibraryFlags.LOAD_LIBRARY_AS_IMAGE_RESOURCE | LoadLibraryFlags.LOAD_LIBRARY_AS_DATAFILE))
                {
                    string resource = ResourceMethods.LoadString(handle, 101);
                    resource.Should().Be("Test");
                }
            }
        }
Exemplo n.º 8
0
        public static void Init(Type resourceType)
        {
            RootNamespace = resourceType.Namespace;
            if (RootNamespace.Contains("."))
            {
                RootNamespace = RootNamespace.Substring(0, RootNamespace.IndexOf('.'));
            }

            var bytesType = typeof(byte[]);

            ResourceMethods = resourceType
                              .GetProperties(BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.GetProperty)
                              .Where(e => e.PropertyType == bytesType)
                              .ToArray();
            ResourcesNames = ResourceMethods.Select(e => e.Name.Replace('_', '.')).ToArray();

            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
        }
Exemplo n.º 9
0
 public static int ShowCursor(bool show) => ResourceMethods.ShowCursor(show);
Exemplo n.º 10
0
 public static void ShowCaret(this WindowHandle window) => ResourceMethods.ShowCaret(window);
Exemplo n.º 11
0
 public static CursorHandle SetCursor(CursorHandle cursor) => ResourceMethods.SetCursor(cursor);
Exemplo n.º 12
0
 public static POINT GetCursorPosition() => ResourceMethods.GetCursorPosition();
Exemplo n.º 13
0
 public static CursorHandle SetCursor(CursorId id) => ResourceMethods.SetCursor(ResourceMethods.LoadCursor(id));
Exemplo n.º 14
0
 public static void SetCursorPosition(int x, int y) => ResourceMethods.SetCursorPosition(x, y);
Exemplo n.º 15
0
 public static void CreateCaret(this WindowHandle window, BitmapHandle bitmap, int width, int height) =>
 ResourceMethods.CreateCaret(window, bitmap, width, height);
Exemplo n.º 16
0
 public static void HideCaret(this WindowHandle window) => ResourceMethods.HideCaret(window);
Exemplo n.º 17
0
 public static void DestroyCaret() => ResourceMethods.DestroyCaret();