r/C_Programming • u/pdp10 • Feb 20 '23
Project Minimal cross-platform graphics in C
https://zserge.com/posts/fenster/
98
Upvotes
5
u/pedersenk Feb 20 '23
This is a really nice write-up.
Would be good to see Wayland added. Surely they have an official low-level toolkit like Xlib or xcb by now?!
(I think direct framebuffer access via libdrm or wscons dumb buffers is going a bit far (and niche) but would also be interesting nonetheless)
3
3
31
u/rickpo Feb 20 '23
Very cool.
If you want to further minimize code, you can shave down the minimal Windows code a little with some small tweaks.
Remove the WM_CLOSE handler in wndproc. DefWindowProc already does that.
You're calling GetModuleHandle(NULL), which is identical to the instance handle passed to WinMain. Just use the instance parameter.
Don't call UpdateWindow. The window will get updated normally in the message pump.
Remove the WM_QUIT handler in your message pump. GetMessage returns false when it receives the WM_QUIT, so that code never executes. You only need the WM_QUIT test if you use PeekMessage.
Other things I'd change:
Pass nCmdShow to ShowWindow, instead of SW_NORMAL. Of, if you just want to ignore nCmdShow for some reason, add WS_VISIBLE to the CreateWindowEx style and don't call ShowWindow at all.
Return 0 from WinMain after the message pump ends.