From 75cbb0974487cd9fee3762a0b2cd272a94402154 Mon Sep 17 00:00:00 2001 From: hikari Date: Fri, 1 Apr 2022 02:11:41 +0300 Subject: [PATCH 1/8] 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/8] 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/8] 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/8] 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/8] 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 } From c21c993646e91bba76ba9d350cbe1f9c42f18ff4 Mon Sep 17 00:00:00 2001 From: Jeroen van Rijn Date: Sat, 2 Apr 2022 01:54:35 +0200 Subject: [PATCH 6/8] [strings] fix. --- core/strings/strings.odin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/strings/strings.odin b/core/strings/strings.odin index d01be7989..8e774b367 100644 --- a/core/strings/strings.odin +++ b/core/strings/strings.odin @@ -1804,7 +1804,7 @@ fields_iterator :: proc(s: ^string) -> (field: string, ok: bool) { return "", false } - field = s[:len(s)] + field = s[start:] ok = true s^ = s[len(s):] return From 850d4a1e1b8abdc9c3a5f35a768529c93ba68eeb Mon Sep 17 00:00:00 2001 From: hikari Date: Sat, 2 Apr 2022 07:38:11 +0300 Subject: [PATCH 7/8] sys/windows: add a couple of procedures and types --- core/sys/windows/types.odin | 63 ++++++++++++++++++++++++++++++++++++ core/sys/windows/user32.odin | 5 +++ 2 files changed, 68 insertions(+) diff --git a/core/sys/windows/types.odin b/core/sys/windows/types.odin index d0551c6bf..e5e630c54 100644 --- a/core/sys/windows/types.odin +++ b/core/sys/windows/types.odin @@ -30,6 +30,7 @@ HBRUSH :: distinct HANDLE HGDIOBJ :: distinct HANDLE HBITMAP :: distinct HANDLE HGLOBAL :: distinct HANDLE +HHOOK :: distinct HANDLE BOOL :: distinct b32 BYTE :: distinct u8 BOOLEAN :: distinct b8 @@ -199,6 +200,24 @@ TIMERPROC :: #type proc "stdcall" (HWND, UINT, UINT_PTR, DWORD) WNDPROC :: #type proc "stdcall" (HWND, UINT, WPARAM, LPARAM) -> LRESULT +HOOKPROC :: #type proc "stdcall" (code: c_int, wParam: WPARAM, lParam: LPARAM) -> LRESULT + +CWPRETSTRUCT :: struct { + lResult: LRESULT, + lParam: LPARAM, + wParam: WPARAM, + message: UINT, + hwnd: HWND, +} + +KBDLLHOOKSTRUCT :: struct { + vkCode: DWORD, + scanCode: DWORD, + flags: DWORD, + time: DWORD, + dwExtraInfo: ULONG_PTR, +} + WNDCLASSA :: struct { style: UINT, lpfnWndProc: WNDPROC, @@ -698,6 +717,50 @@ HOVER_DEFAULT :: 0xFFFFFFFF USER_TIMER_MAXIMUM :: 0x7FFFFFFF USER_TIMER_MINIMUM :: 0x0000000A + +// SetWindowsHook() codes +WH_MIN :: -1 +WH_MSGFILTER :: -1 +WH_JOURNALRECORD :: 0 +WH_JOURNALPLAYBACK :: 1 +WH_KEYBOARD :: 2 +WH_GETMESSAGE :: 3 +WH_CALLWNDPROC :: 4 +WH_CBT :: 5 +WH_SYSMSGFILTER :: 6 +WH_MOUSE :: 7 +WH_HARDWARE :: 8 +WH_DEBUG :: 9 +WH_SHELL :: 10 +WH_FOREGROUNDIDLE :: 11 +WH_CALLWNDPROCRET :: 12 +WH_KEYBOARD_LL :: 13 +WH_MOUSE_LL :: 14 +WH_MAX :: 14 +WH_MINHOOK :: WH_MIN +WH_MAXHOOK :: WH_MAX + +// Hook Codes +HC_ACTION :: 0 +HC_GETNEXT :: 1 +HC_SKIP :: 2 +HC_NOREMOVE :: 3 +HC_NOREM :: HC_NOREMOVE +HC_SYSMODALON :: 4 +HC_SYSMODALOFF :: 5 + +// CBT Hook Codes +HCBT_MOVESIZE :: 0 +HCBT_MINMAX :: 1 +HCBT_QS :: 2 +HCBT_CREATEWND :: 3 +HCBT_DESTROYWND :: 4 +HCBT_ACTIVATE :: 5 +HCBT_CLICKSKIPPED :: 6 +HCBT_KEYSKIPPED :: 7 +HCBT_SYSCOMMAND :: 8 +HCBT_SETFOCUS :: 9 + _IDC_APPSTARTING := rawptr(uintptr(32650)) _IDC_ARROW := rawptr(uintptr(32512)) _IDC_CROSS := rawptr(uintptr(32515)) diff --git a/core/sys/windows/user32.odin b/core/sys/windows/user32.odin index 3985c9ad6..5b910ae73 100644 --- a/core/sys/windows/user32.odin +++ b/core/sys/windows/user32.odin @@ -131,6 +131,11 @@ foreign user32 { GetKeyState :: proc(nVirtKey: c_int) -> SHORT --- GetAsyncKeyState :: proc(vKey: c_int) -> SHORT --- + SetWindowsHookExA :: proc(idHook: c_int, lpfn: HOOKPROC, hmod: HINSTANCE, dwThreadId: DWORD) -> HHOOK --- + SetWindowsHookExW :: proc(idHook: c_int, lpfn: HOOKPROC, hmod: HINSTANCE, dwThreadId: DWORD) -> HHOOK --- + UnhookWindowsHookEx :: proc(hhk: HHOOK) -> BOOL --- + CallNextHookEx :: proc(hhk: HHOOK, nCode: c_int, wParam: WPARAM, lParam: LPARAM) -> LRESULT --- + SetTimer :: proc(hWnd: HWND, nIDEvent: UINT_PTR, uElapse: UINT, lpTimerFunc: TIMERPROC) -> UINT_PTR --- KillTimer :: proc(hWnd: HWND, uIDEvent: UINT_PTR) -> BOOL --- From 4c14e929527627a87b076b0433e95a7cdcf68f79 Mon Sep 17 00:00:00 2001 From: hikari Date: Sat, 2 Apr 2022 08:23:12 +0300 Subject: [PATCH 8/8] sys/windows: add several procedures and macros --- core/sys/windows/types.odin | 17 +++++++++++++++++ core/sys/windows/user32.odin | 23 +++++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/core/sys/windows/types.odin b/core/sys/windows/types.odin index e5e630c54..de19cd6cc 100644 --- a/core/sys/windows/types.odin +++ b/core/sys/windows/types.odin @@ -707,6 +707,23 @@ MK_MBUTTON :: 0x0010 MK_XBUTTON1 :: 0x0020 MK_XBUTTON2 :: 0x0040 +// Value for rolling one detent +WHEEL_DELTA :: 120 + +// Setting to scroll one page for SPI_GET/SETWHEELSCROLLLINES +WHEEL_PAGESCROLL :: max(UINT) + +// XButton values are WORD flags +XBUTTON1 :: 0x0001 +XBUTTON2 :: 0x0002 +// Were there to be an XBUTTON3, its value would be 0x0004 + +MAPVK_VK_TO_VSC :: 0 +MAPVK_VSC_TO_VK :: 1 +MAPVK_VK_TO_CHAR :: 2 +MAPVK_VSC_TO_VK_EX :: 3 +MAPVK_VK_TO_VSC_EX :: 4 + TME_HOVER :: 0x00000001 TME_LEAVE :: 0x00000002 TME_NONCLIENT :: 0x00000010 diff --git a/core/sys/windows/user32.odin b/core/sys/windows/user32.odin index 5b910ae73..2316d3363 100644 --- a/core/sys/windows/user32.odin +++ b/core/sys/windows/user32.odin @@ -131,6 +131,9 @@ foreign user32 { GetKeyState :: proc(nVirtKey: c_int) -> SHORT --- GetAsyncKeyState :: proc(vKey: c_int) -> SHORT --- + MapVirtualKeyA :: proc(uCode: UINT, uMapType: UINT) -> UINT --- + MapVirtualKeyW :: proc(uCode: UINT, uMapType: UINT) -> UINT --- + SetWindowsHookExA :: proc(idHook: c_int, lpfn: HOOKPROC, hmod: HINSTANCE, dwThreadId: DWORD) -> HHOOK --- SetWindowsHookExW :: proc(idHook: c_int, lpfn: HOOKPROC, hmod: HINSTANCE, dwThreadId: DWORD) -> HHOOK --- UnhookWindowsHookEx :: proc(hhk: HHOOK) -> BOOL --- @@ -228,6 +231,22 @@ when ODIN_ARCH == .amd64 { SetWindowLongPtrW :: GetWindowLongW } -GET_SC_WPARAM :: #force_inline proc(wparam: WPARAM) -> i32 { - return i32(wparam) & 0xFFF0 +GET_SC_WPARAM :: #force_inline proc "contextless" (wParam: WPARAM) -> c_int { + return c_int(wParam) & 0xFFF0 +} + +GET_WHEEL_DELTA_WPARAM :: #force_inline proc "contextless" (wParam: WPARAM) -> c_short { + return cast(c_short)HIWORD(cast(DWORD)wParam) +} + +GET_KEYSTATE_WPARAM :: #force_inline proc "contextless" (wParam: WPARAM) -> WORD { + return LOWORD(cast(DWORD)wParam) +} + +GET_NCHITTEST_WPARAM :: #force_inline proc "contextless" (wParam: WPARAM) -> c_short { + return cast(c_short)LOWORD(cast(DWORD)wParam) +} + +GET_XBUTTON_WPARAM :: #force_inline proc "contextless" (wParam: WPARAM) -> WORD { + return HIWORD(cast(DWORD)wParam) }