From 75cbb0974487cd9fee3762a0b2cd272a94402154 Mon Sep 17 00:00:00 2001 From: hikari Date: Fri, 1 Apr 2022 02:11:41 +0300 Subject: [PATCH 1/5] sys/windows: add intrinsics.constant_utf16_cstring --- core/sys/windows/types.odin | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/sys/windows/types.odin b/core/sys/windows/types.odin index 50098a59c..05f71192c 100644 --- a/core/sys/windows/types.odin +++ b/core/sys/windows/types.odin @@ -3,6 +3,8 @@ package sys_windows import "core:c" +L :: intrinsics.constant_utf16_cstring + c_char :: c.char c_uchar :: c.uchar c_int :: c.int From 107bede9fdf32594d19bc290e717dca65921b088 Mon Sep 17 00:00:00 2001 From: hikari Date: Fri, 1 Apr 2022 02:23:44 +0300 Subject: [PATCH 2/5] sys/windows: fix building error --- core/sys/windows/types.odin | 1 + 1 file changed, 1 insertion(+) diff --git a/core/sys/windows/types.odin b/core/sys/windows/types.odin index 05f71192c..653d2c62f 100644 --- a/core/sys/windows/types.odin +++ b/core/sys/windows/types.odin @@ -2,6 +2,7 @@ package sys_windows import "core:c" +import "core:intrinsics" L :: intrinsics.constant_utf16_cstring From b21cf05d44afb8697bf34d6718bb165c724d57f5 Mon Sep 17 00:00:00 2001 From: hikari Date: Fri, 1 Apr 2022 02:25:10 +0300 Subject: [PATCH 3/5] sys/windows: move L into util.odin --- core/sys/windows/types.odin | 3 --- core/sys/windows/util.odin | 5 ++++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/sys/windows/types.odin b/core/sys/windows/types.odin index 653d2c62f..50098a59c 100644 --- a/core/sys/windows/types.odin +++ b/core/sys/windows/types.odin @@ -2,9 +2,6 @@ package sys_windows import "core:c" -import "core:intrinsics" - -L :: intrinsics.constant_utf16_cstring c_char :: c.char c_uchar :: c.uchar diff --git a/core/sys/windows/util.odin b/core/sys/windows/util.odin index 5797216c3..d464007d3 100644 --- a/core/sys/windows/util.odin +++ b/core/sys/windows/util.odin @@ -3,6 +3,9 @@ package sys_windows import "core:strings" import "core:sys/win32" +import "core:intrinsics" + +L :: intrinsics.constant_utf16_cstring LOWORD :: #force_inline proc "contextless" (x: DWORD) -> WORD { return WORD(x & 0xffff) @@ -456,4 +459,4 @@ run_as_user :: proc(username, password, application, commandline: string, pi: ^P } else { return false } -} \ No newline at end of file +} From 73f9d12d476f378e6b8abc7dcd5155c4f688719e Mon Sep 17 00:00:00 2001 From: hikari Date: Fri, 1 Apr 2022 06:22:27 +0300 Subject: [PATCH 4/5] sys/windows: add various procedures --- core/sys/windows/types.odin | 15 +++++++++++++++ core/sys/windows/user32.odin | 5 +++++ 2 files changed, 20 insertions(+) diff --git a/core/sys/windows/types.odin b/core/sys/windows/types.odin index 50098a59c..47c180db8 100644 --- a/core/sys/windows/types.odin +++ b/core/sys/windows/types.odin @@ -96,6 +96,7 @@ LPPROCESS_INFORMATION :: ^PROCESS_INFORMATION PSECURITY_ATTRIBUTES :: ^SECURITY_ATTRIBUTES LPSECURITY_ATTRIBUTES :: ^SECURITY_ATTRIBUTES LPSTARTUPINFO :: ^STARTUPINFO +LPTRACKMOUSEEVENT :: ^TRACKMOUSEEVENT VOID :: rawptr PVOID :: rawptr LPVOID :: rawptr @@ -272,6 +273,13 @@ PAINTSTRUCT :: struct { rgbReserved: [32]BYTE, } +TRACKMOUSEEVENT :: struct { + cbSize: DWORD, + dwFlags: DWORD, + hwndTrack: HWND, + dwHoverTime: DWORD, +} + WIN32_FIND_DATAW :: struct { dwFileAttributes: DWORD, ftCreationTime: FILETIME, @@ -645,6 +653,13 @@ MK_MBUTTON :: 0x0010 MK_XBUTTON1 :: 0x0020 MK_XBUTTON2 :: 0x0040 +TME_HOVER :: 0x00000001 +TME_LEAVE :: 0x00000002 +TME_NONCLIENT :: 0x00000010 +TME_QUERY :: 0x40000000 +TME_CANCEL :: 0x80000000 +HOVER_DEFAULT :: 0xFFFFFFFF + USER_TIMER_MAXIMUM :: 0x7FFFFFFF USER_TIMER_MINIMUM :: 0x0000000A diff --git a/core/sys/windows/user32.odin b/core/sys/windows/user32.odin index bdab77e27..4068ecdb2 100644 --- a/core/sys/windows/user32.odin +++ b/core/sys/windows/user32.odin @@ -123,6 +123,11 @@ foreign user32 { BeginPaint :: proc(hWnd: HWND, lpPaint: ^PAINTSTRUCT) -> HDC --- EndPaint :: proc(hWnd: HWND, lpPaint: ^PAINTSTRUCT) -> BOOL --- + GetCapture :: proc() -> HWND --- + SetCapture :: proc(hWnd: HWND) -> HWND --- + ReleaseCapture :: proc() -> BOOL --- + TrackMouseEvent :: proc(lpEventTrack: LPTRACKMOUSEEVENT) -> BOOL --- + GetKeyState :: proc(nVirtKey: c_int) -> SHORT --- GetAsyncKeyState :: proc(vKey: c_int) -> SHORT --- From e28525e28c5baf6906cb3e7e1e15b11510ec959e Mon Sep 17 00:00:00 2001 From: hikari Date: Fri, 1 Apr 2022 07:28:18 +0300 Subject: [PATCH 5/5] sys/windows: fix some procedure definitions and types --- core/sys/windows/types.odin | 49 ++++++++++++++++++++++++++++++------ core/sys/windows/user32.odin | 43 ++++++++++++++++++++++++------- 2 files changed, 76 insertions(+), 16 deletions(-) diff --git a/core/sys/windows/types.odin b/core/sys/windows/types.odin index 47c180db8..d0551c6bf 100644 --- a/core/sys/windows/types.odin +++ b/core/sys/windows/types.odin @@ -395,13 +395,6 @@ CS_BYTEALIGNWINDOW : UINT : 0x2000 CS_GLOBALCLASS : UINT : 0x4000 CS_DROPSHADOW : UINT : 0x0002_0000 -GWL_EXSTYLE : c_int : -20 -GWLP_HINSTANCE : c_int : -6 -GWLP_ID : c_int : -12 -GWL_STYLE : c_int : -16 -GWLP_USERDATA : c_int : -21 -GWLP_WNDPROC : c_int : -4 - WS_BORDER : UINT : 0x0080_0000 WS_CAPTION : UINT : 0x00C0_0000 WS_CHILD : UINT : 0x4000_0000 @@ -493,6 +486,48 @@ HWND_BOTTOM :: HWND( uintptr(1)) // 1 HWND_TOPMOST :: HWND(~uintptr(0)) // -1 HWND_NOTOPMOST :: HWND(~uintptr(0) - 1) // -2 +// Window field offsets for GetWindowLong() +GWL_STYLE :: -16 +GWL_EXSTYLE :: -20 +GWL_ID :: -12 + +when ODIN_ARCH == .i386 { + GWL_WNDPROC :: -4 + GWL_HINSTANCE :: -6 + GWL_HWNDPARENT :: -8 + GWL_USERDATA :: -21 +} + +GWLP_WNDPROC :: -4 +GWLP_HINSTANCE :: -6 +GWLP_HWNDPARENT :: -8 +GWLP_USERDATA :: -21 +GWLP_ID :: -12 + +// Class field offsets for GetClassLong() +GCL_CBWNDEXTRA :: -18 +GCL_CBCLSEXTRA :: -20 +GCL_STYLE :: -26 +GCW_ATOM :: -32 + +when ODIN_ARCH == .i386 { + GCL_MENUNAME :: -8 + GCL_HBRBACKGROUND :: -10 + GCL_HCURSOR :: -12 + GCL_HICON :: -14 + GCL_HMODULE :: -16 + GCL_WNDPROC :: -24 + GCL_HICONSM :: -34 +} + +GCLP_MENUNAME :: -8 +GCLP_HBRBACKGROUND :: -10 +GCLP_HCURSOR :: -12 +GCLP_HICON :: -14 +GCLP_HMODULE :: -16 +GCLP_WNDPROC :: -24 +GCLP_HICONSM :: -34 + // GetSystemMetrics() codes SM_CXSCREEN :: 0 SM_CYSCREEN :: 1 diff --git a/core/sys/windows/user32.odin b/core/sys/windows/user32.odin index 4068ecdb2..3985c9ad6 100644 --- a/core/sys/windows/user32.odin +++ b/core/sys/windows/user32.odin @@ -10,19 +10,19 @@ foreign user32 { GetClassInfoExA :: proc(hInsatnce: HINSTANCE, lpszClass: LPCSTR, lpwcx: ^WNDCLASSEXA) -> BOOL --- GetClassInfoExW :: proc(hInsatnce: HINSTANCE, lpszClass: LPCWSTR, lpwcx: ^WNDCLASSEXW) -> BOOL --- - GetClassLongPtrA :: proc(hWnd: HWND, nIndex: c_int) -> DWORD --- - GetClassLongPtrW :: proc(hWnd: HWND, nIndex: c_int) -> DWORD --- - SetClassLongPtrA :: proc(hWnd: HWND, nIndex: c_int, dwNewLong: LONG_PTR) -> ULONG_PTR --- - SetClassLongPtrW :: proc(hWnd: HWND, nIndex: c_int, dwNewLong: LONG_PTR) -> ULONG_PTR --- + GetClassLongA :: proc(hWnd: HWND, nIndex: c_int) -> DWORD --- + GetClassLongW :: proc(hWnd: HWND, nIndex: c_int) -> DWORD --- + SetClassLongA :: proc(hWnd: HWND, nIndex: c_int, dwNewLong: LONG) -> DWORD --- + SetClassLongW :: proc(hWnd: HWND, nIndex: c_int, dwNewLong: LONG) -> DWORD --- + + GetWindowLongA :: proc(hWnd: HWND, nIndex: c_int) -> LONG --- + GetWindowLongW :: proc(hWnd: HWND, nIndex: c_int) -> LONG --- + SetWindowLongA :: proc(hWnd: HWND, nIndex: c_int, dwNewLong: LONG) -> LONG --- + SetWindowLongW :: proc(hWnd: HWND, nIndex: c_int, dwNewLong: LONG) -> LONG --- GetClassNameA :: proc(hWnd: HWND, lpClassName: LPSTR, nMaxCount: c_int) -> c_int --- GetClassNameW :: proc(hWnd: HWND, lpClassName: LPWSTR, nMaxCount: c_int) -> c_int --- - GetWindowLongPtrA :: proc(hWnd: HWND, nIndex: c_int) -> LONG_PTR --- - GetWindowLongPtrW :: proc(hWnd: HWND, nIndex: c_int) -> LONG_PTR --- - SetWindowLongPtrA :: proc(hWnd: HWND, nIndex: c_int, dwNewLong: LONG_PTR) -> LONG_PTR --- - SetWindowLongPtrW :: proc(hWnd: HWND, nIndex: c_int, dwNewLong: LONG_PTR) -> LONG_PTR --- - RegisterClassA :: proc(lpWndClass: ^WNDCLASSA) -> ATOM --- RegisterClassW :: proc(lpWndClass: ^WNDCLASSW) -> ATOM --- RegisterClassExA :: proc(^WNDCLASSEXA) -> ATOM --- @@ -198,6 +198,31 @@ CreateWindowW :: #force_inline proc "stdcall" ( ) } +when ODIN_ARCH == .amd64 { + @(default_calling_convention="stdcall") + foreign user32 { + GetClassLongPtrA :: proc(hWnd: HWND, nIndex: c_int) -> ULONG_PTR --- + GetClassLongPtrW :: proc(hWnd: HWND, nIndex: c_int) -> ULONG_PTR --- + SetClassLongPtrA :: proc(hWnd: HWND, nIndex: c_int, dwNewLong: LONG_PTR) -> ULONG_PTR --- + SetClassLongPtrW :: proc(hWnd: HWND, nIndex: c_int, dwNewLong: LONG_PTR) -> ULONG_PTR --- + + GetWindowLongPtrA :: proc(hWnd: HWND, nIndex: c_int) -> LONG_PTR --- + GetWindowLongPtrW :: proc(hWnd: HWND, nIndex: c_int) -> LONG_PTR --- + SetWindowLongPtrA :: proc(hWnd: HWND, nIndex: c_int, dwNewLong: LONG_PTR) -> LONG_PTR --- + SetWindowLongPtrW :: proc(hWnd: HWND, nIndex: c_int, dwNewLong: LONG_PTR) -> LONG_PTR --- + } +} else when ODIN_ARCH == .i386 { + GetClassLongPtrA :: GetClassLongA + GetClassLongPtrW :: GetClassLongW + SetClassLongPtrA :: SetClassLongA + SetClassLongPtrW :: SetClassLongW + + GetWindowLongPtrA :: GetWindowLongA + GetWindowLongPtrW :: GetWindowLongW + SetWindowLongPtrA :: GetWindowLongA + SetWindowLongPtrW :: GetWindowLongW +} + GET_SC_WPARAM :: #force_inline proc(wparam: WPARAM) -> i32 { return i32(wparam) & 0xFFF0 }