Skip to content

Commit

Permalink
migrated resources
Browse files Browse the repository at this point in the history
  • Loading branch information
Valkirie committed Jul 1, 2021
1 parent d04e78a commit 91f31c9
Show file tree
Hide file tree
Showing 25 changed files with 369 additions and 109 deletions.
2 changes: 1 addition & 1 deletion MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="d3gamepad" Height="720" Width="1280" Topmost="True" AllowsTransparency="True" WindowStyle="None" Background="{x:Null}" Left="0" Top="0">
<Canvas x:Name="Canvas1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Image x:Name="GamepadIco" Height="50" Width="50" Source="Ressources/XBOne_Gamepad.png" Canvas.Top="-50" Opacity="0.75" Canvas.Left="0"/>
<Image x:Name="GamepadIco" Height="50" Width="50" Source="img/XBOne_Gamepad.png" Canvas.Top="-50" Opacity="0.75" Canvas.Left="0"/>
</Canvas>
</Window>
26 changes: 25 additions & 1 deletion MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
using System.Text;
using System.Windows.Input;
using System.Drawing;
using System.Windows.Media.Imaging;
using System.Windows.Interop;

namespace d3gamepad
{
Expand All @@ -36,6 +38,10 @@ public partial class MainWindow : Window
[DllImport("user32.dll")]
static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count);

[DllImport("gdi32.dll", EntryPoint = "DeleteObject")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool DeleteObject([In] IntPtr hObject);

public static Bitmap CaptureFromScreen(System.Drawing.Point location, int width, int height)
{
Bitmap bmpScreenCapture = new Bitmap(width, height);
Expand Down Expand Up @@ -293,6 +299,24 @@ public static void ThreadUI()
}
}

public static Bitmap GetImageByName(string imageName)
{
System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
string resourceName = asm.GetName().Name + ".Properties.Resources";
var rm = new System.Resources.ResourceManager(resourceName, asm);
return (Bitmap)rm.GetObject(imageName);
}

public ImageSource ImageSourceFromBitmap(Bitmap bmp)
{
var handle = bmp.GetHbitmap();
try
{
return Imaging.CreateBitmapSourceFromHBitmap(handle, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
}
finally { DeleteObject(handle); }
}

static d3gamepad.MainWindow myForm;
static Canvas myCanvas;
static System.Windows.Controls.Image myGamepad;
Expand Down Expand Up @@ -331,7 +355,7 @@ public MainWindow()
{
Fill = new ImageBrush
{
ImageSource = new System.Windows.Media.Imaging.BitmapImage(new Uri(".\\Ressources\\XBOne_" + ico + ".png", UriKind.Relative))
ImageSource = ImageSourceFromBitmap(GetImageByName("XBOne_" + ico))
},
Stretch = Stretch.Uniform,
};
Expand Down
258 changes: 220 additions & 38 deletions Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 91f31c9

Please sign in to comment.