Chrome插件——一键保存网页为PDF1.0

http://blog.csdn.net/bdstjk/article/details/9208313

仿照网上的一个代码写的,地址找不到了。

将窗体,控件什么的都封装到一个类库里面了,方便以后使用。

源码下载:http://download.csdn.net/detail/bdstjk/5679651

界面效果:

窗体模板,主要是实现一个无边框窗体,并添加阴影效果。

<Style TargetType="DazzleWPF:DazzleWindow">
<Setter Property="AllowsTransparency" Value="true"/>
<Setter Property="Background" Value="Transparent"/>
<!--<Setter Property="ResizeMode" Value="CanResizeWithGrip"/>-->
<Setter Property="WindowStyle" Value="None"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="DazzleWPF:DazzleWindow">
<Grid Margin="5">
<Rectangle Fill="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" >
<Rectangle.Effect>
<DropShadowEffect BlurRadius="10" ShadowDepth="0"/>
</Rectangle.Effect>
</Rectangle>
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Padding="{TemplateBinding Margin}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
<ContentPresenter />
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

窗体类,代码也很简单,调用一下类WindowBehaviorHelper 的方法,实现缩放操作的修复,避免最大化覆盖任务栏等。

再添加一下鼠标左键按下的拖动支持。

就OK了。

    public class DazzleWindow : Window
{
public DazzleWindow()
{
this.DefaultStyleKey = typeof(DazzleWindow); //缩放,最大化修复
WindowBehaviorHelper wh = new WindowBehaviorHelper(this);
wh.RepairBehavior(); this.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(DazzleWindow_MouseLeftButtonDown);
} void DazzleWindow_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
this.DragMove();
}
}

窗体行为修复,主要代码来了:

    public class WindowBehaviorHelper
{
private const int WM_NCHITTEST = 0x0084; //测试消息
private const int WM_GETMINMAXINFO = 0x0024;//大小变化 private Window WindowTarget; //目标窗口
private int WidthCorner = 3; //拐角宽度
private int ThicknessTransparentBorder = 5; //阴影宽度
private int ThicknessBorder = 4; //边框宽度
private Point PointMouse = new Point(); //鼠标坐标
public enum HitTest : int //测试句柄
{
#region 测试句柄 HTERROR = -2,
HTTRANSPARENT = -1,
HTNOWHERE = 0,
HTCLIENT = 1,
HTCAPTION = 2,
HTSYSMENU = 3,
HTGROWBOX = 4,
HTSIZE = HTGROWBOX,
HTMENU = 5,
HTHSCROLL = 6,
HTVSCROLL = 7,
HTMINBUTTON = 8,
HTMAXBUTTON = 9,
HTLEFT = 10,
HTRIGHT = 11,
HTTOP = 12,
HTTOPLEFT = 13,
HTTOPRIGHT = 14,
HTBOTTOM = 15,
HTBOTTOMLEFT = 16,
HTBOTTOMRIGHT = 17,
HTBORDER = 18,
HTREDUCE = HTMINBUTTON,
HTZOOM = HTMAXBUTTON,
HTSIZEFIRST = HTLEFT,
HTSIZELAST = HTBOTTOMRIGHT,
HTOBJECT = 19,
HTCLOSE = 20,
HTHELP = 21 #endregion
} //构造函数
public WindowBehaviorHelper(Window window)
{
this.WindowTarget = window;
} //修复行为
public void RepairBehavior()
{
if (WindowTarget == null)
return; this.WindowTarget.SourceInitialized += delegate
{
IntPtr handle = (new WindowInteropHelper(WindowTarget)).Handle;
HwndSource hwndSource = HwndSource.FromHwnd(handle);
if (hwndSource != null)
{
hwndSource.AddHook(WindowProc);
}
};
} //消息循环
private IntPtr WindowProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
switch (msg)
{
case WM_NCHITTEST: if (WindowTarget.WindowState != WindowState.Normal)
{
break;
} this.PointMouse.X = (lParam.ToInt32() & 0xFFFF);
this.PointMouse.Y = (lParam.ToInt32() >> 16); //窗口左上角
if (this.PointMouse.X > this.WindowTarget.Left + this.ThicknessTransparentBorder
&& this.PointMouse.X <= this.WindowTarget.Left + this.ThicknessTransparentBorder + this.WidthCorner
&& this.PointMouse.Y > this.WindowTarget.Top + this.ThicknessTransparentBorder
&& this.PointMouse.Y <= this.WindowTarget.Top + this.ThicknessTransparentBorder + this.WidthCorner)
{
handled = true;
return new IntPtr((int)HitTest.HTTOPLEFT);
}
//窗口左下角
else if (this.PointMouse.X > this.WindowTarget.Left + this.ThicknessTransparentBorder
&& this.PointMouse.X <= this.WindowTarget.Left + this.ThicknessTransparentBorder + this.WidthCorner
&& this.PointMouse.Y < this.WindowTarget.Top + this.WindowTarget.ActualHeight - this.ThicknessTransparentBorder
&& this.PointMouse.Y >= this.WindowTarget.Top + this.WindowTarget.ActualHeight - this.ThicknessTransparentBorder - this.WidthCorner)
{
handled = true;
return new IntPtr((int)HitTest.HTBOTTOMLEFT);
}
//窗口右上角
else if (this.PointMouse.X < this.WindowTarget.Left + this.WindowTarget.ActualWidth - this.ThicknessTransparentBorder
&& this.PointMouse.X >= this.WindowTarget.Left + this.WindowTarget.ActualWidth - this.ThicknessTransparentBorder - this.WidthCorner
&& this.PointMouse.Y > this.WindowTarget.Top + this.ThicknessTransparentBorder
&& this.PointMouse.Y <= this.WindowTarget.Top + this.ThicknessTransparentBorder + this.WidthCorner)
{
handled = true;
return new IntPtr((int)HitTest.HTTOPRIGHT);
}
//窗口右下角
else if (this.PointMouse.X < this.WindowTarget.Left + this.WindowTarget.ActualWidth - this.ThicknessTransparentBorder
&& this.PointMouse.X >= this.WindowTarget.Left + this.WindowTarget.ActualWidth - this.ThicknessTransparentBorder - this.WidthCorner
&& this.PointMouse.Y < this.WindowTarget.Top + this.WindowTarget.ActualHeight - this.ThicknessTransparentBorder
&& this.PointMouse.Y >= this.WindowTarget.Top + this.WindowTarget.ActualHeight - this.ThicknessTransparentBorder - this.WidthCorner)
{
handled = true;
return new IntPtr((int)HitTest.HTBOTTOMRIGHT);
}
//窗口左侧
else if (this.PointMouse.X > this.WindowTarget.Left + this.ThicknessTransparentBorder
&& this.PointMouse.X <= this.WindowTarget.Left + this.ThicknessTransparentBorder + this.ThicknessBorder
&& this.PointMouse.Y > this.WindowTarget.Top + this.ThicknessTransparentBorder
&& this.PointMouse.Y < this.WindowTarget.Top + this.WindowTarget.ActualHeight - this.ThicknessTransparentBorder)
{
handled = true;
return new IntPtr((int)HitTest.HTLEFT);
}
//窗口右侧
else if (this.PointMouse.X < this.WindowTarget.Left + this.WindowTarget.ActualWidth - this.ThicknessTransparentBorder
&& this.PointMouse.X >= this.WindowTarget.Left + this.WindowTarget.ActualWidth - this.ThicknessTransparentBorder - this.ThicknessBorder
&& this.PointMouse.Y > this.WindowTarget.Top + this.ThicknessTransparentBorder
&& this.PointMouse.Y < this.WindowTarget.Top + this.WindowTarget.ActualHeight - this.ThicknessTransparentBorder)
{
handled = true;
return new IntPtr((int)HitTest.HTRIGHT);
}
//窗口上方
else if (this.PointMouse.X > this.WindowTarget.Left + this.ThicknessTransparentBorder
&& this.PointMouse.X < this.WindowTarget.Left + this.WindowTarget.ActualWidth - this.ThicknessTransparentBorder
&& this.PointMouse.Y > this.WindowTarget.Top + this.ThicknessTransparentBorder
&& this.PointMouse.Y <= this.WindowTarget.Top + this.ThicknessTransparentBorder + this.ThicknessBorder)
{
handled = true;
return new IntPtr((int)HitTest.HTTOP);
}
//窗口下方
else if (this.PointMouse.X > this.WindowTarget.Left + this.ThicknessTransparentBorder
&& this.PointMouse.X < this.WindowTarget.Left + this.WindowTarget.ActualWidth - this.ThicknessTransparentBorder
&& this.PointMouse.Y < this.WindowTarget.Top + this.WindowTarget.ActualHeight - this.ThicknessTransparentBorder
&& this.PointMouse.Y >= this.WindowTarget.Top + this.WindowTarget.ActualHeight - this.ThicknessTransparentBorder - this.ThicknessBorder)
{
handled = true;
return new IntPtr((int)HitTest.HTBOTTOM);
}
//其他消息
else
{
break;
} case WM_GETMINMAXINFO:
WmGetMinMaxInfo(hwnd, lParam);
handled = true;
break; default:
break;
}
return IntPtr.Zero;
} //更改最小化最大化时窗口位置大小
private void WmGetMinMaxInfo(IntPtr hwnd, IntPtr lParam)
{
MINMAXINFO mmi = (MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(MINMAXINFO)); int MONITOR_DEFAULTTONEAREST = 0x00000002;
IntPtr monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST); if (monitor != IntPtr.Zero)
{
MONITORINFO monitorInfo = new MONITORINFO();
GetMonitorInfo(monitor, monitorInfo);
RECT rcWorkArea = monitorInfo.rcWork;
RECT rcMonitorArea = monitorInfo.rcMonitor;
mmi.ptMaxPosition.x = Math.Abs(rcWorkArea.left - rcMonitorArea.left) - 3;
mmi.ptMaxPosition.y = Math.Abs(rcWorkArea.top - rcMonitorArea.top) - 3;
mmi.ptMaxSize.x = Math.Abs(rcWorkArea.right - rcWorkArea.left) + 6;
mmi.ptMaxSize.y = Math.Abs(rcWorkArea.bottom - rcWorkArea.top) + 6;
mmi.ptMinTrackSize.x = (int)this.WindowTarget.MinWidth;
mmi.ptMinTrackSize.y = (int)this.WindowTarget.MinHeight;
} Marshal.StructureToPtr(mmi, lParam, true);
} [DllImport("user32")]
internal static extern bool GetMonitorInfo(IntPtr hMonitor, MONITORINFO lpmi);
[DllImport("User32")]
internal static extern IntPtr MonitorFromWindow(IntPtr handle, int flags); #region Nested type: MINMAXINFO
[StructLayout(LayoutKind.Sequential)]
internal struct MINMAXINFO
{
public POINT ptReserved;
public POINT ptMaxSize;
public POINT ptMaxPosition;
public POINT ptMinTrackSize;
public POINT ptMaxTrackSize;
}
#endregion #region Nested type: MONITORINFO
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
internal class MONITORINFO
{
public int cbSize = Marshal.SizeOf(typeof(MONITORINFO));
public RECT rcMonitor;
public RECT rcWork;
public int dwFlags;
}
#endregion #region Nested type: POINT
[StructLayout(LayoutKind.Sequential)]
internal struct POINT
{
public int x;
public int y;
public POINT(int x, int y)
{
this.x = x;
this.y = y;
}
}
#endregion #region Nested type: RECT
[StructLayout(LayoutKind.Sequential, Pack = 0)]
internal struct RECT
{
public int left;
public int top;
public int right;
public int bottom; public static readonly RECT Empty; public int Width
{
get { return Math.Abs(right - left); }
}
public int Height
{
get { return bottom - top; }
} public RECT(int left, int top, int right, int bottom)
{
this.left = left;
this.top = top;
this.right = right;
this.bottom = bottom;
} public RECT(RECT rcSrc)
{
left = rcSrc.left;
top = rcSrc.top;
right = rcSrc.right;
bottom = rcSrc.bottom;
} public bool IsEmpty
{
get
{
return left >= right || top >= bottom;
}
} public override string ToString()
{
if (this == Empty)
{
return "RECT {Empty}";
}
return "RECT { left : " + left + " / top : " + top + " / right : " + right + " / bottom : " + bottom + " }";
} public override bool Equals(object obj)
{
if (!(obj is Rect))
{
return false;
}
return (this == (RECT)obj);
} public override int GetHashCode()
{
return left.GetHashCode() + top.GetHashCode() + right.GetHashCode() + bottom.GetHashCode();
} public static bool operator ==(RECT rect1, RECT rect2)
{
return (rect1.left == rect2.left && rect1.top == rect2.top && rect1.right == rect2.right && rect1.bottom == rect2.bottom);
} public static bool operator !=(RECT rect1, RECT rect2)
{
return !(rect1 == rect2);
}
}
#endregion
}

WPF仿360卫士9.0界面设计的更多相关文章

  1. C# WPF仿360安全卫士11

    首先上效果图: 这是我的第一篇随笔,最近因为写一个播放器,开始学习WPF相关技术,随着不断入坑,播放器倒是做出来了,掉坑里了... 本着闲着也是闲着的精神,拿360开刀了: 主界面主要使用DMSkin ...

  2. android开发之-Android 开发之4.0界面设计原则-整理

    设计原则: 一.让人着迷: 1.给人惊喜:使用漂亮的界面.精心的动画.适时的音乐. 2.真实的对象比按钮和菜单更有趣   这句话的意思是:使用描述描述性的图标作为快捷方式,界面美观   当然这个快捷方 ...

  3. Qt实现360安全卫士10.0界面(编译时出现的一些问题)

    http://www.qtcn.org/bbs/read-htm-tid-57817.html 源码下载:https://git.oschina.net/zhjun5337/Qt360-10.0  或 ...

  4. DELPHI实现类似仿360桌面的程序界面

    1.窗体半透明: Alphablend属性为true;Alphablendvalue的值为100 2.窗体透明: formCreate: Self.TransparentColor := True;S ...

  5. WPF界面设计

    WPF仿360卫士9.0界面设计   Chrome插件——一键保存网页为PDF1.0 http://www.cnblogs.com/bdstjk/p/3163723.html 仿照网上的一个代码写的, ...

  6. 仿360手机卫士界面效果android版源码

    仿360手机卫士界面效果android版,这个今天一大早在源码天堂的那个网站上看到了一个那个网站最新更新的一个源码,所以就分享给大学习一下吧,布局还挺不错的,而且也很简单的,我就不把我修改的那个分享出 ...

  7. 基于WPF系统框架设计(5)-Ribbon整合Avalondock 2.0实现多文档界面设计(二)

    AvalonDock 是一个.NET库,用于在停靠模式布局(docking)中排列一系列WPF/WinForm控件.最新发布的版本原生支持MVVM框架.Aero Snap特效并具有更好的性能. Ava ...

  8. WPF界面设计技巧(3)—实现不规则动画按钮

    原文:WPF界面设计技巧(3)-实现不规则动画按钮 发布了定义WPF按钮的教程后,有朋友问能否实现不规则形状的按钮,今天我们就来讲一下不规则按钮的制作. 不规则按钮的做法实际上和先前我们做不规则窗体的 ...

  9. WPF下的视频录制界面设计

    原文:WPF下的视频录制界面设计 在去年12月份,我曾经写过三篇文章讨论C#下视频录制.播放界面的设计.这三篇文章是:利用C#画视频录制及播放的界面(一) 利用C#画视频录制及播放的界面(二)利用C# ...

随机推荐

  1. ArcGIS 开发的一些知识学习点

    由于文章太多,不便转载,现主要列举如下: ArcGIS Runtime支持的GP工具列表 ArcGIS Runtime支持的GP工具列表 目录(?)[-] Standard版本Standard 空间分 ...

  2. HDU5800 To My Girlfriend 背包计数dp

    分析:首先定义状态dp[i][j][s1][s2]代表前i个物品中,选若干个物品,总价值为j 其中s1个物品时必选,s2物品必不选的方案数 那么转移的时候可以考虑,第i个物品是可选可可不选的 dp[i ...

  3. IOS-多视图控制器之间的切换

    1. 创建个单视图应用程序 2. 在向Main.storyboard中拖一个ViewController控制器 3. 在第一个viewController中添加一个按钮 4. 按着control键,推 ...

  4. 使用json格式的数据进行通信

    4 Java对象转换成JSON 4.1 问题 将Java对象转换成符合JSON格式的字符串,并测试. 4.2 方案 使用与json-lib.jar相关的jar文件完成类型的转换. 4.3 步骤 步骤一 ...

  5. spring初探1

    spring初探1 关于新建对象,对象依赖的三种方式比较 场景 某个交易的业务组建拆分,为原先的功能模块新写了一个业务组件 使用new. 修改上层代码的对象生成部分( 如果不是面向接口编程,简直就是灾 ...

  6. WinForm 中两个窗口之间传递数据

    方法有很多种,这里介绍项目中使用的两种 一.通过委托+事件的方法进行传值 (点击Form2中的button1按钮,将会把Form2中的textbox.text 传给Form1中的 lable.text ...

  7. vim7.4 安装 k-vim

    注:在虚拟机 kali 1.9中安装完成之后,无法连接到网络(目前没找到有效的解决方法,不知道是不是通病,本人安装了两次,都一样),cpu占用率 70%+  ,建议安装之前,先建立快照,否则,后悔莫极 ...

  8. 【Python学习笔记】with语句与上下文管理器

    with语句 上下文管理器 contextlib模块 参考引用 with语句 with语句时在Python2.6中出现的新语句.在Python2.6以前,要正确的处理涉及到异常的资源管理时,需要使用t ...

  9. ninject学习笔记一:IOC的实现

    这篇文章主要介绍ninject在IOC方面的实现,至于IOC的含义,网络资源很丰富,我这儿就不再赘述了.官方的文档其实挺好的,只是本人英语很烂,看起来比较费劲,下面这些东西是看官方的代码推敲的,我觉得 ...

  10. Hadoop入门简介

    一.Hadoop简介 1.1.Hadoop主要进行分布式存储和分布式计算 1.1-1.HDFS:分布式文件系统 1.1-2.MapReduce:并行计算框架 1.2.Hadoop用来做什么? 搭建大型 ...