First window up in the language!

This commit is contained in:
Krzosa Karol
2022-06-16 09:29:47 +02:00
parent 4f0d16e632
commit d591cfea6f
3 changed files with 81 additions and 12 deletions

View File

@@ -1,5 +1,6 @@
DWORD :: U32
LPCSTR :: *char
LPSTR :: *char
LPCWSTR :: *U16
HWND :: *void
HMENU :: *void
@@ -22,6 +23,7 @@ BYTE :: U8 // @todo? unsigned char
WORD :: S16 // short
LONG :: S32 // @todo long
UINT :: U32 // @todo uint
ATOM :: WORD
MEM_COMMIT :: 0x00001000
MEM_RESERVE :: 0x00002000

View File

@@ -131,21 +131,20 @@ create_bitmap :: (size: Vec2I, bottom_up: Bool = true): Windows_Bitmap
result.hdc = CreateCompatibleDC(hdc)
return result
app_is_running := true
window_procedure :: (hwnd: HWND, msg: UINT, wparam: WPARAM, lparam: LPARAM): LRESULT
if msg == WM_DESTROY
PostQuitMessage(0)
return 0
else;; return DefWindowProcW(hwnd, msg, wparam, lparam)
main :: (argc: int, argv: **char): int
bitmap := create_bitmap({1280, 720})
test_unicode :: ()
string := " 豈 更 車 賈 滑 串 句 龜 龜 契 金 喇 奈 懶 癩 羅 蘿 螺 裸 邏 樂 洛 烙 珞 落 酪 駱 亂 卵 欄 爛 蘭 鸞 嵐 濫 藍 襤 拉 臘 蠟 廊 朗 浪 狼 郎 來 冷 勞 擄 櫓 爐 盧 老 蘆 虜 路 露 魯 鷺 碌 祿 綠 菉 錄 鹿 論 壟 弄 籠 聾 牢 磊 賂 雷 壘 屢 樓 淚 漏 累 縷 陋 勒 肋 凜 凌 稜 綾 菱 陵 讀 拏 樂 諾 丹 寧 怒 率 異 北 磻 便 復 不 泌 數 索 參 塞 省 葉 說 殺 辰 沈 拾 若 掠 略 亮 兩 凉 梁 糧 良 諒 量 勵 ..."
string_result := string_to_string16(string)
print(string_result)
result := utf8_to_utf32(&"A"[0], 1)
assert(result.out_str == 'A, "Invalid decode")
assert(result.out_str == 'A, "Invalid decode") // '
result = utf8_to_utf32(&"ć"[0], 2)
assert(result.out_str == 0x107, "Invalid decode")
@@ -153,3 +152,31 @@ main :: (argc: int, argv: **char): int
result = utf8_to_utf32(&"ó"[0], 2)
assert(result.out_str == 0xF3, "Invalid decode")
WinMain :: (hInstance: HINSTANCE, hPrevInstance: HINSTANCE, lpCmdLine: LPSTR, nShowCmd: int): int
bitmap := create_bitmap({1280, 720})
window_name := string_to_string16("Have a wonderful day!")
w := WNDCLASSW{
lpfnWndProc = window_procedure,
hInstance = hInstance,
lpszClassName = window_name.str,
}
assert(RegisterClassW(&w) != 0)
window := CreateWindowExW(
dwExStyle = 0, hWndParent = 0, hMenu = 0, lpParam = 0,
X = CW_USEDEFAULT, Y = CW_USEDEFAULT, nWidth = CW_USEDEFAULT, nHeight = CW_USEDEFAULT,
lpClassName = window_name.str,
lpWindowName = window_name.str,
dwStyle = WS_OVERLAPPEDWINDOW,
hInstance = hInstance
)
assert(window != 0)
ShowWindow(window, nShowCmd)
for app_is_running
msg: MSG
for PeekMessageW(&msg, window, 0, 0, PM_REMOVE) > 0
TranslateMessage(&msg)
DispatchMessageW(&msg)

View File

@@ -1,13 +1,53 @@
#load "Windows.kl"
WNDPROC :: (hwnd: HWND, uMsg: UINT, wParam: WPARAM, lParam: LPARAM): LRESULT
WNDCLASSW :: struct;; style: UINT; lpfnWndProc: WNDPROC; cbClsExtra: int; cbWndExtra: int; hInstance: HINSTANCE; hIcon: HICON; hCursor: HCURSOR; hbrBackground: HBRUSH; lpszMenuName: LPCWSTR; lpszClassName: LPCWSTR
WNDPROC :: (hwnd: HWND, uMsg: UINT, wParam: WPARAM, lParam: LPARAM): LRESULT
WNDCLASSW :: struct;; style: UINT; lpfnWndProc: WNDPROC; cbClsExtra: int; cbWndExtra: int; hInstance: HINSTANCE; hIcon: HICON; hCursor: HCURSOR; hbrBackground: HBRUSH; lpszMenuName: LPCWSTR; lpszClassName: LPCWSTR
MSG :: struct;; hwnd: HWND; message: UINT; wParam: WPARAM; lParam: LPARAM; time: DWORD; pt: POINT; lPrivate: DWORD
POINT :: struct;; x: LONG; y: LONG
LPMSG :: *MSG
PostQuitMessage :: #foreign (nExitCode: int)
DefWindowProcW :: #foreign (hwnd: HWND, uMsg: UINT, wParam: WPARAM, lParam: LPARAM): LRESULT
GetDC :: #foreign (hWnd: HWND): HDC
CreateWindowA :: #foreign (dwExStyle: DWORD, lpClassName: *char, lpWindowName: *char, dwStyle: DWORD, X: int, Y: int, nWidth: int, nHeight: int, hWndParent: HWND, hMenu: HMENU, hInstance: HINSTANCE, lpParam: *void): HWND
CreateWindowExW :: #foreign (dwExStyle: DWORD, lpClassName: LPCWSTR, lpWindowName: LPCWSTR, dwStyle: DWORD, X: int, Y: int, nWidth: int, nHeight: int, hWndParent: HWND, hMenu: HMENU, hInstance: HINSTANCE, lpParam: LPVOID): HWND
RegisterClassW :: #foreign (lpWndClass: *WNDCLASSW): ATOM
ShowWindow :: #foreign (hWnd: HWND, nCmdShow: int): BOOL
PeekMessageW :: #foreign (lpMsg: LPMSG, hWnd: HWND, wMsgFilterMin: UINT, wMsgFilterMax: UINT, wRemoveMs: UINT):BOOL
TranslateMessage:: #foreign (lpMsg: *MSG): BOOL
DispatchMessageW:: #foreign (lpMsg: *MSG): LRESULT
PostQuitMessage :: #foreign(nExitCode: int)
DefWindowProcW :: #foreign (hwnd: HWND, uMsg: UINT, wParam: WPARAM, lParam: LPARAM): LRESULT
GetDC :: #foreign (hWnd: HWND): HDC
CreateWindowA :: #foreign (dwExStyle: DWORD, lpClassName: *char, lpWindowName: *char, dwStyle: DWORD, X: int, Y: int, nWidth: int, nHeight: int, hWndParent: HWND, hMenu: HMENU, hInstance: HINSTANCE, lpParam: *void): HWND
CreateWindowExW :: #foreign (dwExStyle: DWORD, lpClassName: LPCWSTR, lpWindowName: LPCWSTR, dwStyle: DWORD, X: int, Y: int, nWidth: int, nHeight: int, hWndParent: HWND, hMenu: HMENU, hInstance: HINSTANCE, lpPara: LPVOID): HWND
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
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
WS_CLIPCHILDREN :: 0x02000000
WS_CLIPSIBLINGS :: 0x04000000
WS_DISABLED :: 0x08000000
WS_DLGFRAME :: 0x00400000
WS_GROUP :: 0x00020000
WS_HSCROLL :: 0x00100000
WS_ICONIC :: 0x20000000
WS_MAXIMIZE :: 0x01000000
WS_MAXIMIZEBOX :: 0x00010000
WS_MINIMIZE :: 0x20000000
WS_MINIMIZEBOX :: 0x00020000
WS_OVERLAPPED :: 0x00000000
WS_POPUP :: 0x80000000
WS_SIZEBOX :: 0x00040000
WS_SYSMENU :: 0x00080000
WS_TABSTOP :: 0x00010000
WS_THICKFRAME :: 0x00040000
WS_TILED :: 0x00000000
WS_VISIBLE :: 0x10000000
WS_VSCROLL :: 0x00200000
WS_OVERLAPPEDWINDOW :: WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX
PM_NOREMOVE :: 0
PM_REMOVE :: 0x0001
PM_NOYIELD :: 0x0002