Last active
March 31, 2025 22:01
-
-
Save ske2004/336d8cce8cd9db59d61ceb13c1ed500a to your computer and use it in GitHub Desktop.
811 byte windows executable with graphics update.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Compile like this: | |
// cl Win32.c /O1 /c /GS- && crinkler Win32.obj user32.lib kernel32.lib gdi32.lib /SUBSYSTEM:WINDOWS /NODEFAULTLIB /UNSAFEIMPORT /TINYHEADER | |
#include <windows.h> | |
#define WN_TITLE "Unnamed" | |
#define WN_CLASS "WindowClassName" | |
#define WN_WIDTH 800 | |
#define WN_HEIGHT 600 | |
int ScrollX = 0; | |
static void BlitToWindow(HWND Window) | |
{ | |
RECT Rect; | |
GetWindowRect(Window, &Rect); | |
int Width = Rect.right-Rect.left; | |
int Height = Rect.bottom-Rect.top; | |
DWORD32 *Buffer = VirtualAlloc(NULL, Width*Height*4, MEM_COMMIT, PAGE_READWRITE); | |
for (int i = 0; i < Height; i++) | |
{ | |
for (int j = 0; j < Width; j++) | |
{ | |
Buffer[i*Width+j] = i^j+ScrollX; | |
} | |
} | |
ScrollX++; | |
HDC DC = GetDC(Window); | |
BITMAPINFOHEADER BmpInfo = { 0 }; | |
BmpInfo.biSize = sizeof BmpInfo; | |
BmpInfo.biPlanes = 1; | |
BmpInfo.biBitCount = 32; | |
BmpInfo.biWidth = Width; | |
BmpInfo.biHeight = -Height; | |
SetDIBitsToDevice(DC, 0, 0, Width, Height, 0, 0, 0, Height, Buffer, (BITMAPINFO*)&BmpInfo, DIB_RGB_COLORS); | |
ReleaseDC(Window, DC); | |
VirtualFree(Buffer, 0, MEM_RELEASE); | |
} | |
UINT_PTR FrameTimer = 1; | |
static LRESULT CALLBACK WndProc( | |
HWND hWnd, | |
UINT Msg, | |
WPARAM wParam, | |
LPARAM lParam | |
) | |
{ | |
switch (Msg) { | |
case WM_TIMER: | |
if (wParam == FrameTimer) | |
{ | |
BlitToWindow(hWnd); | |
} | |
break; | |
case WM_CLOSE: | |
DestroyWindow(hWnd); | |
break; | |
case WM_DESTROY: | |
PostQuitMessage(0); | |
break; | |
} | |
return DefWindowProcA(hWnd, Msg, wParam, lParam); | |
} | |
int WinMainCRTStartup() | |
{ | |
WNDCLASSA WindowClass = { 0 }; | |
WindowClass.lpszClassName = WN_CLASS; | |
WindowClass.lpfnWndProc = WndProc; | |
// NOTE(ske): No error handling, but not really necessary. | |
RegisterClassA(&WindowClass); | |
// NOTE(ske): No error handling, but not really necessary. | |
HWND Window = CreateWindowA( | |
WindowClass.lpszClassName, | |
WN_TITLE, | |
WS_OVERLAPPEDWINDOW, | |
CW_USEDEFAULT, CW_USEDEFAULT, | |
WN_WIDTH, WN_HEIGHT, | |
NULL, | |
NULL, | |
NULL, | |
NULL | |
); | |
ShowWindow(Window, TRUE); | |
SetTimer(Window, FrameTimer, 16, NULL); | |
MSG Msg = { 0 }; | |
while (GetMessageA(&Msg, NULL, 0, 0)) { | |
TranslateMessage(&Msg); | |
DispatchMessage(&Msg); | |
} | |
ExitProcess(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment