- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是否正确理解 EdgeHTML 现在可用于 Windows 10 中的桌面(Win32/Win64 应用程序)?根据这些博客文章:
https://blogs.windows.com/msedgedev/2018/05/09/modern-webview-winforms-wpf-apps/ https://blogs.windows.com/msedgedev/2018/10/04/edgehtml-18-october-2018-update/ https://learn.microsoft.com/en-us/windows/communitytoolkit/controls/wpf-winforms/webview
微软似乎已经为 Windows 桌面 (Win32) 应用程序添加了 EdgeHTML WebViewControl,但迄今为止该应用程序尚未可用于桌面应用程序(只有基于 Trident 的 MSHTML 控件可用于桌面应用程序)。
如果这是真的,是否有可能在 Delphi/C++ Builder 中使用它,或者我们是否必须等待 RAD Studio 的新更新中出现新的 TWebView 控件?如果可能的话 - 是否有任何代码示例可供查看(C++ Builder 或 Delphi)? .NET 的要求是否意味着它不能在 RAD Studio 生成的常规 Win32/Win64 应用程序中使用?
最佳答案
这个答案已经过时,但了解技术背景可能会很有趣。 RAD Studio 10.4 Sydney 现在支持使用开箱即用的 Edge 浏览器。请参阅my other answer .
<小时/>WebView 控件通过 WinRT 提供,不依赖于 .net。您可以从普通的 Win32 应用程序中使用它。
WinRT(Windows 运行时)现在在 Windows 10 中更名为 UWP(通用 Windows 平台),类似于 COM 的后继者。
与 COM 一样,它很大程度上基于接口(interface),并且可用的接口(interface)是在类型库中定义的。对于 WinRT,类型库存储在 Windows 系统目录中的 *.WinMD 文件中。包含我们嵌入 Edge 浏览器所需的功能的类型库是 Windows.Web.winmd
。
Delphi 确实支持使用 WinRT 组件,并且它附带了一些类型库的翻译以及一些附加的辅助函数和类,以便与 WinRT 一起使用。
但是,目前还没有工具可以自动将 WinMD 文件或从 WinMD 文件派生的 IDL 文件转换为 Delphi 代码。如果要使用 Delphi 未附带的 WinRT 功能,则必须手动将类型定义转换为 Delphi 代码。
WinRT 大量使用与 Delphi 中通用接口(interface)的工作方式不兼容的通用接口(interface)(带有类型参数的接口(interface))。这需要在翻译类型定义时进行一些手动调整。
如果安装 Windows Platform SDK,您可以在 Drive:\Windows Kits\10\Include\10.0.17134.0\winrt
等目录中找到 WinRT 类型库的 IDL 和 C++ 翻译。
我使用这些文件作为模板来创建一个非常基本的概念验证 Delphi 项目(适用于 Delphi 10.2),该项目使用嵌入式 Edge 浏览器。您可以找到下面的代码。为了测试这一点,只需创建一个新的 VCL 项目,粘贴代码并将 FormCreate
、FormDestroy
和 FormResize
事件与表单连接起来。
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,
System.Types,
Winapi.Winrt,
System.Win.WinRT,
WinAPI.Foundation,
WinAPI.Foundation.Types;
const
SWebViewControlProcess = 'Windows.Web.UI.Interop.WebViewControlProcess';
type
// Interface with functionality to interact with WebBrowser Control
// https://learn.microsoft.com/en-us/uwp/api/windows.web.ui.iwebviewcontrol
IWebViewControl = interface(IInspectable)
['{3F921316-BC70-4BDA-9136-C94370899FAB}']
procedure Placeholder_SourceGet; safecall;
procedure Placeholder_SourcePut; safecall;
procedure Placeholder_DocumentTitle; safecall;
procedure Placeholder_CanGoBack; safecall;
procedure Placeholder_CanGoForward; safecall;
procedure Placeholder_DefaultBackgroundColorPut; safecall;
procedure Placeholder_DefaultBackgroundColorGet; safecall;
procedure Placeholder_ContainsFullScreenElement; safecall;
procedure Placeholder_Settings; safecall;
procedure Placeholder_DeferredPermissionRequests; safecall;
procedure Placeholder_GoForward; safecall;
procedure Placeholder_GoBack; safecall;
procedure Placeholder_Refresh; safecall;
procedure Placeholder_Stop; safecall;
procedure Navigate(source: IUriRuntimeClass); stdcall;
procedure NavigateToString(text: HString); stdcall;
// TODO: Declare further properties and functions of IWebViewControl
end;
IWebViewControlProcess = interface;
// Declare IWebViewControlSite
IWebViewControlSite = interface(IInspectable)
['{133F47C6-12DC-4898-BD47-04967DE648BA}']
function get_Process: IWebViewControlProcess; safecall;
procedure put_Scale(value: Double); safecall;
function get_Scale: Double; safecall;
procedure put_Bounds(value: TRectF); safecall;
function get_Bounds: TRectF; safecall;
procedure put_IsVisible(value: Boolean); safecall;
function get_IsVisible: Boolean; safecall;
// TODO: Declare further properties and functions of IWebViewControlSite
property Process: IWebViewControlProcess read get_Process;
property Scale: Double read get_Scale write put_Scale;
property Bounds: TRectF read get_Bounds write put_Bounds;
property IsVisible: Boolean read get_IsVisible write put_IsVisible;
end;
// types for reacting to when the WebView has finished initialization
IAsyncOperation_1__IWebViewControl = interface;
IAsyncOperationCompletedHandler_1__IWebViewControl = interface(IUnknown)
['{d61963d6-806d-50a8-a81c-75d9356ad5d7}']
procedure Invoke(asyncInfo: IAsyncOperation_1__IWebViewControl; asyncStatus: AsyncStatus); safecall;
end;
IAsyncOperation_1__IWebViewControl = interface(IInspectable)
['{ac3d28ac-8362-51c6-b2cc-16f3672758f1}']
procedure put_Completed(handler: IAsyncOperationCompletedHandler_1__IWebViewControl); safecall;
function get_Completed: IAsyncOperationCompletedHandler_1__IWebViewControl; safecall;
function GetResults: IWebViewControl; safecall;
property Completed: IAsyncOperationCompletedHandler_1__IWebViewControl read get_Completed write put_Completed;
end;
TWebViewControlCompleted = procedure(asyncInfo: IAsyncOperation_1__IWebViewControl; aasyncStatus: AsyncStatus) of object;
TWebViewControlCompletedHandler = class(TInspectableObject,
IAsyncOperationCompletedHandler_1__IWebViewControl
)
private
FEvent: TWebViewControlCompleted;
public
procedure Invoke(asyncInfo: IAsyncOperation_1__IWebViewControl; aasyncStatus: AsyncStatus); safecall;
constructor Create(AEvent: TWebViewControlCompleted);
end;
// The interface for interacting with the process hosting the web view control
// https://learn.microsoft.com/en-us/uwp/api/windows.web.ui.interop.webviewcontrolprocess
[WinRTClassNameAttribute(SWebViewControlProcess)]
IWebViewControlProcess = interface(IInspectable)
['{02C723EC-98D6-424A-B63E-C6136C36A0F2}']
function get_ProcessId: Cardinal; safecall;
function get_EnterpriseId: HSTRING; safecall;
function get_IsPrivateNetworkClientServerCapabilityEnabled: Boolean; safecall;
function CreateWebViewControlAsync(hostWindowHandle: Int64; bounds: TRectF): IAsyncOperation_1__IWebViewControl; safecall;
procedure Placeholder_GetWebViewControls; safecall;
procedure Terminate; safecall;
property ProcessId: Cardinal read get_ProcessId;
property EnterpriseId: HSTRING read get_EnterpriseId;
property IsPrivateNetworkClientServerCapabilityEnabled: Boolean read get_IsPrivateNetworkClientServerCapabilityEnabled;
// TODO:
//[eventadd] HRESULT ProcessExited([in] Windows.Foundation.TypedEventHandler<Windows.Web.UI.Interop.WebViewControlProcess*, IInspectable*>* handler, [out] [retval] EventRegistrationToken* token);
//[eventremove] HRESULT ProcessExited([in] EventRegistrationToken token);
end;
// The CoClass to create an IWebViewControlProcess instance
TWebViewControlProcess = class(TWinRTGenericImportI<IWebViewControlProcess>)
end;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormResize(Sender: TObject);
private
{ Private declarations }
FProcess: IWebViewControlProcess;
FBrowser: IWebViewControl;
FBrowserSite: IWebViewControlSite;
procedure WebViewCompleted(asyncInfo: IAsyncOperation_1__IWebViewControl; aasyncStatus: AsyncStatus);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
Rect: TRectF;
AsyncOperation: IAsyncOperation_1__IWebViewControl;
CompletedHandler: IAsyncOperationCompletedHandler_1__IWebViewControl;
begin
CompletedHandler:=TWebViewControlCompletedHandler.Create(WebViewCompleted);
// Size for browser
Rect:= TRectF.Create(0, 0, ClientWidth, ClientHeight);
// Create hosting process
FProcess:= TWebViewControlProcess.Create();
// Create WebView Control
AsyncOperation:= FProcess.CreateWebViewControlAsync(self.Handle, Rect);
// We will get notified when the control creation is finished
AsyncOperation.Completed:= CompletedHandler;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
// If there is a hosting process, then terminate it
if Assigned(FProcess) then
begin
FProcess.Terminate;
end;
end;
procedure TForm1.FormResize(Sender: TObject);
begin
if Assigned(FBrowserSite) then
begin
FBrowserSite.Bounds := TRectF.Create(0,0,ClientWidth, ClientHeight);
end;
end;
procedure TForm1.WebViewCompleted(
asyncInfo: IAsyncOperation_1__IWebViewControl;
aasyncStatus: AsyncStatus);
var
WinS: TWindowsString;
Uri: IUriRuntimeClass;
begin
// Initializing the WebView control was successful
// Remember reference to control
FBrowser:= asyncInfo.GetResults();
FBrowserSite := FBrowser as IWebViewControlSite;
// Load web page into control
WinS:= TWindowsString.Create('http://www.whatismybrowser.com');
Uri:= TUri.CreateUri(WinS);
FBrowser.Navigate(Uri);
end;
{ TWebViewControlCompletedHandler }
constructor TWebViewControlCompletedHandler.Create(
AEvent: TWebViewControlCompleted);
begin
FEvent := AEvent;
end;
procedure TWebViewControlCompletedHandler.Invoke(
asyncInfo: IAsyncOperation_1__IWebViewControl;
aasyncStatus: AsyncStatus);
begin
FEvent(asyncInfo, aasyncStatus);
end;
end.
关于delphi - 在 Delphi/C++ Builder 中使用 WebView (EdgeHTML),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52766249/
我正在开发一个应用程序,我成功地消除了除一个错误之外的所有错误: no suitable constructor found for builder 更改为“意图” https://file.io/O
我可以在 C++Builder 6 中成功编译以下代码片段,但我无法在 RAD Studio Seattle 中编译它: unsigned long x = 50; String s = In
我有一个项目(新开始),其中 C++ Builder 没有在任何断点处停止。我已确保我处于 Debug模式(未发布),链接器->完整调试信息 = True,C++ 编译器->调试配置,C++ 编译器-
我们想在正在开发的 C++ builder XE 应用程序中绘制大型控制流程图。 这些图表将以编程方式生成并以交互方式显示给用户(用户可以滚动大流程图、选择节点等)。节点必须能够显示自定义组件(如 T
我有以下问题 午餐时 FlashBuilder.exe (BURRITO):它崩溃并创建一个错误日志文件,例如: hs_err_pid7084.log 及以下 但是当我咀嚼 FlashBuilderC
我有一个大型 Flash Builder 项目,它是更大 (.net) 解决方案的一部分。对于整个项目,我通常有一个前进的开发分支,以及一个或多个错误修复分支。考虑到 Flash Builder 不想
乘数(自动布局中约束的属性)有什么作用? 最佳答案 约束中两个值之间的关系由以下公式确定: b = am + c 其中 a 和 b 是要关联的两个值,m 是乘数,c code> 是常量。 例如,如果
我们的开发团队使用 Borland C++ Builder 6 和 CodeGear C++ Builder 2007(以及 Visual Studio)。我听到很多评论说 Builder 2007
我想阐明我对构建器模式的使用,特别是构建器类型是如何创建的。在示例中,它只是假定构建器的类型并创建它。但是,我在“ChartBuilderFactory”类中创建了一个 CreateBuilder 方
首先,我对 Java 比较陌生,所以我问的可能是微不足道的,但我在这里或其他地方找不到答案。 为简单起见,假设我有以下类层次结构: class Shape { protected Shape(
我试图在另一个 AlertDialog 中打开一个 AlertDialog,但它不起作用,知道为什么它不起作用吗? String items[] = {"Details","Edit","Delete
我有一个包含 Form1 和 Form2 的程序。如何单击按钮从 form1 打开 form2? 最佳答案 更多信息 在你的 Project.cpp 中有这个:Application->CreateF
每当我使用 C++ Builder(XE4 版,但以前的版本也这样做)在 Release模式下构建 Win32 EXE 时,它总是创建一个导出目录并为我的项目中的每个单元导出一个 Initialize
我正在尝试在我的试用版 flashbuilder 上启用设计模式,但找不到任何选项, 我已经查看了 Windows 菜单,但没有启用设计模式, 和首选项,但首选项对话框中没有 Flex 来启用其设计模
我目前正在将一个大型 RAD Studio 2010 项目迁移到 XE4。作为其中的一部分,我正在重新创建许多项目文件。我想借此机会确保我们对预编译头使用最好的机制,因为似乎有几种方法可以做到这一点。
我观看了“Interface Builder 中的新增功能” session 视频并尝试复制显示的代码,但不幸的是,当我将 View 分配给具有 @IBDesignable 的自定义类时,出现 2 个
这个问题在这里已经有了答案: Why is NotificationCompat needed? (3 个答案) 关闭 5 年前。 我看到的几乎所有 Android 通知示例代码似乎都使用了 Not
我正在使用 fcm 从我的 Android 应用程序发送通知,并且我已经实现了它要求我提供的所有库。 val topic = "highScores" // See docum
我正在尝试在Flash Builder 4.6中进行项目范围内的查找和替换,但是对我而言,如何实现这一点并不明显。 我试过Edit-> Find/Replace然后全部替换,但它仅替换当前打开的文件中
帮助我在 XCode4 中取消 fubar 界面构建器。 我在 interface-builder 中创建了一个按钮,并在 View 的代码中为它定义了一个 IBAction 方法。它运行良好。然后我
我是一名优秀的程序员,十分优秀!