/* * $RCSfile: ScreenCap.cs,v $ * Copyright (C) 2006 Rob Loach (http://robloach.net) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Text; using System.Windows.Forms; namespace ScreenCap { public partial class ScreenCap : Form { public ScreenCap() { InitializeComponent(); m_Instance = this; KeyboardListener.s_KeyEventHandler += new EventHandler(KeyboardListener_s_KeyEventHandler); } #region CreateParams // Thank you goes to uavfun for this awesome finding to disable the alt tab form. private static uint WS_POPUP = 0x80000000; private static uint WS_EX_TOPMOST = 0x00000008; private static uint WS_EX_TOOLWINDOW = 0x00000080; private static uint WS_MINIMIZE = 0x20000000; protected override CreateParams CreateParams { get { CreateParams cp = base.CreateParams; cp.Style = unchecked((int)(WS_POPUP | WS_MINIMIZE)); cp.ExStyle = (int)WS_EX_TOPMOST + (int)WS_EX_TOOLWINDOW; // Set location cp.X = 100; cp.Y = 100; return cp; } } #endregion CreateParams void KeyboardListener_s_KeyEventHandler(object sender, EventArgs e) { KeyboardListener.UniversalKeyEventArgs eventArgs = (KeyboardListener.UniversalKeyEventArgs)e; Keys key = (Keys)eventArgs.m_Key; if (key == keyCapWindow) capWindow = eventArgs.m_Msg == 256; //257 = key up, 256 = keydown else if (key == keyCapArea) capArea = eventArgs.m_Msg == 256; else if (key == Keys.PrintScreen) // print screen { if (eventArgs.m_Msg == 256) { if (capWindow) ScreenCapture.Capture(ScreenCapture.CaptureArea.Window); else if (capArea) ScreenCapture.Capture(ScreenCapture.CaptureArea.ClientArea); else ScreenCapture.Capture(ScreenCapture.CaptureArea.Fullscreen); } } } public static Keys keyCapWindow = Config.CaptureActiveWindow; public static Keys keyCapArea = Config.CaptureActiveClientArea; private bool capWindow = false; private bool capArea = false; private void exitToolStripMenuItem_Click(object sender, EventArgs e) { Config.Save(); this.Close(); Application.Exit(); } private About m_About; private Settings m_Settings; private void aboutScreenCapToolStripMenuItem_Click(object sender, EventArgs e) { if(m_About != null) m_About.Dispose(); m_About = new About(); m_About.Show(); } private void notifyIcon_MouseDoubleClick(object sender, MouseEventArgs e) { settingsToolStripMenuItem_Click(sender, e); } private void settingsToolStripMenuItem_Click(object sender, EventArgs e) { if (m_Settings != null) m_Settings.Dispose(); m_Settings = new Settings(); m_Settings.Show(); } private static ScreenCap m_Instance; public static NotifyIcon NotifyIcon { get { return m_Instance.notifyIcon; } } private void ScreenCap_Load(object sender, EventArgs e) { if(Config.NotifyStartup) notifyIcon.ShowBalloonTip(4000, "ScreenCap", "ScreenCap is now initialized and ready for screen capturing.", ToolTipIcon.Info); try { if (Config.StartupSound) SoundManager.PlayWav("startup.wav"); } catch { Config.StartupSound = false; } } private void viewScreenshotsToolStripMenuItem_Click(object sender, EventArgs e) { System.Diagnostics.Process.Start(Config.SaveDirectory); } private void ScreenCap_FormClosed(object sender, FormClosedEventArgs e) { try { Config.Save(); } catch { MessageBox.Show("ScreenCap failed to save the configuration settings.", "ScreenCap", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); } } private void ScreenCap_Shown(object sender, EventArgs e) { Hide(); } } }