add recents items list

change from stream to bytes
This commit is contained in:
nyyu 2015-09-27 13:16:15 +02:00
parent 5cf3983c1c
commit dfe251ef99
5 changed files with 65 additions and 3593 deletions

35
MainForm.Designer.cs generated
View file

@ -30,13 +30,15 @@
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.tabPage2 = new System.Windows.Forms.TabPage();
this.notifyIcon = new System.Windows.Forms.NotifyIcon(this.components);
this.contextMenu = new System.Windows.Forms.ContextMenuStrip(this.components);
this.screenCaptureToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.recentsItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
this.captureWindowMenu = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
this.settingsMenu = new System.Windows.Forms.ToolStripMenuItem();
@ -64,7 +66,7 @@
this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
this.tabPage1.Size = new System.Drawing.Size(511, 207);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "General Settings";
this.tabPage1.Text = "General";
this.tabPage1.UseVisualStyleBackColor = true;
//
// groupBox1
@ -89,7 +91,6 @@
// notifyIcon
//
this.notifyIcon.ContextMenuStrip = this.contextMenu;
this.notifyIcon.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.notifyIcon.Text = "ScreenCapture";
this.notifyIcon.Visible = true;
this.notifyIcon.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.notifyIcon1_MouseDoubleClick);
@ -97,12 +98,34 @@
// contextMenu
//
this.contextMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.screenCaptureToolStripMenuItem,
this.recentsItem,
this.toolStripSeparator2,
this.captureWindowMenu,
this.toolStripSeparator1,
this.settingsMenu,
this.closeMenu});
this.contextMenu.Name = "contextMenuStrip1";
this.contextMenu.Size = new System.Drawing.Size(207, 76);
this.contextMenu.Size = new System.Drawing.Size(207, 126);
//
// screenCaptureToolStripMenuItem
//
this.screenCaptureToolStripMenuItem.Enabled = false;
this.screenCaptureToolStripMenuItem.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold);
this.screenCaptureToolStripMenuItem.Name = "screenCaptureToolStripMenuItem";
this.screenCaptureToolStripMenuItem.Size = new System.Drawing.Size(206, 22);
this.screenCaptureToolStripMenuItem.Text = "ScreenCapture";
//
// recentsItem
//
this.recentsItem.Name = "recentsItem";
this.recentsItem.Size = new System.Drawing.Size(206, 22);
this.recentsItem.Text = "Recent Uploads";
//
// toolStripSeparator2
//
this.toolStripSeparator2.Name = "toolStripSeparator2";
this.toolStripSeparator2.Size = new System.Drawing.Size(203, 6);
//
// captureWindowMenu
//
@ -136,7 +159,6 @@
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(544, 258);
this.Controls.Add(this.tabControl1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "MainForm";
@ -164,6 +186,9 @@
private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
private System.Windows.Forms.ToolStripMenuItem closeMenu;
private System.Windows.Forms.ToolStripMenuItem settingsMenu;
private System.Windows.Forms.ToolStripMenuItem screenCaptureToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem recentsItem;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
}
}

View file

@ -1,4 +1,7 @@
using System;
using System.Diagnostics;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
namespace ScreenCapture
@ -6,10 +9,16 @@ namespace ScreenCapture
public partial class MainForm : Form
{
private KeyboardHook hook;
private bool forceClose = false;
public MainForm()
{
InitializeComponent();
Icon appIcon = Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location);
this.Icon = appIcon;
this.notifyIcon.Icon = appIcon;
hook = new KeyboardHook(this.Handle);
hook.KeyPressed += CaptureWindow_Click;
hook.RegisterHotKey(ModifierKeysWin.Win, Keys.F12);
@ -40,17 +49,18 @@ namespace ScreenCapture
{
ScreenCapture sc = ScreenCapture.Instance;
sc.CaptureWindow();
string link = await Web.upload(sc.Stream, sc.FileName);
string link = await Web.upload(sc.Bytes, sc.FileName);
sc.Release();
Clipboard.SetText(link);
ShowNotification(link);
this.recentsItem.DropDownItems.Add(link, null, (s, evt) => Process.Start(s.ToString()));
}
private void Close_Click(object sender, EventArgs e)
{
Application.Exit();
forceClose = true;
Close();
}
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
@ -65,10 +75,13 @@ namespace ScreenCapture
private void OnClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;
this.ShowInTaskbar = false;
this.WindowState = FormWindowState.Minimized;
Hide();
if (!forceClose)
{
e.Cancel = true;
this.ShowInTaskbar = false;
this.WindowState = FormWindowState.Minimized;
Hide();
}
}
private void MainForm_Load(object sender, EventArgs e)

File diff suppressed because it is too large Load diff

View file

@ -29,7 +29,7 @@ namespace ScreenCapture
private readonly static ImageCodecInfo codecPNG = GetEncoderInfo(ImageFormat.Png);
public string FileName { get; private set; }
public MemoryStream Stream { get; private set; }
public Byte[] Bytes { get; private set; }
private ScreenCapture()
{
@ -43,8 +43,7 @@ namespace ScreenCapture
public void Release()
{
Stream.Close();
Stream.Dispose();
Bytes = null;
FileName = null;
}
@ -70,8 +69,10 @@ namespace ScreenCapture
{
g.CopyFromScreen(new Point(bounds.Left, bounds.Top), Point.Empty, bounds.Size);
}
Stream = BestStream(image);
Stream.Seek(0, SeekOrigin.Begin);
using (MemoryStream ms = BestStream(image))
{
Bytes = ms.ToArray();
}
}
}

14
Web.cs
View file

@ -1,5 +1,4 @@
using System;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
@ -7,18 +6,15 @@ namespace ScreenCapture
{
static class Web
{
public static async Task<string> upload(MemoryStream ms, string fileName)
public static async Task<string> upload(byte[] bytes, string fileName)
{
using (HttpClient client = new HttpClient())
using (var content = new MultipartFormDataContent("------Upload" + DateTime.Now.Ticks))
{
using (var content = new MultipartFormDataContent("------Upload" + DateTime.Now.Ticks))
content.Add(new ByteArrayContent(bytes), "file", fileName);
using (var message = await client.PostAsync("http://nyyu.tk/sc/api.php", content))
{
content.Add(new StreamContent(ms), "file", fileName);
using (var message = await client.PostAsync("http://nyyu.tk/sc/api.php", content))
{
return await message.Content.ReadAsStringAsync();
}
return await message.Content.ReadAsStringAsync();
}
}
}