public void CreateMenu() { using (MenuHandle menu = ResourceMethods.CreateMenu()) { menu.IsInvalid.Should().BeFalse(); } }
public void AppendMenu() { using (MenuHandle menu = ResourceMethods.CreateMenu()) { menu.IsInvalid.Should().BeFalse(); ResourceMethods.AppendMenu(menu, "&File", 1000); } }
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)); }
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"); } } }
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; }
public static int ShowCursor(bool show) => ResourceMethods.ShowCursor(show);
public static void ShowCaret(this WindowHandle window) => ResourceMethods.ShowCaret(window);
public static CursorHandle SetCursor(CursorHandle cursor) => ResourceMethods.SetCursor(cursor);
public static POINT GetCursorPosition() => ResourceMethods.GetCursorPosition();
public static CursorHandle SetCursor(CursorId id) => ResourceMethods.SetCursor(ResourceMethods.LoadCursor(id));
public static void SetCursorPosition(int x, int y) => ResourceMethods.SetCursorPosition(x, y);
public static void CreateCaret(this WindowHandle window, BitmapHandle bitmap, int width, int height) => ResourceMethods.CreateCaret(window, bitmap, width, height);
public static void HideCaret(this WindowHandle window) => ResourceMethods.HideCaret(window);
public static void DestroyCaret() => ResourceMethods.DestroyCaret();