public void ActivateApplication()
        {
            var mainFormHandle = IntPtr.Zero;

            foreach (var process in Process.GetProcesses().Where(x => x.ProcessName.Contains("SiteManager")))
            {
                if (process.MainWindowHandle.ToInt32() == 0)
                {
                    continue;
                }
                mainFormHandle = process.MainWindowHandle;
                break;
            }
            if (mainFormHandle.ToInt32() == 0)
            {
                return;
            }
            WinAPIHelper.ShowWindow(mainFormHandle, WindowShowStyle.ShowMaximized);
            WinAPIHelper.MakeTopMost(mainFormHandle); WinAPIHelper.MakeNormal(mainFormHandle);
            uint lpdwProcessId;

            WinAPIHelper.AttachThreadInput(WinAPIHelper.GetCurrentThreadId(), WinAPIHelper.GetWindowThreadProcessId(WinAPIHelper.GetForegroundWindow(), out lpdwProcessId), true);
            WinAPIHelper.SetForegroundWindow(mainFormHandle);
            WinAPIHelper.AttachThreadInput(WinAPIHelper.GetCurrentThreadId(), WinAPIHelper.GetWindowThreadProcessId(WinAPIHelper.GetForegroundWindow(), out lpdwProcessId), false);
        }
        private void FormFileDescription_Shown(object sender, EventArgs e)
        {
            WinAPIHelper.ShowWindow(Handle, WindowShowStyle.ShowNormal);
            WinAPIHelper.MakeTopMost(Handle); WinAPIHelper.MakeNormal(Handle);
            uint lpdwProcessId;

            WinAPIHelper.AttachThreadInput(WinAPIHelper.GetCurrentThreadId(), WinAPIHelper.GetWindowThreadProcessId(WinAPIHelper.GetForegroundWindow(), out lpdwProcessId), true);
            WinAPIHelper.SetForegroundWindow(Handle);
            WinAPIHelper.AttachThreadInput(WinAPIHelper.GetCurrentThreadId(), WinAPIHelper.GetWindowThreadProcessId(WinAPIHelper.GetForegroundWindow(), out lpdwProcessId), false);
        }
Esempio n. 3
0
        private static void TakeSemaphorFailed()
        {
            var procs = AppHelper.GetAllProcessesButThis();
            var count = procs.Length;

            switch (count)
            {
            case 1:
                MessageBox.Show("Application is already launched", "Info");
                WinAPIHelper.ShowWindow(procs[0].MainWindowHandle, ShowWindowCommands.Normal);
                break;

            default:
                MessageBox.Show("Allowable limit of " + count + " copies exhausted", "Info");
                break;
            }
        }