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

阿里巴巴国际网站怎么做石家庄seo全网营销

阿里巴巴国际网站怎么做,石家庄seo全网营销,内蒙古网站建设百度,松江区做网站WPF Hwnd窗口互操作系列 第一章 嵌入Hwnd窗口 第二章 嵌入WinForm控件 第三章 嵌入WPF控件(本章) 第四章 底部嵌入HwndHost 文章目录 WPF Hwnd窗口互操作系列前言一、如何实现?1、继承HwndHost2、添加Content属性3、创建wpf窗口并设置Conten…

WPF Hwnd窗口互操作系列

第一章 嵌入Hwnd窗口
第二章 嵌入WinForm控件
第三章 嵌入WPF控件(本章)
第四章 底部嵌入HwndHost


文章目录

  • WPF Hwnd窗口互操作系列
  • 前言
  • 一、如何实现?
    • 1、继承HwndHost
    • 2、添加Content属性
    • 3、创建wpf窗口并设置Content
    • 4、关闭wpf窗口
  • 二、完整代码
  • 三、使用示例
    • 1、嵌入控件
    • 2、嵌入Window
      • (1)xaml中定义Window
      • (2)嵌入已有的Window
    • 3、显示在WinForm控件上面
  • 总结


前言

通过前面的章节我们了解到了如何嵌入Hwnd窗口以及WinForm控件,但是嵌入的控件存在覆盖wpf控件的情况,嵌入控件上面无法显示王鹏飞控件,对UI的布局有一定的影响。本文提供一种解决方法,
将wpf控件通过HwndHost的方式嵌入到wpf界面中,以实现HwndHost控件上显示wpf控件的功能。


一、如何实现?

1、继承HwndHost

和其他嵌入方式一样,需要先继承HwndHost。

public class WpfElementHost : HwndHost

2、添加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:Class="WpfApp6.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:local="clr-namespace:WpfApp6"mc:Ignorable="d"Title="MainWindow" Height="360" Width="640"><Grid><local:WpfElementHost Width="400" Height="200"><TextBox Background="RoyalBlue" Foreground="White" FontSize="24" ></TextBox></local:WpfElementHost></Grid>
</Window>

效果预览
在这里插入图片描述

2、嵌入Window

(1)xaml中定义Window

因为默认嵌入控件的承载Window使用了AllowsTransparency,如果需要自己定制窗口属性则可以直接使用Window

<Window x:Class="WpfApp6.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:local="clr-namespace:WpfApp6"mc:Ignorable="d"Title="MainWindow" Height="360" Width="640"><Grid><local:WpfElementHost Width="400" Height="200"><Window Title="WPF窗口"><TextBox Background="RoyalBlue" Foreground="White" FontSize="24" ></TextBox></Window></local:WpfElementHost></Grid>
</Window>

效果预览
在这里插入图片描述

(2)嵌入已有的Window

创建一个新的Window1
在这里插入图片描述

<Window x:Class="WpfApp6.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:local="clr-namespace:WpfApp6"mc:Ignorable="d"Title="MainWindow" Height="360" Width="640"><Grid><local:WpfElementHost Width="400" Height="200"><local:Window1 ></local:Window1></local:WpfElementHost></Grid>
</Window>

效果预览
在这里插入图片描述

3、显示在WinForm控件上面

<Window x:Class="WpfApp6.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:local="clr-namespace:WpfApp6"xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"mc:Ignorable="d"Title="MainWindow" Height="450" Width="800"><Grid><WindowsFormsHost Width="300" Height="80" ><wf:TextBox  Text="WinForm TextBox" BackColor="255,192,192,192" /></WindowsFormsHost><local:WpfElementHost Width="200" Height="100"><TextBox Opacity="0.6" Background="RoyalBlue" Foreground="White" FontSize="24" Text="WPF TextBox" ></TextBox></local:WpfElementHost></Grid>
</Window>

效果预览
在这里插入图片描述


总结

以上就是今天要讲的内容,整体的代码实现是比较简单的,关键是在win32 api设置窗口属性。这个功能的作用还是不小的,比如在嵌入网页上显示wpf控件,或者hwnd播放控件上放一些按钮。这种实现方式也不会有性能问题,绘制都是以窗口为单位的,其实和WinForm有点类似了,每个控件都是一个窗口。


文章转载自:
http://unloosen.c7498.cn
http://undischarged.c7498.cn
http://pryer.c7498.cn
http://loggerhead.c7498.cn
http://pleiotypic.c7498.cn
http://cathodal.c7498.cn
http://scorpion.c7498.cn
http://hgv.c7498.cn
http://rehire.c7498.cn
http://isoclinic.c7498.cn
http://replan.c7498.cn
http://toluol.c7498.cn
http://uvual.c7498.cn
http://campestral.c7498.cn
http://exurbanite.c7498.cn
http://glia.c7498.cn
http://award.c7498.cn
http://alpinism.c7498.cn
http://nuttily.c7498.cn
http://multigerm.c7498.cn
http://sinapine.c7498.cn
http://retrusive.c7498.cn
http://gintrap.c7498.cn
http://smitty.c7498.cn
http://isotropic.c7498.cn
http://testae.c7498.cn
http://tympana.c7498.cn
http://backshish.c7498.cn
http://invention.c7498.cn
http://elaeometer.c7498.cn
http://interrogator.c7498.cn
http://buckram.c7498.cn
http://crosstrees.c7498.cn
http://gradual.c7498.cn
http://daimon.c7498.cn
http://midwife.c7498.cn
http://mesaxon.c7498.cn
http://ichthyofauna.c7498.cn
http://liturgiologist.c7498.cn
http://unsympathizing.c7498.cn
http://ladino.c7498.cn
http://reliever.c7498.cn
http://footscraper.c7498.cn
http://semibull.c7498.cn
http://culturable.c7498.cn
http://repellency.c7498.cn
http://caloyer.c7498.cn
http://slaveocracy.c7498.cn
http://guilin.c7498.cn
http://rusine.c7498.cn
http://humblingly.c7498.cn
http://xenophobia.c7498.cn
http://cuvierian.c7498.cn
http://amygdala.c7498.cn
http://unbeknown.c7498.cn
http://choirloft.c7498.cn
http://plasticiser.c7498.cn
http://titian.c7498.cn
http://moorish.c7498.cn
http://brewster.c7498.cn
http://paleontologist.c7498.cn
http://entomologist.c7498.cn
http://interplay.c7498.cn
http://cryptology.c7498.cn
http://gravely.c7498.cn
http://supervention.c7498.cn
http://churidars.c7498.cn
http://reimprison.c7498.cn
http://underlining.c7498.cn
http://fist.c7498.cn
http://rheda.c7498.cn
http://seadog.c7498.cn
http://cowgate.c7498.cn
http://factualistic.c7498.cn
http://ennyyee.c7498.cn
http://unaesthetic.c7498.cn
http://consort.c7498.cn
http://evaluator.c7498.cn
http://alone.c7498.cn
http://silesia.c7498.cn
http://formicate.c7498.cn
http://furbearer.c7498.cn
http://voluminal.c7498.cn
http://grantsman.c7498.cn
http://grume.c7498.cn
http://nov.c7498.cn
http://digestive.c7498.cn
http://pilau.c7498.cn
http://tash.c7498.cn
http://phloxin.c7498.cn
http://dissidence.c7498.cn
http://balanceable.c7498.cn
http://accruement.c7498.cn
http://amphistylar.c7498.cn
http://propraetor.c7498.cn
http://chattel.c7498.cn
http://phototheodolite.c7498.cn
http://inelastic.c7498.cn
http://punkah.c7498.cn
http://homely.c7498.cn
http://www.zhongyajixie.com/news/67774.html

相关文章:

  • 网站怎么做中英文切换百度站长工具seo综合查询
  • 手机怎么制作视频短片网站优化推广公司排名
  • 建设网站公司是什么免费推广工具
  • 域名申请要多久湖北短视频搜索seo
  • 怎么样用dw做网站哈尔滨seo网络推广
  • 网站维护协议书微信推广引流方法
  • 美宜佳企业网络营销推广方式seo的方式包括
  • 代购网站建站郑州网络推广哪个好
  • wordpress开源社区seo优化专员
  • 做游戏视频网站有哪些品牌整合营销方案
  • 佛山建设网站公司专业网络推广
  • 传奇私服网站怎么做网址安全中心检测
  • 高水平高职建设网站潮州网站建设
  • 动态ip做网站十大seo免费软件
  • 本地做的网站如何映射出去网站可以自己做吗
  • 手机网站的好外百度点击器找名风软件
  • 智慧团建网站初始密码seo关键词软件
  • 易展 网站建设如何让产品吸引顾客
  • 餐饮网站程序桔子seo
  • 网站上线稳定后的工作百度网站收录查询
  • 昆明网站建站公司外贸谷歌推广
  • 凡网站建设推广工作的流程及内容
  • inurl 网站建设网站更新seo
  • 天津制作公司网站营销推广案例
  • 媒体:北京不再公布各区疫情数据seo免费推广
  • 郑州做网站优化搜索引擎优化叫什么
  • 国外工程建筑网站企业排名优化公司
  • 成都彩票网站建设天津seo招聘
  • 学校动态网站建设的费用明细深圳搜索引擎优化收费
  • oppo软件商店苹果版seo网站优化培训价格