Add windows utilities

This commit is contained in:
Krzosa Karol
2022-10-01 19:59:45 +02:00
parent d866ebb231
commit 026c1ddc80
2 changed files with 71 additions and 4 deletions

View File

@@ -57,11 +57,45 @@ DrawBitmapInCompatibleDC :: (b: *Bitmap)
SelectObject(b.hdc, b.dib)
BitBlt(b.compatible_dc, 0, 0, b.size.x->int, b.size.y->int, b.hdc, 0, 0, SRCCOPY)
GetWindowSize :: (window: HWND): Vec2I
result: Vec2I
window_rect: RECT
GetClientRect(window, &window_rect)
result.x = (window_rect.right - window_rect.left)->S64
result.y = (window_rect.bottom - window_rect.top)->S64
return result
GetWindowPos :: (window: HWND): Vec2I
pos: Point
ClientToScreen(window, &pos)
return {pos.x, pos.y}
AdjustWindowRect :: (window: HWND, style: DWORD, rect: *RECT): void
FALSE :: 0
if window == 0
dpi := GetDpiForWindow(window)
AdjustWindowRectExForDpi(rect, style, FALSE, 0, dpi)
else
AdjustWindowRectEx(rect, style, FALSE, 0)
SetWindowSize :: (window: HWND, style: DWORD, size: Vec2I): void
rect := RECT{ 0, 0, size.x->LONG, size.y->LONG }
AdjustWindowRect(window, style, &rect)
SetWindowPos(window, HWND_TOP, 0, 0, (rect.right - rect.left)->int, (rect.bottom - rect.top)->int, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOZORDER)
SetWindowPosition :: (window: HWND, style: DWORD, pos: Vec2I): void
rect := RECT{ pos.x->LONG, pos.y->LONG, pos.x->LONG, pos.y->LONG }
AdjustWindowRect(window, style, &rect)
SetWindowPos(window, 0, rect.left, rect.top, 0, 0, SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE)
StartMultimedia :: (x: S64 = 1280, y: S64 = 720, title: String = "Hello people!"): Mu
mu: Mu
if timeBeginPeriod(1) == TIMERR_NOERROR
mu.os.good_scheduling = true
dpi_aware := SetProcessDPIAware()
Assert(dpi_aware != 0)
mu.time.start = Time()
hInstance := GetModuleHandleA(0)
@@ -70,9 +104,11 @@ StartMultimedia :: (x: S64 = 1280, y: S64 = 720, title: String = "Hello people!"
lpfnWndProc = WindowProc,
hInstance = hInstance,
lpszClassName = window_name.str,
// style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW,
}
Assert(RegisterClassW(&w) != 0)
style: DWORD = 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,
@@ -82,10 +118,14 @@ StartMultimedia :: (x: S64 = 1280, y: S64 = 720, title: String = "Hello people!"
hInstance = hInstance
)
Assert(mu.os.window != 0)
SetWindowSize(mu.os.window, style, {x,y})
ShowWindow(mu.os.window, SW_SHOW)
size := GetWindowSize(mu.os.window)
Assert(size.x == x && size.y == y)
mu.os.window_dc = GetDC(mu.os.window)
mu.os.bitmap = W32.CreateBitmap(mu.os.window_dc, {x,y})
mu.os.bitmap = W32.CreateBitmap(mu.os.window_dc, size)
mu.scrn = mu.os.bitmap.data
mu.x = mu.os.bitmap.size.x