我需要使用alt + f4关闭exe。 1.在运行exe时,用户可以通过按PrintScreen保存屏幕截图,此时任务栏被隐藏。 2.显示保存任务栏后。 3.保存后,用户需要按Alt + f4键关闭exe文件,但控件进入窗口并显示关机窗口
保存屏幕截图后,exe需要关闭
以下是实施的代码。
private void GuiPane_KeyUp(object sender, KeyEventArgs e)
{
try
{
if ((e.KeyCode == Keys.PrintScreen))
{
Taskbar.Hide();
Bitmap bitmap;
Rectangle bounds = this.Bounds;
using ( bitmap = new Bitmap(bounds.Width, bounds.Height))
{
using (Graphics g = Graphics.FromImage(bitmap))
{
g.CopyFromScreen(new Point(bounds.Left, bounds.Top), Point.Empty, bounds.Size);
}
SaveImage(bitmap);
}
Taskbar.Show();
}
}
catch (Exception)
{
throw;
}
}
public class Taskbar
{
[DllImport("user32.dll")]
private static extern int FindWindow(string className, string windowText);
[DllImport("user32.dll")]
private static extern int ShowWindow(int hwnd, int command);
[DllImport("user32.dll")]
public static extern int FindWindowEx(int parentHandle, int childAfter, string className, int windowTitle);
[DllImport("user32.dll")]
private static extern int GetDesktopWindow();
private const int SW_HIDE = 0;
private const int SW_SHOW = 1;
protected static int Handle
{
get
{
return FindWindow("Shell_TrayWnd", "");
}
}
protected static int HandleOfStartButton
{
get
{
int handleOfDesktop = GetDesktopWindow();
int handleOfStartButton = FindWindowEx(handleOfDesktop, 0, "button", 0);
return handleOfStartButton;
}
}
private Taskbar()
{
// hide ctor
}
public static void Show()
{
ShowWindow(Handle, SW_SHOW);
ShowWindow(HandleOfStartButton, SW_SHOW);
}
public static void Hide()
{
ShowWindow(Handle, SW_HIDE);
ShowWindow(HandleOfStartButton, SW_HIDE);
}
}