"VB6이 숨겨진 후에 C# 형식을 어떻게 표시합니까? 창 핸들을 사용해야합니까?"
고아가 된 msgbox가 열린 상태로 유지되는 것으로 가정하면
public static int FindWindow(string windowName, bool wait)
{
int hWnd = FindWindow(null, windowName);
while (wait && hWnd == 0)
{
System.Threading.Thread.Sleep(500);
hWnd = FindWindow(null, windowName);
}
return hWnd;
}
는 다음 상단에 C#을 창을 가지고 :
[DllImport("user32.dll", SetLastError = true)]
public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
// When you don't want the ProcessId, use this overload and pass IntPtr.Zero for the second parameter
[DllImport("user32.dll")]
public static extern uint GetWindowThreadProcessId(IntPtr hWnd, IntPtr ProcessId);
[DllImport("kernel32.dll")]
public static extern uint GetCurrentThreadId();
/// <summary>The GetForegroundWindow function returns a handle to the foreground window.</summary>
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
public static extern bool AttachThreadInput(uint idAttach, uint idAttachTo, bool fAttach);
[DllImport("user32.dll", SetLastError = true)]
public static extern bool BringWindowToTop(IntPtr hWnd);
[DllImport("user32.dll", SetLastError = true)]
public static extern bool BringWindowToTop(HandleRef hWnd);
[DllImport("user32.dll")]
public static extern bool ShowWindow(IntPtr hWnd, uint nCmdShow);
private static void ForceForegroundWindow(IntPtr hWnd)
{
uint foreThread = GetWindowThreadProcessId(GetForegroundWindow(), IntPtr.Zero);
uint appThread = GetCurrentThreadId();
const uint SW_SHOW = 5;
if (foreThread != appThread)
{
AttachThreadInput(foreThread, appThread, true);
BringWindowToTop(hWnd);
ShowWindow(hWnd, SW_SHOW);
AttachThreadInput(foreThread, appThread, false);
}
else
{
BringWindowToTop(hWnd);
ShowWindow(hWnd, SW_SHOW);
}
}
참조 : SetForegroundWindow Win32-API not always works on Windows-7
'NativeWindow'클래스는 아래쪽에 있습니다. http://social.msdn.microsoft.com/Forums/lt/vbinterop/thread/2692df26-317c-4415-816b-d08fe6854df8 – CJ7
+1 윈도우 개발자 인 Raymond Chen은이 상황에서이'AttachThreadInput' 해결 방법은 [프로그램이 응답을 멈추게 할 수 있습니다] (http://stackoverflow.com/a/8081858/15639)라고 지적합니다. 그러나 나는이 벌레들을 직접 만나 본 적이 없다. YMMV. – MarkJ
@ MarkJ : 위의 내 의견에서 취한 접근은 어떻습니까? – CJ7