110,541
社区成员
发帖
与我相关
我的任务
分享
if (this.WindowState == FormWindowState.Minimized) {
this.WindowState = FormWindowState.Normal;
this.ShowInTaskbar = true;
this.Activate();
} else if (this.WindowState == FormWindowState.Maximized || this.WindowState == FormWindowState.Normal) {
this.WindowState = FormWindowState.Minimized;
this.ShowInTaskbar = false;
}
this.WindowState = FormWindowState.Normal;
this.ShowInTaskbar = true;
this.Activate();
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern IntPtr FindWindow(string strclassName, string strWindowName);
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern bool OpenIcon(IntPtr hWnd);
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern bool IsIconic(IntPtr hWnd);
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern int SetForegroundWindow(IntPtr hWnd);
void FindAndOpenWindow(string Title)
{
IntPtr hWnd = (IntPtr ) FindWindow(null, Title);
if (hWnd != IntPtr.Zero)
{
bool isIcon = IsIconic(hWnd);
if ( !isIcon )
{
SetForegroundWindow(hWnd);
}
else
{
OpenIcon(hWnd);
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace textCC
{
public partial class Form7 : Form
{
public Form7()
{
InitializeComponent();
}
[DllImport("user32.dll")]
public extern static IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
public const int SW_HIDE = 0;
public const int SW_SHOWNORMAL = 1;
public const int SW_NORMAL = 1;
public const int SW_SHOWMINIMIZED = 2;
public const int SW_SHOWMAXIMIZED = 3;
public const int SW_MAXIMIZE = 3;
public const int SW_SHOWNOACTIVATE = 4;
public const int SW_SHOW = 5;
public const int SW_MINIMIZE = 6;
public const int SW_SHOWMINNOACTIVE = 7;
public const int SW_SHOWNA = 8;
public const int SW_RESTORE = 9;
public const int SW_SHOWDEFAULT = 10;
public const int SW_FORCEMINIMIZE = 11;
public const int SW_MAX = 11;
private void button1_Click(object sender, EventArgs e)
{
IntPtr HWnd = FindWindow(null, "计算器");
MessageBox.Show("隐藏窗体");
ShowWindow(HWnd, SW_HIDE);
MessageBox.Show("显示窗体");
ShowWindow(HWnd, SW_SHOW);
}
}
}