Thank you @Tong Xu - MSFT , but the code you provided only created a black window regardless if I changed the path to an image. However your code gave me ideas on how to rephrase my question and the AI posted this. I must also emphasize that I am still learning Win32 and am not knowledgeable in all terminology, headers, classes etc.
#include <windows.h>
#include <gdiplus.h>
using namespace Gdiplus;
//Next line was missing
#pragma comment(lib, "gdiplus.lib")
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
Graphics graphics(hdc);
Image image(L"C:\\path\\to\\image.jpg");
graphics.DrawImage(&image, 0, 0);
EndPaint(hWnd, &ps);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
break;
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, IDI_APPLICATION);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = L"WindowClass";
wcex.hIconSm = LoadIcon(wcex.hInstance, IDI_APPLICATION);
if (!RegisterClassEx(&wcex))
{
MessageBox(NULL, L"Window Registration Failed!", L"Error!", MB_ICONEXCLAMATION | MB_OK);
return 0;
}
HWND hWnd = CreateWindowEx(WS_EX_CLIENTEDGE, L"WindowClass", L"Window Title", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, NULL, NULL, hInstance, NULL);
if (hWnd == NULL)
{
MessageBox(NULL, L"Window Creation Failed!", L"Error!", MB_ICONEXCLAMATION | MB_OK);
return 0;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
GdiplusShutdown(gdiplusToken);
return msg.wParam;
}
As far as I understand you will need to include gdiplus.h, using namespace gdiplus, and #pragma comment (lib, "gdiplus.lib") or linking to the library itself. That will allow it to access code it needs for the Image and Graphics classes under GDI+. Then before creating the window, you must initialize GDI+ then shutdown GDI+ at the end (which I'm assuming is to free up resources.). It produces the image when given a path to one, but will allow the window to stretch up to the image's size.