private AppViewHandle spawnProc(AppView av) { AppViewHandle avh = new AppViewHandle(); // Start the process if (String.IsNullOrWhiteSpace(av.appFile)) return avh; avh.settings = av; var psh = new ProcessStartInfo(av.appFile, av.appArgs); psh.WindowStyle = ProcessWindowStyle.Minimized; avh.process = new Process(); avh.process.StartInfo = psh; avh.process.Start(); avh.process.WaitForInputIdle(); int retries = 0; while (retries<10) { switch (av.findWindowMethod) { case FindWindowMethod.CaptionSearch: avh.handle = User32.FindWindowByCaption(av.captionMatch); break; case FindWindowMethod.MainWindow: avh.handle = avh.process.MainWindowHandle; break; } if (avh.handle == IntPtr.Zero) { Thread.Sleep(100); retries++; } else break; } avh.panel = new Panel(); avh.panel.BackColor = Color.FromArgb(av.background); avh.panel.Width = Width; avh.panel.Height = GetHeightFromPercent(avh.settings.coverPercent); avh.panel.Top = 0; avh.panel.Left = 0; avh.panel.Visible = false; this.Controls.Add(avh.panel); Thread.Sleep(av.initDelay); // Set the panel control as the application's parent User32.SetParent(avh.handle, avh.panel.Handle); // Maximize application if(av.needsMaximize) User32.SendMessage(avh.handle, 274, 61488, 0); // Set window style to no borders var lStyle = User32.GetWindowLong(avh.handle, User32.GWL_STYLE); lStyle &= ~(User32.WS_CAPTION | User32.WS_THICKFRAME | User32.WS_SYSMENU); User32.SetWindowLong(avh.handle, User32.GWL_STYLE, lStyle); int lExStyle = User32.GetWindowLong(avh.handle, User32.GWL_EXSTYLE); lExStyle &= ~(User32.WS_EX_DLGMODALFRAME | User32.WS_EX_CLIENTEDGE | User32.WS_EX_STATICEDGE); User32.SetWindowLong(avh.handle, User32.GWL_EXSTYLE, lExStyle); // Call pRedraw pRedraw(avh, av); return avh; }
private void SaveAV(int index) { var av = new AppView { name = tbName.Text, appFile = tbAppFile.Text, appArgs = tbAppArgs.Text, captionMatch = tbCaptionMatch.Text, findWindowMethod = (FindWindowMethod)cbFindWindowMethod.SelectedIndex, hotKey = selectedKey, hotKeyModifier = (cbModAlt.Checked ? KeyModifier.Alt : 0) | (cbModCtrl.Checked ? KeyModifier.Ctrl : 0) | (cbModShift.Checked ? KeyModifier.Shift : 0) | (cbModWin.Checked ? KeyModifier.Win : 0), launchAtStart = cbLaunchAtStart.Checked, needsMaximize = cbMaximize.Checked, needsMove = cbMove.Checked, needsResize = cbResize.Checked, initDelay = int.Parse(tbDelay.Text), alpha = tbAlpha.Value, coverPercent = 100 - tbCover.Value, background = pBackground.BackColor.ToArgb() }; if (settings.appViews[index] != av) { settings.appViews[index] = av; avNames[index] = av.name; } }
private void pRedraw(AppViewHandle avh, AppView av) { int swpFlags = User32.SWP_FRAMECHANGED | User32.SWP_NOZORDER; if (!av.needsMove) swpFlags |= User32.SWP_NOMOVE; if (!av.needsResize) swpFlags |= User32.SWP_NOSIZE; User32.SetWindowPos(avh.handle, IntPtr.Zero, 0, 0, screenBounds.Width, GetHeightFromPercent(av.coverPercent), swpFlags); }
private void LoadAV(AppView av) { tbName.Text = av.name; tbAppFile.Text = av.appFile; tbAppArgs.Text = av.appArgs; tbCaptionMatch.Text = av.captionMatch; cbFindWindowMethod.SelectedIndex = (int)av.findWindowMethod; SetHotkey(av.hotKey); cbModAlt.Checked = (av.hotKeyModifier & KeyModifier.Alt) == KeyModifier.Alt; cbModCtrl.Checked = (av.hotKeyModifier & KeyModifier.Ctrl) == KeyModifier.Ctrl; cbModShift.Checked = (av.hotKeyModifier & KeyModifier.Shift) == KeyModifier.Shift; cbModWin.Checked = (av.hotKeyModifier & KeyModifier.Win) == KeyModifier.Win; cbLaunchAtStart.Checked = av.launchAtStart; cbResize.Checked = av.needsResize; cbMove.Checked = av.needsMove; cbMaximize.Checked = av.needsMaximize; tbDelay.Text = av.initDelay.ToString(); tbAlpha.Value = av.alpha; tbCover.Value = 100 - av.coverPercent; pBackground.BackColor = Color.FromArgb(av.background); }