// Use the Gdiplus namespace to simplify code
// Global token for GDI+ usage
// Function declaration for creating a window with an image
extern "C" __declspec(dllexport) void CreateBorderlessWindowWithImage(BYTE* imageBytes, UINT length);
// Window procedure function
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
static Bitmap* image = nullptr; // Static pointer to hold the image
// This block handles window creation.
// The image data is passed as a parameter in WM_CREATE.
CREATESTRUCT* pCreate = reinterpret_cast<CREATESTRUCT*>(lParam);
BYTE* data = reinterpret_cast<BYTE*>(pCreate->lpCreateParams);
// Create an IStream from the byte array (image data)
HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, length);
void* pMem = GlobalLock(hMem);
memcpy(pMem, data, length);
IStream* pStream = nullptr;
CreateStreamOnHGlobal(hMem, TRUE, &pStream);
// Load the image from the stream
image = new Bitmap(pStream);
if (!image || image->GetLastStatus() != Gdiplus::Ok) {
MessageBox(hwnd, L"Failed to load image", L"Error", MB_ICONERROR);
// This block handles the paint messages for the window.
HDC hdc = BeginPaint(hwnd, &ps);
graphics.DrawImage(image, 0, 0, image->GetWidth(), image->GetHeight());
// This block handles the cleanup when the window is destroyed.
return DefWindowProc(hwnd, uMsg, wParam, lParam);
// Function to create the borderless window and display the image
void CreateBorderlessWindowWithImage(BYTE* imageBytes, UINT length) {
GdiplusStartupInput gdiplusStartupInput;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
// Define the class name for the window
const char CLASS_NAME[] = "BorderlessWindowClass";
// Fill in the WNDCLASS struct to define the window
wc.lpfnWndProc = WindowProc; // Pointer to the window procedure
wc.hInstance = GetModuleHandle(NULL);
wc.lpszClassName = CLASS_NAME;
// Register the window class
HWND hwnd = CreateWindowEx(
0, // Optional window styles.
CLASS_NAME, // Window class
"A Borderless Window", // Window text
WS_POPUP, // Window style - Borderless
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
wc.hInstance, // Instance handle
imageBytes // Pass image bytes to WM_CREATE
// Check if window creation was successful
GdiplusShutdown(gdiplusToken);
// Show and update the window
ShowWindow(hwnd, SW_SHOW);
while (GetMessage(&msg, NULL, 0, 0)) {
GdiplusShutdown(gdiplusToken);