修复使用 user32.dll 的第三方控件
public partial class Form1 : Form
{
TheForm theForm;//empty form
public Form1()
{
InitializeComponent();
theForm = new TheForm();
}
internal const int SWP_SHOWWINDOW = 0x0040;
[DllImport("user32.dll", CharSet = CharSet.Auto)]
internal static extern int ShowWindow(IntPtr hWnd, short cmdShow);
private void button1_Click(object sender, EventArgs e)//shows theForm when it wants to
{
ShowWindow(theForm.Handle, SWP_SHOWWINDOW);
}
private void button2_Click(object sender, EventArgs e)//shows theForm always
{
theForm.Show();
}
}
为什么在调用 user32 ShowWindow 之后,大多数时候窗口“陷入困境”?它捕获失去焦点和处置,但不捕获鼠标事件并且不绘制自身。