I am working on WPF application. I got a scenario where I need to find a unmanaged popup window when it pops up and bring it to front of the application. I used user32.dll and following code snippet (something like) to achieve it:
private void SetPopupScreenForeground()
{
string popupTitle = "Popup Screen"
IntPtr hwnd = FindWindowByCaption(IntPtr.Zero, popupTitle);
if (IntPtr.Zero != hwnd)
{
SetForegroundWindow(hwnd);
}
}
But when I installed my application in another machine, the code is not working. From internet, I found the reason being the code is running as a service and does not have access in the different machine. Is there any workaround for this issue?
Is there any way to find unmanaged window and bring it to front in WPF application without using user32.dll? Please help.
The issue is actually how Windows handles “desktops”. Services run under a special desktop that has no ability to interact with the user’s desktop. You will need to communicate using a shared object such as a named pipe.
Here is a duplicate question:
How to use FindWindow() from a service application?