浮动窗口问题
我要的效果:有个浮动窗口,不管程序其他窗口怎么开关,浮动窗口都可以响应。MFC程序按下面这段代码可以实现这点。
BOOL CMFCTestApp::InitInstance()
{
//此处省略几行代码
Dlgaa * a = new Dlgaa();
a->Create(IDD_DIALOG1, NULL);
a->ShowWindow(SW_SHOW);
CMFCTestDlg dlg;
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
}
else if (nResponse == IDCANCEL)
{
}
return FALSE;
}
在主窗体上的BUTTON点击事件打开一个模式窗体:
void CMFCTestDlg::OnBnClickedOk()
{
// TODO: 在此添加控件通知处理程序代码
Dlgaa a;
a.DoModal();
// OnOK();
}
打开模式窗体后,浮动窗体扔可响应。
但是C#的WINFORM怎么实现这一效果?在有模式窗体弹出后,浮动窗体便无法响应了,下面是C#代码
[STAThread]
static void Main()
{
form2 = new Form2();
ShowWindow(form2.Handle, 5);
Application.Run(new Form1());
}
static Form2 form2;
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern Boolean ShowWindow(IntPtr hWnd,Int32 nCmdShow);
主窗体按钮点击后打开模式窗体:
private void button1_Click(object sender, System.EventArgs e)
{
Form form = new Form();
form.ShowDialog(this);
}