I am facing a problem in “BringWindowToTop” and “ShowWindow” which is occuring in some applications, but not all.
The issue is that if my applications are minimized to the taskbar, and when I open applications one by one, they all open except Outlook.
In the case of Outlook, I found using the GetWindowPlacement dll , it returns its x , y & height , width 0 value.
In Outlook if my application is in restore mode / maximize mode , process.MainWindowHandle has different value , while it is in minimize mode MainWindowHandle has different value.
Below is code :
foreach (var process in System.Diagnostics.Process.GetProcessesByName("outlook"))
{
ForceForegroundWindow1(process.MainWindowHandle, 2);
}
private static void ForceForegroundWindow1(IntPtr hWnd, int Status)
{
uint foreThread = GetWindowThreadProcessId(GetForegroundWindow(), IntPtr.Zero);
uint appThread = GetCurrentThreadId();
int SW_SHOW = 5;
if (Status == 0)
SW_SHOW = 3;
else if (Status == 2)
SW_SHOW = 9;
//SW_SHOW = 1;
const int SW_RESTORE = 9;
if (foreThread != appThread)
{
AttachThreadInput(foreThread, appThread, true);
BringWindowToTop(hWnd);
ShowWindow(hWnd, SW_SHOW);
// ShowWindowAsync(hWnd, SW_RESTORE);
AttachThreadInput(foreThread, appThread, false);
}
else
{
BringWindowToTop(hWnd);
ShowWindow(hWnd, SW_SHOW);
// ShowWindowAsync(hWnd, SW_RESTORE);
}
}
Can you help me to bring windows on top for all applications?