1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-08-20 09:49:46 +02:00
Files
Configuration
Core
Bridge
Controls
Handling
Notification
Screenshot
FormNotificationScreenshotable.cs
TweetScreenshotManager.cs
FormNotificationBase.Designer.cs
FormNotificationBase.cs
FormNotificationMain.Designer.cs
FormNotificationMain.cs
FormNotificationTweet.Designer.cs
FormNotificationTweet.cs
SoundNotification.cs
TweetNotification.cs
Other
Utils
FormBrowser.Designer.cs
FormBrowser.cs
FormBrowser.resx
TrayIcon.Designer.cs
TrayIcon.cs
Data
Plugins
Properties
Resources
Updates
bld
lib
subprocess
tests
.gitignore
LICENSE.md
Program.cs
README.md
Reporter.cs
TweetDuck.csproj
TweetDuck.sln
TweetDuck.sln.DotSettings
_postbuild.bat
packages.config
TweetDuck/Core/Notification/Screenshot/FormNotificationScreenshotable.cs

62 lines
2.3 KiB
C#

using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
using TweetDuck.Core.Bridge;
using TweetDuck.Core.Utils;
using TweetDuck.Data;
using TweetDuck.Plugins;
using TweetDuck.Resources;
namespace TweetDuck.Core.Notification.Screenshot{
sealed class FormNotificationScreenshotable : FormNotificationBase{
private readonly PluginManager plugins;
public FormNotificationScreenshotable(Action callback, Form owner, PluginManager pluginManager) : base(owner, false){
this.plugins = pluginManager;
browser.RegisterAsyncJsObject("$TD_NotificationScreenshot", new CallbackBridge(this, callback));
browser.FrameLoadEnd += (sender, args) => {
if (args.Frame.IsMain && browser.Address != "about:blank"){
ScriptLoader.ExecuteScript(args.Frame, "window.setTimeout($TD_NotificationScreenshot.trigger, 67)", "gen:screenshot");
}
};
}
protected override string GetTweetHTML(TweetNotification tweet){
string html = tweet.GenerateHtml("td-screenshot", false);
foreach(InjectedHTML injection in plugins.Bridge.NotificationInjections){
html = injection.Inject(html);
}
return html;
}
public void LoadNotificationForScreenshot(TweetNotification tweet, int width, int height){
LoadTweet(tweet);
SetNotificationSize(width, height);
}
public void TakeScreenshot(){
IntPtr context = NativeMethods.GetDC(this.Handle);
if (context == IntPtr.Zero){
MessageBox.Show("Could not retrieve a graphics context handle for the notification window to take the screenshot.", "Screenshot Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else{
using(Bitmap bmp = new Bitmap(ClientSize.Width, ClientSize.Height, PixelFormat.Format32bppRgb)){
try{
NativeMethods.RenderSourceIntoBitmap(context, bmp);
}finally{
NativeMethods.ReleaseDC(this.Handle, context);
}
Clipboard.SetImage(bmp);
}
}
}
}
}