Add windows utilities
This commit is contained in:
@@ -4,6 +4,8 @@ WNDCLASSW :: struct;; style: UINT; lpfnWndProc: WNDPROC; cbClsExtra: int;
|
||||
MSG :: struct;; hwnd: HWND; message: UINT; wParam: WPARAM; lParam: LPARAM; time: DWORD; pt: POINT; lPrivate: DWORD
|
||||
POINT :: struct;; x: LONG; y: LONG
|
||||
LPMSG :: *MSG
|
||||
RECT :: struct;; left: LONG; top: LONG; right: LONG; bottom: LONG
|
||||
LPRECT :: *RECT
|
||||
|
||||
PostQuitMessage :: #foreign (nExitCode: int)
|
||||
DefWindowProcW :: #foreign (hwnd: HWND, uMsg: UINT, wParam: WPARAM, lParam: LPARAM): LRESULT
|
||||
@@ -16,14 +18,18 @@ PeekMessageW :: #foreign (lpMsg: LPMSG, hWnd: HWND, wMsgFilterMin: UINT, wM
|
||||
TranslateMessage :: #foreign (lpMsg: *MSG): BOOL
|
||||
DispatchMessageW :: #foreign (lpMsg: *MSG): LRESULT
|
||||
SetProcessDPIAware:: #foreign (): BOOL
|
||||
|
||||
GetDpiForWindow :: #foreign (hwnd: HWND): UINT
|
||||
AdjustWindowRectExForDpi :: #foreign (lpRect: *RECT, dwStyle: DWORD, bMenu: BOOL, dwExStyle: DWORD, dpi: UINT): BOOL
|
||||
AdjustWindowRectEx :: #foreign (lpRect: *RECT, dwStyle: DWORD, bMenu: BOOL, dwExStyle: DWORD): BOOL
|
||||
SetWindowPos :: #foreign (hWnd: HWND, hWndInsertAfter: HWND, X: int, Y: int, cx: int, cy: int, uFlags: UINT): BOOL
|
||||
GetClientRect :: #foreign (hWnd: HWND, lpRect: LPRECT): BOOL
|
||||
|
||||
WM_NULL :: 0x0000; WM_CREATE :: 0x0001; WM_DESTROY :: 0x0002; WM_MOVE :: 0x0003; WM_SIZE :: 0x0005
|
||||
WM_ACTIVATE :: 0x0006; WA_INACTIVE :: 0; WA_ACTIVE :: 1; WA_CLICKACTIVE :: 2
|
||||
WM_SETFOCUS :: 0x0007; WM_KILLFOCUS :: 0x0008; WM_ENABLE :: 0x000A; WM_SETREDRAW :: 0x000B; WM_SETTEXT :: 0x000C; WM_GETTEXT :: 0x000D; WM_GETTEXTLENGTH :: 0x000E; WM_PAINT :: 0x000F; WM_CLOSE :: 0x0010
|
||||
CW_USEDEFAULT :: -2147483648//0x80000000
|
||||
|
||||
WS_BORDER :: 0x00800000
|
||||
|
||||
WS_CAPTION :: 0x00C00000
|
||||
WS_CHILD :: 0x40000000
|
||||
WS_CHILDWINDOW :: 0x40000000
|
||||
@@ -64,4 +70,25 @@ SW_SHOWMINNOACTIVE :: 7
|
||||
SW_SHOWNA :: 8
|
||||
SW_RESTORE :: 9
|
||||
SW_SHOWDEFAULT :: 10
|
||||
SW_FORCEMINIMIZE :: 11
|
||||
SW_FORCEMINIMIZE :: 11
|
||||
|
||||
HWND_TOP :: 0
|
||||
HWND_BOTTOM :: 1
|
||||
// HWND_NOTOPMOST :: -2 // Probably relies on overflow ?
|
||||
// HWND_TOPMOST :: -1 // Probably relies on overflow ?
|
||||
|
||||
SWP_ASYNCWINDOWPOS :: 0x4000
|
||||
SWP_DEFERERASE :: 0x2000
|
||||
SWP_DRAWFRAME :: 0x0020
|
||||
SWP_FRAMECHANGED :: 0x0020
|
||||
SWP_HIDEWINDOW :: 0x0080
|
||||
SWP_NOACTIVATE :: 0x0010
|
||||
SWP_NOCOPYBITS :: 0x0100
|
||||
SWP_NOMOVE :: 0x0002
|
||||
SWP_NOOWNERZORDER :: 0x0200
|
||||
SWP_NOREDRAW :: 0x0008
|
||||
SWP_NOREPOSITION :: 0x0200
|
||||
SWP_NOSENDCHANGING :: 0x0400
|
||||
SWP_NOSIZE :: 0x0001
|
||||
SWP_NOZORDER :: 0x0004
|
||||
SWP_SHOWWINDOW :: 0x0040
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user