110,567
社区成员
发帖
与我相关
我的任务
分享
[DllImport("User32.dll")]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
private void Form1_SizeChanged(object sender, System.EventArgs e)
{//当窗体的大小改变时
if(WindowState==FormWindowState.Minimized)
{
this.Visible=false;
this.notifyIcon1.Visible=true;
this.Hide();
}
}
private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
{//使用托盘还原窗体
this.Visible=true;
this.WindowState=FormWindowState.Normal;
this.notifyIcon1.Visible=false;
}
void FirstInstance()
{
HWND pFirstWindow;
if ( pFirstWindow = FindWindow( NULL, L"窗体的名称" ) )
{
if( IsIconic(pFirstWindow) )
ShowWindowAsync(pFirstWindow, 9); // 9:SW_RESTORE标志,表示还原窗体
SetForegroundWindow(pFirstWindow);
PostMessage( pFirstWindow, WM_SHOWWINDOW, true, 0 );
exit(0);
}
else
{
//
}
}