UE5C++独立窗口空白程序创建模版

Build.cs

// Copyright Epic Games, Inc. All Rights Reserved.

using UnrealBuildTool;

public class SlateWindowTest : ModuleRules
{
	public SlateWindowTest(ReadOnlyTargetRules Target) : base(Target)
	{
		PublicIncludePathModuleNames.Add("Launch");
		PrivateDependencyModuleNames.Add("Core");
		PrivateDependencyModuleNames.Add("Projects");
		
		PrivateDependencyModuleNames.Add("Slate");
		PrivateDependencyModuleNames.Add("SlateCore");
		PrivateDependencyModuleNames.Add("StandaloneRenderer");
		
		// to link with CoreUObject module:
		// PrivateDependencyModuleNames.Add("CoreUObject");

		// to enable tracing:
		// AppendStringToPublicDefinition("UE_TRACE_ENABLED", "1");

		// to enable LLM tracing:
		// GlobalDefinitions.Add("LLM_ENABLED_IN_CONFIG=1");
		// GlobalDefinitions.Add("UE_MEMORY_TAGS_TRACE_ENABLED=1");
	}
}

 Target.cs

// Copyright Epic Games, Inc. All Rights Reserved.

using UnrealBuildTool;
using System.Collections.Generic;

[SupportedPlatforms(UnrealPlatformClass.All)]
public class SlateWindowTestTarget : TargetRules
{
	public SlateWindowTestTarget(TargetInfo Target) : base(Target)
	{
		Type = TargetType.Program;
		IncludeOrderVersion = EngineIncludeOrderVersion.Latest;
		LinkType = TargetLinkType.Monolithic;
		LaunchModuleName = "SlateWindowTest";

		// Lean and mean
		bBuildDeveloperTools = false;

		// Editor-only is enabled for desktop platforms to run unit tests that depend on editor-only data
		// It's disabled in test and shipping configs to make profiling similar to the game
		bool bDebugOrDevelopment = Target.Configuration == UnrealTargetConfiguration.Debug || Target.Configuration == UnrealTargetConfiguration.Development;
		bBuildWithEditorOnlyData = Target.Platform.IsInGroup(UnrealPlatformGroup.Desktop) && bDebugOrDevelopment;

		// Currently this app is not linking against the engine, so we'll compile out references from Core to the rest of the engine
		bCompileAgainstEngine = false;
		bCompileAgainstCoreUObject = true;	// 需要使用CoreUObject模块,因为需要使用对象系统和反射机制
		bCompileAgainstApplicationCore = true;	// 需要使用ApplicationCore模块,需要使用应用程序框架和事件处理机制
		bCompileICU = false;

		// UnrealHeaderTool is a console application, not a Windows app (sets entry point to main(), instead of WinMain())
		bIsBuildingConsoleApplication = false;	// 使用WinMain()函数作为入口,因为需要绘制UI,因此关闭 console application
	}
}

.h

// Copyright Epic Games, Inc. All Rights Reserved.

#pragma once

#include "CoreMinimal.h"

#include "SlotBase.h"
#include "StandaloneRenderer.h"


.cpp

// Copyright Epic Games, Inc. All Rights Reserved.

#include "SlateWindowTest.h"

#include "RequiredProgramMainCPPInclude.h"

#include "StandaloneRenderer.h"

//定义一个日志类别
DEFINE_LOG_CATEGORY_STATIC(LogSlateWindowTest, Log, All);

//实现一个名为SlateWindowTest的应用程序
IMPLEMENT_APPLICATION(SlateWindowTest, "SlateWindowTest");

//Windows应用程序的入口点
int WINAPI WinMain( _In_ HINSTANCE hInInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR, _In_ int nCmdShow )
{
	//预初始化Unreal Engine循环,并获取命令行参数,GetCommandLineW函数检索当前进程的命令行字符串
	GEngineLoop.PreInit(GetCommandLineW());

	// 告诉模块管理器,当加载新的C++模块时,它现在可以处理新加载的UObjects
	FModuleManager::Get().StartProcessingNewlyLoadedObjects();

	// 使用平台的独立渲染器启动正常的Slate应用程序
	SlateApplication::InitializeAsStandaloneApplication(GetStandardStandaloneRenderer());

	//初始化高DPI支持
	FSlateApplication::InitHighDPI(true);
	
	//创建一个新的SWindow对象,设置窗口的客户区大小为200x200像素
	TSharedRef<SWindow> Window = SNew(SWindow)
	.ClientSize(FVector2D(800.f, 600.f))
	[
		//在窗口中放置一个空的小部件
		//SNullWidget::NullWidget
		
		//在窗口内放入图片
		SNew(SImage)
	];
	
	//将新创建的窗口添加到Slate应用程序中
	FSlateApplication::Get().AddWindow(Window);

	//IsEngineExitRequested=false, while保持窗口,=true,向下执行
	while (!IsEngineExitRequested())
	{
		//如果已请求退出,开始退出过程
		BeginExitIfRequested();

		//处理所有待处理的消息
		FSlateApplication::Get().PumpMessages();
		//更新Slate应用程序的状态
		FSlateApplication::Get().Tick();
	}
	
	//关闭并清理Slate应用程序
	FSlateApplication::Shutdown();

	//在退出之前清理操作
	GEngineLoop.AppPreExit();
	//执行最终退出操作
	GEngineLoop.AppExit();

	//结束程序,正常退出
	return 0;
}

  • 6
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我救我自己

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值