Click here to Skip to main content
15,885,920 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
ProcessInfo[] procs = null;
            if (denizbankProcess == null || (denizProcess != null && denizProcess.HasExited))
            {
                procs = ProcessCE.GetProcesses();
                if (procs.Where(p => p.FullPath.Contains("DotNetDeniz")).Count() > 0)
                {
                    var pid = procs.Where(p => p.FullPath.Contains("DotNetDeniz")).First().Pid;
                    denizbankProcess = Process.GetProcessById((int)pid);
                }
                //denizProcess = Process.GetProcessById(Marshal.ReadInt32(procs.Where(p => p.FullPath.Contains("DotNetEMVDeniz")).First().Pid));
                else
                {
                    var psi = new System.Diagnostics.ProcessStartInfo();
                    psi.FileName = "\\PocketStore\\WIN_CE\\DotNet\\Deniz\\DotNetDeniz.exe";
                    denizProcess = Process.Start(psi);
                    Thread.Sleep(10000);
                }
            }


What I have tried:

I am tring to show runing application.
First I can run an application, second time ı check if it is runing background ı want to show it but it is not work
Posted
Updated 4-Jan-19 22:44pm
v2

1 solution

You could probably use SetForegroundWindow function | Microsoft Docs[^] to bring the window to topmost

Something like
C#
[System.Runtime.InteropServices.DllImport("user32.dll")]
internal static extern int SetForegroundWindow(IntPtr hwnd);

...

void YourMethod() {
   ProcessInfo[] procs = null;
   if (denizbankProcess == null || (denizProcess != null && denizProcess.HasExited))
   {
      procs = ProcessCE.GetProcesses();
      if (procs.Where(p => p.FullPath.Contains("DotNetDeniz")).Count() > 0)
      {
         var pid = procs.Where(p => p.FullPath.Contains("DotNetDeniz")).First().Pid;
         denizbankProcess = Process.GetProcessById((int)pid);
         SetForegroundWindow(denizbankProcess.MainWindowHandle);
      }
      //denizProcess = Process.GetProcessById(Marshal.ReadInt32(procs.Where(p => p.FullPath.Contains("DotNetEMVDeniz")).First().Pid));
      else
      {
         var psi = new System.Diagnostics.ProcessStartInfo();
         psi.FileName = "\\PocketStore\\WIN_CE\\DotNet\\Deniz\\DotNetDeniz.exe";
         denizProcess = Process.Start(psi);
         Thread.Sleep(10000);
      }
   }
}


Note that if the window is minimized, you need to use ShowWindow function | Microsoft Docs[^] to restore or maximize the window first.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900