Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Thursday, November 14, 2013 2:53 PM
I'm calling a photo application to open within a controller of my MVC app. The application opens just fine, but sometimes it's hidden behind the browser window, which is not desirable. Is it possible to make my application "always on top"?
Code blurb:
public void OpenMyApplication(...)
{
string filePath = "C:\\somepath\somepic.jpg";
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = "MyPhotoApplication.exe";
psi.Arguments = filePath;
Process p = Process.Start(psi);
}
As said, the application opens and display the image specified, but half the time, the application ends up behind the browser. I always want it to be the top-most window.
All replies (3)
Thursday, November 14, 2013 5:01 PM
You can use the windows api directly, look for thne msdn winform forums. Anyway what is the point opening a pictureviewer process in server side code?
Thursday, January 9, 2014 5:12 AM
Hello,
I found a solution to show top most windows.
Process process = Process.Start(psi);
IntPtr windowHandle = process.MainWindowHandle;
RECT r;
GetWindowRect(new HandleRef(this, windowHandle), out r);
int cx = r.Right - r.Left;
int cy = r.Bottom - r.Top;
cx -= 20;
cy -= 20;
SetWindowPos(windowHandle, (IntPtr) SpecialWindowHandles.HWND_TOPMOST, r.Left, r.Top, cx, cy, SetWindowPosFlags.SWP_SHOWWINDOW);
Thursday, January 9, 2014 5:45 PM
I just want to verify because a lot of people use this technique without realising it but you understand this will not work in a deployed application. The code to open a process will only run on the system hosting the application. If you publish this to a server, this will attempt to open a window on the server and the user will never, ever see this. It works in development because you are both the client and the server in this case.
As I said, just making sure you realised this as we get a lot of people who try to use the Process object to start a process on a client's computer.