**EDIT: When I put a breakpoint in my MinimizePlayer() method, and step through it, it minimizes the wmplayer process. But it does not without stepping through. I don't know why. **
I had a similar script on my Linux machine where I automated some tasks that I use every time I boot up. I was able to start Rhythmbox, begin playing my playlist, and minimize the process.
Well, I'm trying the same thing on my new Windows 10 machine, and I don't know how to minimize the wmplayer.exe process from my script.
This is what I have so far. It works fine, I just want wmplayer to be minimized:
using System;
using System.Diagnostics;
using System.Threading;
using System.Runtime.InteropServices;
namespace Playlist
{
class Program
{
[DllImport("user32.dll")]
private static extern bool ShowWindow(IntPtr hWnd, WindowShowStyle nCmdShow);
private enum WindowShowStyle:uint
{
Hide = 0,
ShowMinimized = 2,
Minimize = 6
}
static void Main(string[] args)
{
Run();
}
public static void Run()
{
String username = Environment.UserName;
username = char.ToUpper(username[0]) + username.Substring(1);
Console.WriteLine("Hello " + username);
Thread.Sleep(2000);
Console.WriteLine("Opening Playlist...");
Thread.Sleep(2000);
Process.Start("wmplayer.exe", "C:\\Users\\" + username + "\\Music\\A_ChillstepMix.mp3");
//Thread.Sleep(2000);
//Console.WriteLine("Opening your IDE...");
//Thread.Sleep(2000);
//Process.Start("C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\Common7\\IDE\\devenv.exe");
//Thread.Sleep(2000);
MinimizePlayer();
Thread.Sleep(2000);
Console.WriteLine("Goodbye...");
Thread.Sleep(2000);
System.Environment.Exit(0);
}
public static void MinimizePlayer()
{
Process[] ps = Process.GetProcesses();
foreach(Process p in ps)
{
if(p.ProcessName.Contains("wmplayer"))
{
IntPtr h = p.MainWindowHandle;
ShowWindow(h, WindowShowStyle.Minimize);
}
}
}
}
}