Cześć wszystkim,
Potrzebuję program który spakuje folder do archiwum wyświetlając przy tym pasek postępu, a następnie otworzy to archiwum na pierwszym planie. Program musi poprawnie pracować na windowsie 10 w trybie tabletu i tutaj jest problem z którym nie mogę sobie poradzić.
Napisałem program jak niżej, niestety czasami otwiera się archiwum na pierwszym planie a czasem zostaje na pasku - masakra z tym trybem tabletu.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO.Compression;
using System.Threading;
using System.Threading.Tasks;
using System.ComponentModel;
namespace PoprawioneKartyCheck
{
/// <summary>
/// Description of MainForm.
/// </summary>
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
[System.Runtime.InteropServices.DllImport("User32.dll")]
private static extern bool SetForegroundWindow(IntPtr handle);
[System.Runtime.InteropServices.DllImport("User32.dll")]
private static extern bool ShowWindow(IntPtr handle, int nCmdShow);
[System.Runtime.InteropServices.DllImport("User32.dll")]
private static extern bool IsIconic(IntPtr handle);
public async void MainFormLoad(object sender, EventArgs e)
{
string filePath = @"C:\Program Files\7-Zip\7z.exe";
string sciezkapakowania = @"2";
string spakowanyfolder = @"1.7z";
try
{
ProcessStartInfo startInfo = new ProcessStartInfo();
{
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
startInfo.CreateNoWindow = true;
startInfo.FileName = filePath;
startInfo.Arguments = "u -uq0 -t7z \"" + spakowanyfolder + "\" \"" + sciezkapakowania + "\" -mx=1";
progressBar1.Style = ProgressBarStyle.Marquee;
progressBar1.MarqueeAnimationSpeed = 20;
label3.Text = "Proszę czekać, zaraz otworzę";
}
using (Process process = new Process {StartInfo = startInfo})
await Task.Run (() =>
{
process.Start();
process.WaitForExit();
});
progressBar1.Style = ProgressBarStyle.Continuous;
progressBar1.MarqueeAnimationSpeed = 0;
Process proc = Process.Start(@"1.7z");
const int SW_RESTORE = 9;
IntPtr handle = proc.MainWindowHandle;
if (IsIconic(handle))
{
ShowWindow(handle, SW_RESTORE);
}
SetForegroundWindow(handle);
Application.Exit();
}
catch (Exception ex)
{
MessageBox.Show("Wystąpił błąd:" + ex.Message, "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}