C#에서 양식을 만들고 다른 응용 프로그램 창 앞에 쌓아 넣는 응용 프로그램이 있습니다. SetParent
을 사용하여이 작업을 수행합니다. 그러나 (새) 상위 창이 동결됩니다.SetParent를 사용하여 부모 창 고정
어떻게 해결할 수 있습니까? 이 문제가 스레딩의 문제입니까?
private void Test(object sender, EventArgs e)
{
FormCover cov = new FormCover();
IntPtr hwnd = Win32Utils.FindWindowByCaptionStart(IntPtr.Zero, TrackerName, null);
Win32Utils.SetParent(cov.Handle, hwnd);
cov.SetDesktopLocation(0, 0);
cov.Show();
}
을하지만 (타이머가 경과와 함께 이벤트)하지입니다 :
이 작동하고
public partial class Form1 : Form
{
FormCover cover;
void tmrCheck_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
ShowCover();
}
private void ShowCover()
{
cover = new FormCover();
IntPtr hwnd = Win32Utils.FindWindowByCaptionStart(IntPtr.Zero, TrackerName, null);
cover.CoverInitialize(hwnd);
cover.Activate();
}
}
//------
public partial class FormCover : Form
{
public delegate void IntPtrDlg(IntPtr param);
public FormCover()
{
InitializeComponent();
}
internal void CoverInitialize(IntPtr hwdnParent)
{
if (this.InvokeRequired)
{
this.Invoke(new IntPtrDlg(CoverInitialize), new object[] { hwdnParent });
}
else
{
Win32Utils.SetParent(this.Handle, hwdnParent);
this.SetDesktopLocation(0, 0);
}
}
internal void CoverActivate(IntPtr handleFormulario)
{
if (!Visible)
this.Show();
}
internal void CoverFinalize()
{
Hide();
Win32ParentUtils.SetParent(Handle, new IntPtr());
}
}
이 두 샘플의 차이점은 무엇입니까? 첫 번째는 잘 작동하고 두 번째는 첫 번째 창을 멈추게합니다.
다음과 같이 간단하게 창을 만들 수 없다고 생각합니다. 모달 창 일 때 창에는 메시지 펌프가 필요합니다. –
CoverInitialize 에서처럼 (Begin) Invoke 메서드를 사용하여 GUI 스레드에서 전체 ShowCover 메서드를 실행 해보십시오. – Bond