Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void ForceForegroundWindow(IntPtr hWnd)
- {
- uint a;
- WinAPI.LockSetForegroundWindow(WinAPI.LSFW_UNLOCK);
- WinAPI.AllowSetForegroundWindow(WinAPI.ASFW_ANY);
- IntPtr hWndForeground = WinAPI.GetForegroundWindow();
- SendKeys.SendWait("{UP}");
- if (hWndForeground.ToInt32() != 0)
- {
- if (hWndForeground != hWnd)
- {
- uint thread1 = WinAPI.GetWindowThreadProcessId(hWndForeground, out a);
- uint thread2 = WinAPI.GetCurrentThreadId();
- if (thread1 != thread2)
- {
- WinAPI.AttachThreadInput(thread1, thread2, true);
- WinAPI.LockSetForegroundWindow(WinAPI.LSFW_UNLOCK);
- WinAPI.AllowSetForegroundWindow(WinAPI.ASFW_ANY);
- WinAPI.BringWindowToTop(hWnd);
- if (WinAPI.IsIconic(hWnd))
- {
- WinAPI.ShowWindow(hWnd, WinAPI.ShowWindowFlags.SW_SHOWNORMAL);
- }
- else
- {
- WinAPI.ShowWindow(hWnd, WinAPI.ShowWindowFlags.SW_SHOW);
- }
- WinAPI.SetFocus(hWnd);
- WinAPI.AttachThreadInput(thread1, thread2, false);
- }
- else
- {
- WinAPI.AttachThreadInput(thread1, thread2, true);
- WinAPI.LockSetForegroundWindow(WinAPI.LSFW_UNLOCK);
- WinAPI.AllowSetForegroundWindow(WinAPI.ASFW_ANY);
- WinAPI.BringWindowToTop(hWnd);
- WinAPI.SetForegroundWindow(hWnd);
- WinAPI.SetFocus(hWnd);
- WinAPI.AttachThreadInput(thread1, thread2, false);
- }
- if (WinAPI.IsIconic(hWnd))
- {
- WinAPI.AttachThreadInput(thread1, thread2, true);
- WinAPI.LockSetForegroundWindow(WinAPI.LSFW_UNLOCK);
- WinAPI.AllowSetForegroundWindow(WinAPI.ASFW_ANY);
- WinAPI.BringWindowToTop(hWnd);
- WinAPI.ShowWindow(hWnd, WinAPI.ShowWindowFlags.SW_SHOWNORMAL);
- WinAPI.SetFocus(hWnd);
- WinAPI.AttachThreadInput(thread1, thread2, false);
- }
- else
- {
- WinAPI.BringWindowToTop(hWnd);
- WinAPI.ShowWindow(hWnd, WinAPI.ShowWindowFlags.SW_SHOW);
- }
- }
- WinAPI.SetForegroundWindow(hWnd);
- WinAPI.SetFocus(hWnd);
- }
- else
- {
- uint thread1 = WinAPI.GetWindowThreadProcessId(hWndForeground, out a);
- uint thread2 = WinAPI.GetCurrentThreadId();
- try
- {
- WinAPI.AttachThreadInput(thread1, thread2, true);
- }
- catch
- {
- uint failure = 1;
- }
- WinAPI.LockSetForegroundWindow(WinAPI.LSFW_UNLOCK);
- WinAPI.AllowSetForegroundWindow(WinAPI.ASFW_ANY);
- WinAPI.BringWindowToTop(hWnd);
- WinAPI.SetForegroundWindow(hWnd);
- WinAPI.ShowWindow(hWnd, WinAPI.ShowWindowFlags.SW_SHOW);
- WinAPI.SetFocus(hWnd);
- WinAPI.AttachThreadInput(thread1, thread2, false);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement