Skip to content

Commit

Permalink
Merge pull request #68 from karl-zylinski/win32-open-window
Browse files Browse the repository at this point in the history
Open Win32 Window
  • Loading branch information
karl-zylinski authored Jan 12, 2025
2 parents 97ae73c + 3074f66 commit 41b774a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ jobs:
odin check wgpu/microui -target:windows_amd64 $FLAGS
odin check win32/game_of_life -target:windows_amd64 $FLAGS
odin check win32/open_window -target:windows_amd64 $FLAGS
odin check nanovg/example.odin -file $FLAGS
odin check nanovg/fbo.odin -file $FLAGS
Expand Down
41 changes: 41 additions & 0 deletions win32/open_window/main.odin
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package open_win32_window

import win "core:sys/windows"

main :: proc() {
instance := win.HINSTANCE(win.GetModuleHandleW(nil))
assert(instance != nil, "Failed to fetch current instance")
class_name := win.L("Windows Window")

cls := win.WNDCLASSW {
lpfnWndProc = win_proc,
lpszClassName = class_name,
hInstance = instance,
}

class := win.RegisterClassW(&cls)
assert(class != 0, "Class creation failed")

hwnd := win.CreateWindowW(class_name,
win.L("Windows Window"),
win.WS_OVERLAPPEDWINDOW | win.WS_VISIBLE,
100, 100, 1280, 720,
nil, nil, instance, nil)

assert(hwnd != nil, "Window creation Failed")
msg: win.MSG

for win.GetMessageW(&msg, nil, 0, 0) > 0 {
win.TranslateMessage(&msg)
win.DispatchMessageW(&msg)
}
}

win_proc :: proc "stdcall" (hwnd: win.HWND, msg: win.UINT, wparam: win.WPARAM, lparam: win.LPARAM) -> win.LRESULT {
switch(msg) {
case win.WM_DESTROY:
win.PostQuitMessage(0)
}

return win.DefWindowProcW(hwnd, msg, wparam, lparam)
}

0 comments on commit 41b774a

Please sign in to comment.