当前位置: 首页 > news >正文

杭州哪家公司做网站好微信商店怎么开通

杭州哪家公司做网站好,微信商店怎么开通,seo一个月赚多少钱,建设企业银行网站WPF Hwnd窗口互操作系列 第一章 嵌入Hwnd窗口 第二章 嵌入WinForm控件 第三章 嵌入WPF控件#xff08;本章#xff09; 文章目录 WPF Hwnd窗口互操作系列前言一、如何实现#xff1f;1、继承HwndHost2、添加Content属性3、创建wpf窗口并设置Content4、关闭wpf窗口 二、完整…WPF Hwnd窗口互操作系列 第一章 嵌入Hwnd窗口 第二章 嵌入WinForm控件 第三章 嵌入WPF控件本章 文章目录 WPF Hwnd窗口互操作系列前言一、如何实现1、继承HwndHost2、添加Content属性3、创建wpf窗口并设置Content4、关闭wpf窗口 二、完整代码三、使用示例1、嵌入控件2、嵌入Window1xaml中定义Window2嵌入已有的Window 3、显示在WinForm控件上面 总结 前言 通过前面的章节我们了解到了如何嵌入Hwnd窗口以及WinForm控件但是嵌入的控件存在覆盖wpf控件的情况嵌入控件上面无法显示王鹏飞控件对UI的布局有一定的影响。本文提供一种解决方法 将wpf控件通过HwndHost的方式嵌入到wpf界面中以实现HwndHost控件上显示wpf控件的功能。 一、如何实现 1、继承HwndHost 和其他嵌入方式一样需要先继承HwndHost。 public class WpfElementHost : HwndHost2、添加Content属性 添加一个Content属性提供给xaml使用。这个Content属性就是需要嵌入的wpf控件。 [ContentProperty(Content)] public class WpfElementHost : HwndHost {public UIElement Content{get { return (UIElement)GetValue(ContentProperty); }set { SetValue(ContentProperty, value); }}public static readonly DependencyProperty ContentProperty DependencyProperty.RegisterAttached(Content, typeof(UIElement), typeof(WpfElementHost), new PropertyMetadata(null)); }3、创建wpf窗口并设置Content 实现抽象方法窗口wpf窗口这里参考第一章的嵌入wpf窗口以及给窗口设置Content属性。 protected override HandleRef BuildWindowCore(HandleRef hwndParent) {var window Content is Window ? Content as Window : new Window { WindowStyle WindowStyle.None, ResizeMode ResizeMode.NoResize, Focusable false, Width 0, Height 0, ShowInTaskbar false, ShowActivated false, Background Brushes.Transparent, Content Content, AllowsTransparency true };var hwnd new WindowInteropHelper(window).EnsureHandle();SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) | WS_CHILD);User32.SetParent(hwnd, hwndParent.Handle);window!.Show();return new HandleRef(this, hwnd); }4、关闭wpf窗口 实现抽象方法关闭窗口 protected override void DestroyWindowCore(HandleRef hwnd) {var window HwndSource.FromHwnd(hwnd.Handle)?.RootVisual as Window;window?.Close(); }二、完整代码 WpfElementHost.cs using System.Runtime.InteropServices; using System.Windows; using System.Windows.Interop; using System.Windows.Markup; using Brushes System.Windows.Media.Brushes; namespace WpfHwndElement {[ContentProperty(Content)]public class WpfElementHost : HwndHost{public UIElement Content{get { return (UIElement)GetValue(ContentProperty); }set { SetValue(ContentProperty, value); }}public static readonly DependencyProperty ContentProperty DependencyProperty.RegisterAttached(Content, typeof(UIElement), typeof(WpfElementHost), new PropertyMetadata(null));const int GWL_STYLE (-16);const int WS_CHILD 0x40000000;[DllImport(user32.dll, EntryPoint GetWindowLongW)]static extern int GetWindowLong(IntPtr hwnd, int nIndex);[DllImport(user32.dll, EntryPoint SetWindowLongW)]static extern int SetWindowLong(IntPtr hwnd, int nIndex, int dwNewLong);[DllImport(user32.dll)]public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);protected override HandleRef BuildWindowCore(HandleRef hwndParent){var window Content is Window ? Content as Window : new Window { WindowStyle WindowStyle.None, ResizeMode ResizeMode.NoResize, Focusable false, Width 0, Height 0, ShowInTaskbar false, ShowActivated false, Background Brushes.Transparent, Content Content, AllowsTransparency true };var hwnd new WindowInteropHelper(window).EnsureHandle();SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) | WS_CHILD);SetParent(hwnd, hwndParent.Handle);window!.Show();return new HandleRef(this, hwnd);}protected override void DestroyWindowCore(HandleRef hwnd){var window HwndSource.FromHwnd(hwnd.Handle)?.RootVisual as Window;window?.Close();}} }三、使用示例 1、嵌入控件 Window x:ClassWpfApp6.MainWindowxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:dhttp://schemas.microsoft.com/expression/blend/2008xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006xmlns:localclr-namespace:WpfApp6mc:IgnorabledTitleMainWindow Height360 Width640Gridlocal:WpfElementHost Width400 Height200TextBox BackgroundRoyalBlue ForegroundWhite FontSize24 /TextBox/local:WpfElementHost/Grid /Window效果预览 2、嵌入Window 1xaml中定义Window 因为默认嵌入控件的承载Window使用了AllowsTransparency如果需要自己定制窗口属性则可以直接使用Window Window x:ClassWpfApp6.MainWindowxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:dhttp://schemas.microsoft.com/expression/blend/2008xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006xmlns:localclr-namespace:WpfApp6mc:IgnorabledTitleMainWindow Height360 Width640Gridlocal:WpfElementHost Width400 Height200Window TitleWPF窗口TextBox BackgroundRoyalBlue ForegroundWhite FontSize24 /TextBox/Window/local:WpfElementHost/Grid /Window效果预览 2嵌入已有的Window 创建一个新的Window1 Window x:ClassWpfApp6.MainWindowxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:dhttp://schemas.microsoft.com/expression/blend/2008xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006xmlns:localclr-namespace:WpfApp6mc:IgnorabledTitleMainWindow Height360 Width640Gridlocal:WpfElementHost Width400 Height200local:Window1 /local:Window1/local:WpfElementHost/Grid /Window效果预览 3、显示在WinForm控件上面 Window x:ClassWpfApp6.MainWindowxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:dhttp://schemas.microsoft.com/expression/blend/2008xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006xmlns:localclr-namespace:WpfApp6xmlns:wfclr-namespace:System.Windows.Forms;assemblySystem.Windows.Formsmc:IgnorabledTitleMainWindow Height450 Width800GridWindowsFormsHost Width300 Height80 wf:TextBox TextWinForm TextBox BackColor255,192,192,192 //WindowsFormsHostlocal:WpfElementHost Width200 Height100TextBox Opacity0.6 BackgroundRoyalBlue ForegroundWhite FontSize24 TextWPF TextBox /TextBox/local:WpfElementHost/Grid /Window 效果预览 总结 以上就是今天要讲的内容整体的代码实现是比较简单的关键是在win32 api设置窗口属性。这个功能的作用还是不小的比如在嵌入网页上显示wpf控件或者hwnd播放控件上放一些按钮。这种实现方式也不会有性能问题绘制都是以窗口为单位的其实和WinForm有点类似了每个控件都是一个窗口。
http://www.zqtcl.cn/news/453206/

相关文章:

  • 河北建设厅网站衡水网站建设培训学校
  • 新网网站空间到期停了 咋续费网站营销推广应该怎么做
  • 网站建设和编辑实训报告安卓版网页制作软件
  • 网站模板框架站长资讯
  • 上海做网站哪家公司2022年国际国内重大新闻
  • 网站建设如何定位网站建设思路方向
  • 手机网站拦截怎么解除网站生成软件免费制作
  • 中国房地产网站茂名住房和城乡建设厅网站
  • 做网站销售工资怎么样网页设计是哪个专业
  • 吉林省住房城乡建设厅网站首页微商城模板包含哪些
  • 优秀个人网站案例wordpress 文章格式
  • 2019年做网站装修平面设计图的制作
  • 潍坊网站建设top淘宝客网站名
  • 怎么给网站做外链网上接效果图平台
  • 电影网站建设教程下载怎么经营团购网站
  • 做网站卖什么建设银信用卡网站首页
  • 大连市城乡建设档案馆网站网上竞价采购网站建设
  • 国际物流公司网站建设浏览器正能量网站免费图片
  • 河南做外贸网站的公司怎么做家庭网站
  • 知名营销类网站互联网软件开发是什么工作
  • 做网站前新闻录入网站模板
  • 网站域名做跳转要收费吗科技信息期刊
  • 登别的网站应怎么做网站推广广告词大全集
  • 漯河城乡建设管理局网站wordpress icon class
  • 买空间哪个网站好广州多少网络科技有限公司
  • 网站的网络推广方案营销型网站建设论文
  • 苏州做网站便宜的公司哪家好门店管理系统app
  • 学校多语言网站建设网络维护网站建设培训
  • Wordpress外贸网站搭建公司建站系统的应用场景
  • 网站推广网络推广方wordpress汉语公益