using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Threading;
using Microsoft.Win32;
namespace ScreenCapture {
class ScreenCapture {
public static NotifyIcon notifyIcon;
public static About about;
public static Semaphore semaphore=new Semaphore(0,1);
[STAThread]
public static void Main(String[] data) {
about=new About();
about.CreateControl();
about.TopMost=true;
notifyIcon=new NotifyIcon();
notifyIcon.Icon=Icon.FromHandle(Resources.ProjectIcon.GetHicon());
notifyIcon.Text="Left click: collect; Right-click: about";
notifyIcon.Visible=true;
notifyIcon.MouseClick+=new MouseEventHandler(icon_MouseClick);
semaphore.WaitOne();
}
[STAThread]
static void icon_MouseClick(object sender,MouseEventArgs e) {
if(e.Button==MouseButtons.Left) {
CaptureImage();
}
if(e.Button==MouseButtons.Right) {
Application.EnableVisualStyles();
about.ShowDialog();
}
}
public static void CaptureImage() {
notifyIcon.Icon=Icon.FromHandle(Resources.ProjectIconOn.GetHicon());
Rectangle SelectionRectangle=Screen.PrimaryScreen.WorkingArea;
using(Bitmap bitmap=new Bitmap(SelectionRectangle.Width,SelectionRectangle.Height)) {
using(Graphics g=Graphics.FromImage(bitmap)) {
g.CopyFromScreen(Point.Empty,Point.Empty,SelectionRectangle.Size);
}
bitmap.Save(getFolder()+"\\"+getTimeStamp()+".PNG",ImageFormat.Png);
}
Thread.Sleep(250);
notifyIcon.Icon=Icon.FromHandle(Resources.ProjectIcon.GetHicon());
}
static RegistryKey key=Registry.CurrentUser.OpenSubKey("Software",true).CreateSubKey("dragosmateis").CreateSubKey("ScreenCapture");
public static String getPath() {
return ""+key.GetValue("savePath");
}
private static void setPath(String value) {
key.SetValue("savePath",value);
}
private static String getFolder() {
for(;;) {
String path=getPath();
if((path!=null)&&path.Length>0) {
FileAttributes attr=File.GetAttributes(path);
if((attr&FileAttributes.Directory)==FileAttributes.Directory)
return path;
}
selectFolder();
}
}
internal static void selectFolder() {
FolderBrowserDialog fbd=new FolderBrowserDialog();
fbd.SelectedPath=getPath();
fbd.ShowNewFolderButton=true;
fbd.ShowDialog();
setPath(fbd.SelectedPath);
}
private static String getTimeStamp() {
DateTime dt=DateTime.Now;
return f(dt.Year)+'.'+f(dt.Month)+'.'+f(dt.Day)+'-'+f(dt.Hour)+'.'+f(dt.Minute)+'.'+f(dt.Second)+'.'+f(dt.Millisecond/10);
}
private static String f(int i) {
i=i%100;
String result=""+i;
while(result.Length<2)
result="0"+result;
return result;
}
}
}