Window appears with old-style UI and no text in titlebar.

László Szerémi 15 Reputation points
2024-05-24T21:31:24.4833333+00:00

I'm developing a middleware for D that is quite similar to SDL/SFML, here's an exempt from the window creation code:

class OSWindow {
[...]
this(io_str_t title, io_str_t name, int x, int y, int w, int h, ulong flags,
			WindowBitmap icon = null, OSWindow parent = null) {
registeredClass.cbSize = WNDCLASSEXW.sizeof;
registeredClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC ;
registeredClass.hInstance = mainInst;
registeredClass.lpfnWndProc = &wndprocCallback;
registeredClass.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
registeredClass.hCursor = LoadCursor(null, IDC_ARROW);
registeredClass.hIcon = LoadIcon(null, IDI_APPLICATION);
classname = toUTF16z(name);
registeredClass.lpszClassName = classname;
regClResult = RegisterClassExW(&registeredClass);
if (!regClResult) {
	auto errorCode = GetLastError();
	throw new WindowCreationException("Failed to register window class!", errorCode);
}
DWORD dwStyle = WS_OVERLAPPEDWINDOW | WS_VISIBLE;
if (x <= 0) x = CW_USEDEFAULT;
if (y <= 0) y = CW_USEDEFAULT;
if (w <= 0) w = CW_USEDEFAULT;
if (h <= 0) h = CW_USEDEFAULT;
windowname = toUTF16z(title);
HWND parentHndl = null;
if (parent !is null)
	parentHndl = parent.getHandle();
windowHandle = CreateWindowW(classname, windowname, dwStyle, x, y, w, h, parentHndl, null, mainInst, 
		null);
if (!windowHandle) {
	auto errorCode = GetLastError();
	throw new WindowCreationException("Failed to create window!", errorCode);
}
refCount ~= this;
ShowWindow(windowHandle, SW_RESTORE);
UpdateWindow(windowHandle);
}
}

Given this code, I'm getting a Win7 style GUI and no titlebar. Some other oddities is that if I don't include the WS_VISIBLE enum in dwStyle, I get a completely blank white window. In my wndCallback function, every event is dispatched to DefWindowProcW. In my event polling loop, I use Raw Input.

I've heard that I should add a manifest file, but I don't really know how to do with my own toolchain (DMD/LDC + MSVC linker and resource compiler), where I need to include the resource.o file, etc. Visual-C++ does it automatically, so there's little to no documentation, others instead suggest to use other, preexisting middleware like SDL, which has it's own issues, or even some GUI-oriented library that's not too ideal for my primary application (gaming, GUI that draws its own elements, etc.). In general I get little to no documentation and/or help besides of what Microsoft offers due to the aforementioned issues.

Windows
Windows
A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.
4,965 questions
Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,486 questions
{count} votes

1 answer

Sort by: Most helpful
  1. László Szerémi 15 Reputation points
    2024-06-03T20:01:05.0633333+00:00

    Well, the actual solution was a missing DefWindowProcW call.

    static extern (Windows) LRESULT wndprocCallback(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) nothrow @system {
    	//return DefWindowProcW(hWnd, msg, wParam, lParam);
    	switch (msg) {
    		case WM_CREATE, WM_NCCREATE:
    			return DefWindowProcW(hWnd, msg, wParam, lParam);
    		default:
    			foreach (OSWindow key; refCount) {
    				if (key.getHandle() == hWnd)
    					return key.wndCallback(msg, wParam, lParam);
    			}
    			return DefWindowProcW(hWnd, msg, wParam, lParam);
    	}
    }
    

    Tutorials only talked about the importance of WM_CREATE and WM_NCCREATE, the rest wasn't talked as much about. My solution uses OOP solutions, and essentially each class creates a mostly OS-agnostic window.

    1 person found this answer helpful.
    0 comments No comments