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

青岛响应式网站建设华为手机软文范文300

青岛响应式网站建设,华为手机软文范文300,用dreamware做网站,有哪些平台可以免费发广告WPF Hwnd窗口互操作系列 第一章 嵌入Hwnd窗口#xff08;本章#xff09; 第二章 嵌入WinForm控件 第三章 嵌入WPF控件 文章目录 WPF Hwnd窗口互操作系列前言一、如何实现1、继承HwndHost2、实现抽象方法3、xaml中使用HwndHost控件 二、具体实现1、Win32窗口2、HwndSource窗…WPF Hwnd窗口互操作系列 第一章 嵌入Hwnd窗口本章 第二章 嵌入WinForm控件 第三章 嵌入WPF控件 文章目录 WPF Hwnd窗口互操作系列前言一、如何实现1、继承HwndHost2、实现抽象方法3、xaml中使用HwndHost控件 二、具体实现1、Win32窗口2、HwndSource窗口3、Wpf窗口 三、使用示例总结 前言 wpf是Direct UI窗口中只有一个hwnd句柄大部分控件都是直接在上面绘制的。当我们需要使用不同的渲染方式进行绘制时就会和控件绘制产生冲突。比如使用opengl渲染3d图形或者视频时直接在窗口绘制就会出现闪烁与控件相互覆盖。要解决这个问题就需要添加一个新的hwnd窗口或控件嵌入wpf窗口中我们可以通过HwndHost就可以实现这样的功能。 一、如何实现 1、继承HwndHost public class MyWindowHost : HwndHost2、实现抽象方法 只需实现下列2个方法 protected override HandleRef BuildWindowCore(HandleRef hwndParent) {Handle 创建的窗口句柄return new HandleRef(this, Handle); }protected override void DestroyWindowCore(HandleRef hwnd) {hwnd.Handle;根据句柄销毁窗口 }3、xaml中使用HwndHost控件 local:MyWindowHost Width100 Height100 /local:MyWindowHost 二、具体实现 1、Win32窗口 我们可以通过win32 api创建一个窗口封装成HwndHost对象提供给xaml使用。 Win32WindowHost.cs using System.Runtime.InteropServices; using System.Windows; using System.Windows.Interop; namespace WpfHwndElement {/// summary/// 直接通过win32 api创建窗口/// /summarypublic class Win32WindowHost : HwndHost{//重新定义Handle为依赖属性可以用于绑定new public IntPtr Handle{get { return (IntPtr)GetValue(HandleProperty); }private set { SetValue(HandleProperty, value); }}// Using a DependencyProperty as the backing store for Hwnd. This enables animation, styling, binding, etc...public static readonly DependencyProperty HandleProperty DependencyProperty.Register(Handle, typeof(IntPtr), typeof(Win32WindowHost), new PropertyMetadata(IntPtr.Zero));protected override HandleRef BuildWindowCore(HandleRef hwndParent){Handle CreateWindowEx(0, static, , WS_CHILD | WS_VISIBLE | LBS_NOTIFY | WS_CLIPSIBLINGS, 0, 0, (int)Width, (int)Height, hwndParent.Handle, IntPtr.Zero, IntPtr.Zero, 0);return new HandleRef(this, Handle);}[DllImport(user32.dll, SetLastError true)]static extern System.IntPtr DefWindowProcW(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam);protected override void DestroyWindowCore(HandleRef hwnd){DestroyWindow(hwnd.Handle);}const int WS_CHILD 0x40000000;const int WS_VISIBLE 0x10000000;const int LBS_NOTIFY 0x001;const int WS_CLIPSIBLINGS 0x04000000;[DllImport(user32.dll)]internal static extern IntPtr CreateWindowEx(int exStyle, string className, string windowName, int style, int x, int y, int width, int height, IntPtr hwndParent, IntPtr hMenu, IntPtr hInstance, [MarshalAs(UnmanagedType.AsAny)] object pvParam);[DllImport(user32.dll)]static extern bool DestroyWindow(IntPtr hwnd);} }2、HwndSource窗口 如果不想导入win32 api则可以使用HwndSource对象创建句柄窗口。 using System.Runtime.InteropServices; using System.Windows; using System.Windows.Interop;namespace WpfHwndElement {class HwndSourceHost : HwndHost{//重新定义Handle为依赖属性可以用于绑定new public IntPtr Handle{get { return (IntPtr)GetValue(HandleProperty); }private set { SetValue(HandleProperty, value); }}// Using a DependencyProperty as the backing store for Hwnd. This enables animation, styling, binding, etc...public static readonly DependencyProperty HandleProperty DependencyProperty.Register(Handle, typeof(IntPtr), typeof(HwndSourceHost), new PropertyMetadata(IntPtr.Zero));HwndSource _source;protected override HandleRef BuildWindowCore(HandleRef hwndParent){_source new HwndSource(0, WS_CHILD | WS_VISIBLE | LBS_NOTIFY| WS_CLIPSIBLINGS, 0, 0, 0, (int)Width, (int)Height, nativeHost, hwndParent.Handle);Handle _source.Handle;return new HandleRef(this, Handle);}protected override void DestroyWindowCore(HandleRef hwnd){_source.Dispose();}const int WS_CHILD 0x40000000;const int WS_VISIBLE 0x10000000;const int LBS_NOTIFY 0x001;const int WS_CLIPSIBLINGS 0x04000000;} }3、Wpf窗口 wpf窗口也可以进行嵌入但需要导入win32对窗口属性进行设置要设置WS_CHILD 以及父窗口。 using System.Runtime.InteropServices; using System.Windows; using System.Windows.Interop;namespace WpfHwndElement { //重新定义Handle为依赖属性可以用于绑定public class WpfWindowHost : HwndHost{new public IntPtr Handle{get { return (IntPtr)GetValue(HandleProperty); }private set { SetValue(HandleProperty, value); }}// Using a DependencyProperty as the backing store for Hwnd. This enables animation, styling, binding, etc...public static readonly DependencyProperty HandleProperty DependencyProperty.Register(Handle, typeof(IntPtr), typeof(WpfWindowHost), new PropertyMetadata(IntPtr.Zero));const int WS_CHILD 0x40000000;const int GWL_STYLE (-16);[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 new Window(); var hwnd new WindowInteropHelper(window).EnsureHandle();window.Show();SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) | WS_CHILD);SetParent(hwnd, hwndParent.Handle);return new HandleRef(this, hwnd);}protected override void DestroyWindowCore(HandleRef hwnd){var window HwndSource.FromHwnd(hwnd.Handle)?.RootVisual as Window;window?.Close();}} } 三、使用示例 MainWindow.xaml Window x:ClassWpfHwndElement.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:WpfHwndElementmc:IgnorabledTitleMainWindow Height360 Width640 StackPanellocal:Win32WindowHost Width100 Height100/local:HwndSourceHost Margin0,10,0,0 Width100 Height100/local:WpfWindowHost Margin0,10,0,0 Width100 Height100//StackPanel /Window效果预览 总结 以上就是今天要讲的内容通过HwndHost的方式嵌入hwnd窗口是比较简单易用的而且也为wpf实现的界面效果提供的更多的可能性当然嵌入的窗口会覆盖wpf控件虽然有解决的方法本文主要还是提供基础的HwndHost用法。
http://www.zqtcl.cn/news/352730/

相关文章:

  • 匀贵网站建设亿级别网站开发注意
  • 怎样架设网站网站优化公司推荐
  • iis网站防盗链济宁官方网站
  • 网址查询地址查询站长之家在海南注册公司需要什么条件
  • 网站开发兼职平台网站建设需要多少钱小江网页设计
  • 最专业的网站建设收费2021没封的网站有人分享吗
  • 站酷设计网站官网入口文字设计wordpress是服务器吗
  • 律师手机网站模板天津做推广的公司
  • 西安市高新区建设规划局网站织梦小说网站模板下载地址
  • 网站开发简历 自我评价网页设计报告论文
  • 如何让网站不被收录不备案 国内网站
  • 站长之家域名买天猫店铺去哪里买
  • asp.net做的网站模板下载万网x3 wordpress
  • 设计网站设计目标天津市建设工程管理总队网站
  • 网站开始怎么做上海响应式网页建设
  • 网站备案 seo免费二维码制作网站
  • 删除网站备案网站建设湖南岚鸿建设
  • 做vlogger的网站有哪些长沙网站排名技巧
  • 媒体营销平台商品seo关键词优化
  • 芜湖先锋网站两学一做wordpress菜单顶部
  • 网站策划怎么样一级域名网站如何申请
  • 烟台高端网站开发网站开发哪个公司好
  • 广州网站定制开发方案南宁网站 制作
  • php做网站需要后台吗郑州建网站十大
  • 网站跳出率是什么意思百度服务
  • 建站 discuz开发者导航
  • 有哪些网站可以做毕业设计外贸网站发外链
  • 如何使用网站模板计算机培训班有用吗
  • 本地宁波网站建设电子商务网站建设工具都有那些
  • 网站建设的基本目标免费 wordpress企业主题