[C#] 스플래시 윈도를 만들었는데 자꾸 뒤로 숨는다면?

2014. 2. 26. 22:02Coders

스플래시 윈도를 만들었습니다.

쓰레드를 사용해서 잘 만들었기는 한데, 이게 메인 폼 exe를 탐색기 등에서 실행할 때면 꼭 탐색기 뒤로 숨는 겁니다. 이것 저것 다 해 봤습니다만, 안되더군요. 앙대요 앙대!

그간, 이것저것 해 본 건, Form의 TopMost = true; 뭐 이런 건 기본이요, Win32 API 인 SetForegroundWindow 등의 함수도 다 써 봤죠. 그래도 안 땡겨 오는 겁니다.


별 생 쑈를 다 하다가...

코드프로젝트에서 발견했습니다.

http://www.codeproject.com/Articles/21062/Splash-Screen-Control


죽- 읽어가다 보면,

오호호,

Next, we override OnHandleCreated and set the Parent of our window to the Desktop window.

이런 얘기가 있더군요.

그래서 적용해 보았습니다. 잘 됩니다.

개념은, 말 그대로, 해당 스플래시 윈도의 부모로 데스크탑을 주는 겁니다.

아 이런 건 잘 적어 놔야 혀. 흐흐.

스택오버플로우, 코드프로젝트 없음 개발 일 못 할 것 같아요.

protected override void OnHandleCreated(EventArgs e)
{
	if (this.Handle != IntPtr.Zero)
	{
		IntPtr hWndDeskTop = GetDesktopWindow();
		SetParent(this.Handle, hWndDeskTop);
	}

	base.OnHandleCreated(e);
}

[DllImport("user32.dll", SetLastError = false)]
private static extern IntPtr GetDesktopWindow();

[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

몇 달을 고생시키던 숙변이 빠진 것 같네요.