#import "KERNEL32.core" #import "GDI32.core" #import "USER32.core" #import "WINMM.core" #import "Windows.core" OS :: struct bitmap: Bitmap window_dc: HDC window: HWND Bitmap :: struct size: Vec2I data: *U32 hdc: HDC dib: HBITMAP compatible_dc: HDC IsValidBitmap :: (b: *Bitmap): Bool result := b.data != 0 return result CreateBitmap :: (for_dc: HDC, size: Vec2I, bottom_up: Bool = true): Bitmap result: Bitmap = {size = size} if bottom_up == false result.size.y = -result.size.y header_size: U32 = SizeOf(BITMAPINFOHEADER) Assert(header_size == 40) bminfo := BITMAPINFO{ BITMAPINFOHEADER{ biSize = header_size, biWidth = size.x->LONG, biHeight = size.y->LONG, biPlanes = 1, biBitCount = 32, biCompression = BI_RGB, biXPelsPerMeter = 1, biYPelsPerMeter = 1, } } result.dib = CreateDIBSection(for_dc, &bminfo, DIB_RGB_COLORS, (&result.data)->**void, 0, 0) result.hdc = CreateCompatibleDC(for_dc) result.compatible_dc = for_dc return result DestroyBitmap :: (b: *Bitmap) if IsValidBitmap(b) DeleteDC(b.hdc) DeleteObject(b.dib) ZeroMemory(b, SizeOf(Bitmap)) DrawBitmapInCompatibleDC :: (b: *Bitmap) if(IsValidBitmap(b)) SelectObject(b.hdc, b.dib) BitBlt(b.compatible_dc, 0, 0, b.size.x->int, b.size.y->int, b.hdc, 0, 0, SRCCOPY) StartMultimedia :: (x: S64 = 1280, y: S64 = 720, title: String = "Hello people!"): Mu mu: Mu if good_scheduling := false, timeBeginPeriod(1) == TIMERR_NOERROR good_scheduling = true hInstance := GetModuleHandleA(0) window_name := StringToString16(&mu.frame_arena, title) w := WNDCLASSW{ lpfnWndProc = WindowProc, hInstance = hInstance, lpszClassName = window_name.str, } Assert(RegisterClassW(&w) != 0) mu.os.window = CreateWindowExW( dwExStyle = 0, hWndParent = 0, hMenu = 0, lpParam = 0, X = CW_USEDEFAULT, Y = CW_USEDEFAULT, nWidth = x->int, nHeight = y->int, lpClassName = window_name.str, lpWindowName = window_name.str, dwStyle = WS_OVERLAPPEDWINDOW, hInstance = hInstance ) Assert(mu.os.window != 0) ShowWindow(mu.os.window, ShowCmd) mu.os.window_dc = GetDC(mu.os.window) mu.os.bitmap = W32.CreateBitmap(mu.os.window_dc, {x,y}) mu.scrn = mu.os.bitmap.data mu.x = mu.os.bitmap.size.x mu.y = mu.os.bitmap.size.y return mu ShowCmd: int WinMain :: (hInstance: HINSTANCE, hPrevInstance: HINSTANCE, lpCmdLine: LPSTR, nShowCmd: int): int ShowCmd = nShowCmd // for AppIsRunning // msg: MSG // for PeekMessageW(&msg, window, 0, 0, PM_REMOVE) > 0 // TranslateMessage(&msg) // DispatchMessageW(&msg) // for y := 0, y < bitmap.size.y, y+=1 // for x := 0, x < bitmap.size.x, x+=1 // bitmap.data[x + y*bitmap.size.x] = 0xFFFF0000 // W32.DrawBitmapInCompatibleDC(&bitmap) // Sleep(100) return 0 AppIsRunning := true WindowProc :: (hwnd: HWND, msg: UINT, wparam: WPARAM, lparam: LPARAM): LRESULT if msg == WM_DESTROY PostQuitMessage(0) AppIsRunning = false return 0 else;; return DefWindowProcW(hwnd, msg, wparam, lparam)