[DllImport("user32.dll", EntryPoint = "FindWindow")]
public static extern int b(string lpClassName, string lpWindowName);
[DllImport("user32.dll", EntryPoint = "SetWindowPos")]
public static extern int a(int hwnd, int hWndInsertAfter, int x, int y, int cx, int cy, int wFlags);
//点击picturebox事件触发 窗体打开
private void pictureBox2_Click(object sender, EventArgs e)
{
OA fm = new OA();
if (Context.IsHasOpen("OA"))
{
a(b(null, "OA"), -1, 0, 0, 0, 0, 0x001 | 0x002 | 0x040);
a(b(null, "Test2"), -2, 0, 0, 0, 0, 0x001 | 0x002 | 0x040);
}
else
{
if (Context.OpenForm.Length > 0)
{
Context.OpenForm += ",";
}
Context.OpenForm += "OA";
fm.Show();
}
}
private void pictureBox3_Click(object sender, EventArgs e)
{
Test2 f = new Test2();
if (Context.IsHasOpen("Test2"))
{
a(b(null, "Test2"), -1, 0, 0, 0, 0, 0x001 | 0x002 | 0x040);
a(b(null, "OA"), -2, 0, 0, 0, 0, 0x001 | 0x002 | 0x040);
}
else
{
if (Context.OpenForm.Length > 0)
{
Context.OpenForm += ",";
}
Context.OpenForm += "Test2";
f.Show();
}
}
//Content 类
public class Context
{
public static string OpenForm = "";
//记录打开窗体名称
public static bool IsHasOpen(string newForm)
{
bool bR = false;
string[] arrylist = OpenForm.Split(',');
if (arrylist.Length > 0)
{
foreach (string str in arrylist)
{
if (newForm == str)
{
bR = true;
break;
}
else
{
bR = false;
}
}
}
return bR;
}
//窗体关闭触发此事件,清除对应窗体名称
public static string DeleteOpenFrom(string strForm)
{
string[] arrylist = OpenForm.Split(',');
if (arrylist.Length > 0)
{
OpenForm = "";
foreach (string str in arrylist)
{
if (strForm == str)
{
}
else
{
if (OpenForm.Length <= 0)
{
OpenForm += str;
}
else
{
OpenForm += "," + str;
}
}
}
}
return OpenForm;
}
}