ConsoleIcon support Windows 10 on new Console & OnLatencyUpdate Event (#1044)

* new ConsoleIcon support

* Update ChatBot.cs

+ OnLatencyUpdate

* Update McTcpClient.cs

+ OnLatencyUpdate

* Update Protocol18.cs

+ OnLatencyUpdate

* Update IMinecraftComHandler.cs

+ OnLatencyUpdate

* Update Protocol18.cs

+ BugFix

* Update ConsoleIcon.cs
This commit is contained in:
Рома Данилов 2020-06-07 16:16:49 +05:00 committed by GitHub
parent 85f5117833
commit b800bbcb37
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 65 additions and 4 deletions

View file

@ -21,6 +21,32 @@ namespace MinecraftClient.WinAPI
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool SetConsoleIcon(IntPtr hIcon);
/// <summary>
/// Asynchronously download the player's skin and set the head as console icon
/// </summary>
public enum WinMessages : uint
{
/// <summary>
/// An application sends the WM_SETICON message to associate a new large or small icon with a window.
/// The system displays the large icon in the ALT+TAB dialog box, and the small icon in the window caption.
/// </summary>
SETICON = 0x0080,
}
[System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
private static extern IntPtr SendMessage(IntPtr hWnd, int Msg, int wParam, IntPtr lParam);
private static void SetWindowIcon(System.Drawing.Icon icon)
{
IntPtr mwHandle = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle;
IntPtr result01 = SendMessage(mwHandle, (int)WinMessages.SETICON, 0, icon.Handle);
IntPtr result02 = SendMessage(mwHandle, (int)WinMessages.SETICON, 1, icon.Handle);
}
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool SetConsoleIcon(IntPtr hIcon);
/// <summary>
/// Asynchronously download the player's skin and set the head as console icon
/// </summary>
@ -31,7 +57,7 @@ namespace MinecraftClient.WinAPI
{
Thread t = new Thread(new ThreadStart(delegate
{
HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create("http://skins.minecraft.net/MinecraftSkins/" + playerName + ".png");
HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create("https://minotar.net/helm/" + playerName + "/100.png");
try
{
using (HttpWebResponse httpWebReponse = (HttpWebResponse)httpWebRequest.GetResponse())
@ -40,6 +66,7 @@ namespace MinecraftClient.WinAPI
{
Bitmap skin = new Bitmap(Image.FromStream(httpWebReponse.GetResponseStream())); //Read skin from network
skin = skin.Clone(new Rectangle(8, 8, 8, 8), skin.PixelFormat); //Crop skin
SetWindowIcon(Icon.FromHandle(skin.GetHicon()));
SetConsoleIcon(skin.GetHicon()); //Set skin as icon
}
catch (ArgumentException) { /* Invalid image in HTTP response */ }