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

UE5 运行时捕捉外部窗口并嵌入到主窗口

UE5 运行时捕捉外部窗口并嵌入到主窗口的一种方法

创建一个Slate类用于生成一个窗口

.h// Fill out your copyright notice in the Description page of Project Settings.#pragma once#include "CoreMinimal.h"
#include "Widgets/SCompoundWidget.h"/*** */
class NEWWINDOWTEST0822_API SCreateNewWindow : public SCompoundWidget
{
public:SLATE_BEGIN_ARGS(SCreateNewWindow){}SLATE_END_ARGS()/** Constructs this widget with InArgs */void Construct(const FArguments& InArgs);static void CreateAAA();
};
.cpp// Fill out your copyright notice in the Description page of Project Settings.#include "SCreateNewWindow.h"
#include "SlateOptMacros.h"BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION
void SCreateNewWindow::Construct(const FArguments& InArgs)
{/*ChildSlot[// Populate the widget];*/
}void SCreateNewWindow::CreateAAA()
{TSharedPtr<SWindow> NewWin = SNew(SWindow).ClientSize(FVector2D(800,600)).Title(FText::FromString(TEXT("AAAAA")));FSlateApplication::Get().AddWindow(NewWin.ToSharedRef());
}END_SLATE_FUNCTION_BUILD_OPTIMIZATION

创建一个Actor类,用于调用Slate类中的方法

.h// Fill out your copyright notice in the Description page of Project Settings.#pragma once#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "MyActor.generated.h"UCLASS()
class NEWWINDOWTEST0822_API AMyActor : public AActor
{GENERATED_BODY()public:	// Sets default values for this actor's propertiesAMyActor();protected:// Called when the game starts or when spawnedvirtual void BeginPlay() override;public:	// Called every framevirtual void Tick(float DeltaTime) override;UFUNCTION(BlueprintCallable,Category = "Function")static void SpawnWindow();UFUNCTION(BlueprintCallable,Category = "Function")static void findAAA(FString AAAname);static void OnMainWindowClosed();};
.cpp// Fill out your copyright notice in the Description page of Project Settings.#include "MyActor.h"
#include "Windows/AllowWindowsPlatformTypes.h"
#include "SCreateNewWindow.h"FDelegateHandle MainWindowClosedHandle; // 用于存储主窗口关闭事件的句柄
HWND OtherWindowHandle = nullptr; // 嵌入的子窗口句柄
// Sets default values
AMyActor::AMyActor()
{// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.PrimaryActorTick.bCanEverTick = true;}// Called when the game starts or when spawned
void AMyActor::BeginPlay()
{Super::BeginPlay();}// Called every frame
void AMyActor::Tick(float DeltaTime)
{Super::Tick(DeltaTime);}void AMyActor::SpawnWindow()
{SCreateNewWindow::CreateAAA();
}void AMyActor::findAAA(FString AAAname)
{void* winhandle = GEngine->GameViewport->GetWindow()->GetNativeWindow()->GetOSWindowHandle();//static_cast 一个类型转换运算符,用于进行静态类型转换。它可以用来将一个数据类型转换为另一个数据类型HWND MainWindowHwnd = static_cast<HWND>(winhandle);if (MainWindowHwnd){const WCHAR* WindowName = *AAAname;HWND otherWindow = FindWindowW(NULL, WindowName);SetWindowPos(otherWindow, NULL, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOZORDER);LONG style = GetWindowLong(otherWindow, GWL_STYLE);SetWindowLong(otherWindow, GWL_STYLE, style | WS_OVERLAPPEDWINDOW);SetParent(otherWindow,MainWindowHwnd);OtherWindowHandle = otherWindow;// 存储嵌入的子窗口句柄OtherWindowHandle = otherWindow;// 注册主窗口关闭事件//MainWindowClosedHandle = FCoreDelegates::OnPreExit.AddUObject(this, &AMyActor::OnMainWindowClosed);MainWindowClosedHandle = FCoreDelegates::OnPreExit.AddStatic(&AMyActor::OnMainWindowClosed);}}void AMyActor::OnMainWindowClosed()
{if (OtherWindowHandle){DestroyWindow(OtherWindowHandle);}// 取消主窗口关闭事件的注册FCoreDelegates::OnPreExit.Remove(MainWindowClosedHandle);
}

http://www.lryc.cn/news/137164.html

相关文章:

  • uniapp 使用permission获取录音权限
  • 基于paddleocr的文档识别
  • 魏副业而战:闲鱼卖货赚钱策略
  • 语法篇--XML数据传输格式
  • 【Redis】缓存雪崩、缓存击穿、缓存穿透
  • 通过示例学习 JavaScript 运算符 - 逻辑、比较、三元和更多 JS 运算符
  • 基于微信小程序+Springboot校园二手商城系统设计和实现
  • excel 动态表头与合并列
  • jenkins自动部署微服务到docker
  • 【蔚来汽车】蔚来20220713第三题-旅游规划 <模拟、滑动窗口>
  • [解决方案]Antd TreeSelect/Select placeholder失效
  • 微人事 部门管理 模块 (十五)
  • 【Terraform学习】使用 Terraform 从 EC2 实例访问 S3 存储桶(Terraform-AWS最佳实战学习)
  • ZDRE6VP4-1X/50MG24K4V比例压力阀放大器
  • 纠缠辅助的量子网络:原理、技术、发展与挑战
  • React Native 可触摸组件基础知识
  • 用户、权限和Vim编辑器
  • git版本管理加合并笔记
  • Failed to load property source from location ‘classpath:/application.yml‘
  • Ajax复习
  • 里式替换原则(LSP)
  • mysql------做主从复制,读写分离
  • Anaconda虚拟环境跨系统迁移
  • 第四章 IRIS 编程简介 - Macros
  • 大厂考核重点:mysql索引面试题
  • MySQL使用binlog日志做数据恢复
  • USB Type-C端口集成式ESD静电保护方案 安全低成本
  • Shiro学习总结
  • AS中回退git历史版本并删除历史提交记录
  • 线性代数的学习和整理5: 矩阵的加减乘除及其几何意义