Permalink
Browse files

adding solution to github

  • Loading branch information...
0 parents commit 3bebb0eb8e21a5fb19496669e979517dba2bd24f @mcw0933 committed Apr 25, 2011
Showing with 4,088 additions and 0 deletions.
  1. +20 −0 StackOverflowWPF.sln
  2. BIN StackOverflowWPF.suo
  3. +8 −0 StackOverflowWPF/App.xaml
  4. +12 −0 StackOverflowWPF/App.xaml.cs
  5. +99 −0 StackOverflowWPF/HtmlGenerator.cs
  6. +42 −0 StackOverflowWPF/IViewObject.cs
  7. +9 −0 StackOverflowWPF/MainWindow.xaml
  8. +66 −0 StackOverflowWPF/MainWindow.xaml.cs
  9. +55 −0 StackOverflowWPF/Properties/AssemblyInfo.cs
  10. +79 −0 StackOverflowWPF/Properties/Resources.Designer.cs
  11. +3,134 −0 StackOverflowWPF/Properties/Resources.resx
  12. +30 −0 StackOverflowWPF/Properties/Settings.Designer.cs
  13. +7 −0 StackOverflowWPF/Properties/Settings.settings
  14. +103 −0 StackOverflowWPF/StackOverflowWPF.csproj
  15. BIN StackOverflowWPF/bin/Debug/StackOverflowWPF.exe
  16. BIN StackOverflowWPF/bin/Debug/StackOverflowWPF.pdb
  17. BIN StackOverflowWPF/bin/Debug/StackOverflowWPF.vshost.exe
  18. +11 −0 StackOverflowWPF/bin/Debug/StackOverflowWPF.vshost.exe.manifest
  19. +68 −0 StackOverflowWPF/obj/x86/Debug/App.g.cs
  20. +68 −0 StackOverflowWPF/obj/x86/Debug/App.g.i.cs
  21. BIN StackOverflowWPF/obj/x86/Debug/DesignTimeResolveAssemblyReferences.cache
  22. BIN StackOverflowWPF/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache
  23. BIN StackOverflowWPF/obj/x86/Debug/GenerateResource.read.1.tlog
  24. BIN StackOverflowWPF/obj/x86/Debug/GenerateResource.write.1.tlog
  25. BIN StackOverflowWPF/obj/x86/Debug/MainWindow.baml
  26. +112 −0 StackOverflowWPF/obj/x86/Debug/MainWindow.g.cs
  27. +112 −0 StackOverflowWPF/obj/x86/Debug/MainWindow.g.i.cs
  28. BIN StackOverflowWPF/obj/x86/Debug/StackOverflowWPF.Properties.Resources.resources
  29. +13 −0 StackOverflowWPF/obj/x86/Debug/StackOverflowWPF.csproj.FileListAbsolute.txt
  30. BIN StackOverflowWPF/obj/x86/Debug/StackOverflowWPF.exe
  31. BIN StackOverflowWPF/obj/x86/Debug/StackOverflowWPF.g.resources
  32. BIN StackOverflowWPF/obj/x86/Debug/StackOverflowWPF.pdb
  33. +20 −0 StackOverflowWPF/obj/x86/Debug/StackOverflowWPF_MarkupCompile.cache
  34. +20 −0 StackOverflowWPF/obj/x86/Debug/StackOverflowWPF_MarkupCompile.i.cache
  35. BIN StackOverflowWPF/obj/x86/Debug/TempPE/Properties.Resources.Designer.cs.dll
@@ -0,0 +1,20 @@
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StackOverflowWPF", "StackOverflowWPF\StackOverflowWPF.csproj", "{A7C91CF3-3361-4310-95BC-81F580E3FB06}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|x86 = Debug|x86
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {A7C91CF3-3361-4310-95BC-81F580E3FB06}.Debug|x86.ActiveCfg = Debug|x86
+ {A7C91CF3-3361-4310-95BC-81F580E3FB06}.Debug|x86.Build.0 = Debug|x86
+ {A7C91CF3-3361-4310-95BC-81F580E3FB06}.Release|x86.ActiveCfg = Release|x86
+ {A7C91CF3-3361-4310-95BC-81F580E3FB06}.Release|x86.Build.0 = Release|x86
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
Binary file not shown.
@@ -0,0 +1,8 @@
+<Application x:Class="StackOverflowWPF.App"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ StartupUri="MainWindow.xaml">
+ <Application.Resources>
+
+ </Application.Resources>
+</Application>
@@ -0,0 +1,12 @@
+using System;
+using System.Windows;
+
+namespace StackOverflowWPF
+{
+ /// <summary>
+ /// Interaction logic for App.xaml
+ /// </summary>
+ public partial class App : Application
+ {
+ }
+}
@@ -0,0 +1,99 @@
+using System;
+using System.Drawing;
+using System.Windows.Forms;
+
+namespace StackOverflowWPF
+{
+ class HtmlPaginator
+ {
+ public event EventHandler<PageImageEventArgs> PageReady;
+
+ protected virtual void OnPageReady(PageImageEventArgs e)
+ {
+ EventHandler<PageImageEventArgs> handler = this.PageReady;
+ if (handler != null)
+ handler(this, e);
+ }
+
+ public class PageImageEventArgs : EventArgs
+ {
+ public Image PageImage { get; set; }
+ public int PageNumber { get; set; }
+ }
+
+ public void GeneratePages(string url)
+ {
+ Bitmap htmlImage = RenderHtmlToBitmap(url);
+
+ int pageWidth = 800;
+ int pageHeight = 600;
+
+ int xLoc = 0;
+ int yLoc = 0;
+ int pages = 0;
+
+ do
+ {
+ int remainingHeightOrPageHeight = Math.Min(htmlImage.Height - yLoc, pageHeight);
+ int remainingWidthOrPageWidth = Math.Min(htmlImage.Width - xLoc, pageWidth);
+ Rectangle cropFrame = new Rectangle(xLoc, yLoc, remainingWidthOrPageWidth, remainingHeightOrPageHeight);
+
+ Bitmap page = htmlImage.Clone(cropFrame, htmlImage.PixelFormat);
+
+ pages++;
+ PageImageEventArgs args = new PageImageEventArgs { PageImage = page, PageNumber = pages };
+ OnPageReady(args);
+
+ yLoc += pageHeight;
+
+ if (yLoc > htmlImage.Height)
+ {
+ xLoc += pageWidth;
+
+ if (xLoc < htmlImage.Width)
+ {
+ yLoc = 0;
+ }
+ }
+ }
+ while (yLoc < htmlImage.Height && xLoc < htmlImage.Width);
+ }
+
+ private static Bitmap RenderHtmlToBitmap(string url)
+ {
+ Bitmap htmlImage = null;
+
+ using (var webBrowser = new WebBrowser())
+ {
+ webBrowser.ScrollBarsEnabled = false;
+ webBrowser.ScriptErrorsSuppressed = true;
+ //webBrowser.DocumentText = doc;
+ webBrowser.Navigate(url);
+
+ while (webBrowser.ReadyState != WebBrowserReadyState.Complete)
+ {
+ Application.DoEvents();
+ }
+
+ webBrowser.Width = webBrowser.Document.Body.ScrollRectangle.Width;
+ webBrowser.Height = webBrowser.Document.Body.ScrollRectangle.Height;
+
+ htmlImage = new Bitmap(webBrowser.Width, webBrowser.Height);
+ using (Graphics graphics = Graphics.FromImage(htmlImage))
+ {
+ var hdc = graphics.GetHdc();
+
+ var rect1 = new Rectangle(0, 0, webBrowser.Width, webBrowser.Height);
+ var rect2 = new Rectangle(0, 0, webBrowser.Width, webBrowser.Height);
+
+ var viewObject = (IViewObject)webBrowser.Document.DomDocument;
+ viewObject.Draw(1, -1, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, hdc, ref rect1, ref rect2, IntPtr.Zero, 0);
+
+ graphics.ReleaseHdc(hdc);
+ }
+ }
+
+ return htmlImage;
+ }
+ }
+}
@@ -0,0 +1,42 @@
+using System;
+using System.Runtime.InteropServices;
+using System.Drawing;
+using System.Runtime.InteropServices.ComTypes;
+
+namespace StackOverflowWPF
+{
+ [ComVisible(true), ComImport()]
+ [GuidAttribute("0000010d-0000-0000-C000-000000000046")]
+ [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
+ public interface IViewObject
+ {
+ [return: MarshalAs(UnmanagedType.I4)]
+ [PreserveSig]
+ int Draw(
+ [MarshalAs(UnmanagedType.U4)] UInt32 dwDrawAspect,
+ int lindex,
+ IntPtr pvAspect,
+ [In] IntPtr ptd,
+ IntPtr hdcTargetDev,
+ IntPtr hdcDraw,
+ [MarshalAs(UnmanagedType.Struct)] ref Rectangle lprcBounds,
+ [MarshalAs(UnmanagedType.Struct)] ref Rectangle lprcWBounds,
+ IntPtr pfnContinue,
+ [MarshalAs(UnmanagedType.U4)] UInt32 dwContinue);
+ [PreserveSig]
+ int GetColorSet([In, MarshalAs(UnmanagedType.U4)] int dwDrawAspect,
+ int lindex, IntPtr pvAspect, [In] IntPtr ptd,
+ IntPtr hicTargetDev, [Out] IntPtr ppColorSet);
+ [PreserveSig]
+ int Freeze([In, MarshalAs(UnmanagedType.U4)] int dwDrawAspect,
+ int lindex, IntPtr pvAspect, [Out] IntPtr pdwFreeze);
+ [PreserveSig]
+ int Unfreeze([In, MarshalAs(UnmanagedType.U4)] int dwFreeze);
+ void SetAdvise([In, MarshalAs(UnmanagedType.U4)] int aspects,
+ [In, MarshalAs(UnmanagedType.U4)] int advf,
+ [In, MarshalAs(UnmanagedType.Interface)] IAdviseSink pAdvSink);
+ void GetAdvise([In, Out, MarshalAs(UnmanagedType.LPArray)] int[] paspects,
+ [In, Out, MarshalAs(UnmanagedType.LPArray)] int[] advf,
+ [In, Out, MarshalAs(UnmanagedType.LPArray)] IAdviseSink[] pAdvSink);
+ }
+}
@@ -0,0 +1,9 @@
+<Window x:Class="StackOverflowWPF.MainWindow"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ Title="MainWindow" Height="728" Width="839" Loaded="Window_Loaded">
+ <Grid>
+ <Image Height="600" Name="image1" Width="800" />
+ <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="8,12,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
+ </Grid>
+</Window>
@@ -0,0 +1,66 @@
+using System;
+using System.Collections.Generic;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+using System.Runtime.InteropServices;
+using System.IO;
+
+namespace StackOverflowWPF
+{
+ /// <summary>
+ /// Interaction logic for MainWindow.xaml
+ /// </summary>
+ public partial class MainWindow : Window
+ {
+ private List<System.Drawing.Image> images = new List<System.Drawing.Image>();
+ private int currImage = 0;
+
+ public MainWindow()
+ {
+ InitializeComponent();
+ }
+
+ private void Window_Loaded(object sender, RoutedEventArgs e)
+ {
+ button1.IsEnabled = false;
+
+ HtmlPaginator pagr = new HtmlPaginator();
+ pagr.PageReady += new EventHandler<HtmlPaginator.PageImageEventArgs>(pagr_PageReady);
+ //pagr.GeneratePages(StackOverflowWPF.Properties.Resources.bigHtmlString);
+ pagr.GeneratePages("http://www.stackoverflow.com");
+ }
+
+ void pagr_PageReady(object sender, HtmlPaginator.PageImageEventArgs e)
+ {
+ images.Add(e.PageImage);
+ button1.IsEnabled = true;
+ }
+
+ private void button1_Click(object sender, RoutedEventArgs e)
+ {
+ if (currImage >= images.Count)
+ {
+ currImage = 0;
+ }
+
+ MemoryStream ms = new MemoryStream();
+ images[currImage].Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
+
+ BitmapImage bitmap = new BitmapImage();
+ bitmap.BeginInit();
+ bitmap.StreamSource = new MemoryStream(ms.ToArray());
+ bitmap.EndInit();
+
+ image1.Source = bitmap;
+
+ currImage += 1;
+ }
+ }
+}
@@ -0,0 +1,55 @@
+using System.Reflection;
+using System.Resources;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using System.Windows;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("StackOverflowWPF")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("StackOverflowWPF")]
+[assembly: AssemblyCopyright("Copyright © 2011")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+//In order to begin building localizable applications, set
+//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
+//inside a <PropertyGroup>. For example, if you are using US english
+//in your source files, set the <UICulture> to en-US. Then uncomment
+//the NeutralResourceLanguage attribute below. Update the "en-US" in
+//the line below to match the UICulture setting in the project file.
+
+//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
+
+
+[assembly: ThemeInfo(
+ ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
+ //(used if a resource is not found in the page,
+ // or application resource dictionaries)
+ ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
+ //(used if a resource is not found in the page,
+ // app, or any theme specific resource dictionaries)
+)]
+
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 3bebb0e

Please sign in to comment.