Open custom viewport in second display connection

I currently have a function to create a custom viewport and it is working, but I want to make it so this viewport opens in the window of a projector that I have connected to my laptop, does anybody know how to do this?

UFUNCTION(BlueprintCallable, Category = "Texture Processor")
void UVisualisationTextureProcessor::InitializeViewport()
{

    // Create a new Slate brush to hold the UTexture2D
    VisualisationSlateBrush = new FSlateBrush();

    // Create a Slate image widget to display the Slate brush
    TSharedRef<SImage> ImageWidget = SNew(SImage)
        .Image(VisualisationSlateBrush);

    ImageWidgetPtr = ImageWidget;

    // Create the secondary window to contain the image widget
    TSharedRef<SWindow> SecondWindow = SNew(SWindow)
        .Title(FText::FromString(TEXT("Visualisation Viewport")))
        .ClientSize(FVector2D(1920, 1080))
        .Content()
        [
            ImageWidget
        ];

    // Store a weak reference to the window
    SecondWindowPtr = SecondWindow;

    FSlateApplication::Get().AddWindow(SecondWindow);
}

Got it working if anyone ends up having a similar issue

#include <Windows.h>

BOOL CALLBACK MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData)
{
	std::vector<RECT>* monitors = reinterpret_cast<std::vector<RECT>*>(dwData);
	monitors->push_back(*lprcMonitor);
	return true;
}

UFUNCTION(BlueprintCallable, Category = "Texture Processor")
void UVisualisationTextureProcessor::InitializeViewport()
{
	std::vector<RECT> monitorRects;
	EnumDisplayMonitors(0, 0, MonitorEnumProc, reinterpret_cast<LPARAM>(&monitorRects));

	// Create a new Slate brush to hold the UTexture2D
	VisualisationSlateBrush = new FSlateBrush();

	// Create a Slate image widget to display the Slate brush
	TSharedRef<SImage> ImageWidget = SNew(SImage)
		.Image(VisualisationSlateBrush);

	ImageWidgetPtr = ImageWidget;

	// Create the secondary window to contain the image widget
	TSharedRef<SWindow> SecondWindow = SNew(SWindow)
		.Title(FText::FromString(TEXT("Visualisation Viewport")))
		.ClientSize(FVector2D(800, 600))
		.Content()
		[
			ImageWidget
		];

	// Store a weak reference to the window
	SecondWindowPtr = SecondWindow;

	FSlateApplication::Get().AddWindow(SecondWindow);

	if (monitorRects.size() >= 2)
	{
		RECT secondMonitorRect = monitorRects[1];
		int xPos = secondMonitorRect.left;
		int yPos = secondMonitorRect.top;
		int width = secondMonitorRect.right - secondMonitorRect.left;
		int height = secondMonitorRect.bottom - secondMonitorRect.top;

		// Manually move and resize the window to the second monitor
		SecondWindow->MoveWindowTo(FVector2D(xPos, yPos));
		SecondWindow->Resize(FVector2D(width, height));
	}
	else
	{
		UE_LOG(LogTemp, Warning, TEXT("Second monitor not found."));
	}
}

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.