diff --git a/lib/std/core/env.c3 b/lib/std/core/env.c3 index 9261ef4a0..4b6ee4605 100644 --- a/lib/std/core/env.c3 +++ b/lib/std/core/env.c3 @@ -116,6 +116,8 @@ enum ArchType const OsType OS_TYPE = (OsType)$$OS_TYPE; const ArchType ARCH_TYPE = (ArchType)$$ARCH_TYPE; +const bool ARCH_32_BIT = $$REGISTER_SIZE == 4; +const bool ARCH_64_BIT = $$REGISTER_SIZE == 8; const bool LIBC = $$COMPILER_LIBC_AVAILABLE; const bool NO_LIBC = !$$COMPILER_LIBC_AVAILABLE; const CompilerOptLevel COMPILER_OPT_LEVEL = (CompilerOptLevel)$$COMPILER_OPT_LEVEL; diff --git a/lib/std/os/win32/process.c3 b/lib/std/os/win32/process.c3 index f03d34f13..2c6aa80f3 100644 --- a/lib/std/os/win32/process.c3 +++ b/lib/std/os/win32/process.c3 @@ -53,15 +53,17 @@ extern fn Win32_BOOL releaseMutex(Win32_HANDLE) @extern("ReleaseMutex"); extern fn void enterCriticalSection(Win32_CRITICAL_SECTION* section) @extern("EnterCriticalSection"); extern fn void leaveCriticalSection(Win32_CRITICAL_SECTION* section) @extern("LeaveCriticalSection"); extern fn Win32_BOOL tryEnterCriticalSection(Win32_CRITICAL_SECTION* section) @extern("TryEnterCriticalSection"); -extern fn uint waitForSingleObject(Win32_HANDLE, uint milliseconds) @extern("WaitForSingleObject"); +extern fn Win32_DWORD waitForSingleObject(Win32_HANDLE hHandle, Win32_DWORD dwMilliseconds) @extern("WaitForSingleObject"); +extern fn Win32_DWORD waitForSingleObjectEx(Win32_HANDLE hHandle, Win32_DWORD dwMilliseconds, Win32_BOOL bAlertable) @extern("WaitForSingleObjectEx"); +extern fn Win32_DWORD waitForMultipleObjects(Win32_DWORD nCount, Win32_HANDLE* lpHandles, Win32_BOOL bWaitAll, Win32_DWORD dwMilliseconds) @extern("WaitForMultipleObjects"); +extern fn Win32_DWORD waitForMultipleObjectsEx(Win32_DWORD nCount, Win32_HANDLE* lpHandles, Win32_BOOL bWaitAll, Win32_DWORD dwMilliseconds, Win32_BOOL bAlertable) @extern("WaitForMultipleObjectsEx"); extern fn void sleep(uint ms) @extern("Sleep"); -extern fn uint waitForMultipleObjects(uint count, Win32_HANDLE* handles, Win32_BOOL wait_all, uint ms) @extern("WaitForMultipleObjects"); extern fn Win32_BOOL resetEvent(Win32_HANDLE event) @extern("ResetEvent"); extern fn Win32_BOOL setEvent(Win32_HANDLE handle) @extern("SetEvent"); extern fn long interlockedCompareExchange(int* dest, int exchange, int comperand) @extern("InterlockedCompareExchange"); extern fn Win32_DWORD sleepEx(Win32_DWORD ms, Win32_BOOL alertable) @extern("SleepEx"); -extern fn Win32_HANDLE createThread(void* attributes, usz stack, ThreadFn func, void* arg, uint flags, uint* thread_id) @extern("CreateThread"); -extern fn Win32_BOOL getExitCodeThread(Win32_HANDLE handle, uint* exit_code) @extern("GetExitCodeThread"); +extern fn Win32_HANDLE createThread(void* attributes, usz stack, ThreadFn func, Win32_LPVOID arg, Win32_DWORD flags, Win32_LPDWORD thread_id) @extern("CreateThread"); +extern fn Win32_BOOL getExitCodeThread(Win32_HANDLE handle, Win32_LPDWORD exit_code) @extern("GetExitCodeThread"); extern fn Win32_BOOL getExitCodeProcess(Win32_HANDLE hProcess, Win32_LPDWORD lpExitCode) @extern("GetExitCodeProcess"); extern fn Win32_DWORD getThreadId(Win32_HANDLE) @extern("GetThreadId"); extern fn void exitThread(Win32_DWORD dwExitCode) @noreturn @extern("ExitThread"); diff --git a/lib/std/os/win32/winuser.c3 b/lib/std/os/win32/winuser.c3 index 93f3fd4bb..e8cca491d 100644 --- a/lib/std/os/win32/winuser.c3 +++ b/lib/std/os/win32/winuser.c3 @@ -80,18 +80,69 @@ const Win32_DWORD WS_TILEDWINDOW = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU const Win32_DWORD WS_VISIBLE = 0x10000000L; const Win32_DWORD WS_VSCROLL = 0x00200000L; +const Win32_UINT MB_OK = 0x00000000; +const Win32_UINT MB_OKCANCEL = 0x00000001; +const Win32_UINT MB_ABORTRETRYIGNORE = 0x00000002; +const Win32_UINT MB_YESNOCANCEL = 0x00000003; +const Win32_UINT MB_YESNO = 0x00000004; +const Win32_UINT MB_RETRYCANCEL = 0x00000005; +const Win32_UINT MB_CANCELTRYCONTINUE = 0x00000006; +const Win32_UINT MB_ICONHAND = 0x00000010; +const Win32_UINT MB_ICONQUESTION = 0x00000020; +const Win32_UINT MB_ICONEXCLAMATION = 0x00000030; +const Win32_UINT MB_ICONASTERISK = 0x00000040; +const Win32_UINT MB_USERICON = 0x00000080; +const Win32_UINT MB_ICONWARNING = MB_ICONEXCLAMATION; +const Win32_UINT MB_ICONERROR = MB_ICONHAND; +const Win32_UINT MB_ICONINFORMATION = MB_ICONASTERISK; +const Win32_UINT MB_ICONSTOP = MB_ICONHAND; + +const GWL_WNDPROC @if(env::ARCH_32_BIT) = -4; +const GWL_HINSTANCE @if(env::ARCH_32_BIT) = -6; +const GWL_HWNDPARENT @if(env::ARCH_32_BIT) = -8; +const GWL_STYLE = -16; +const GWL_EXSTYLE = -20; +const GWL_USERDATA @if(env::ARCH_32_BIT) = -21; +const GWL_ID = -12; +const GWLP_WNDPROC = -4; +const GWLP_HINSTANCE = -6; +const GWLP_HWNDPARENT = -8; +const GWLP_USERDATA = -21; +const GWLP_ID = -12; + extern fn Win32_HDC beginPaint(Win32_HWND, Win32_LPPAINTSTRUCT) @extern("BeginPaint"); +extern fn Win32_LRESULT callWindowProcW(Win32_WNDPROC lpPrevWndFunc, Win32_HWND hWnd, Win32_UINT msg, Win32_WPARAM wParam, Win32_LPARAM lParam) @extern("CallWindowProcW"); extern fn Win32_HWND createWindowExW(Win32_DWORD, Win32_LPCWSTR, Win32_LPCWSTR, Win32_DWORD, CInt, CInt, CInt, CInt, Win32_HWND, Win32_HMENU, Win32_HINSTANCE, Win32_LPVOID) @extern("CreateWindowExW"); extern fn Win32_LRESULT defWindowProcW(Win32_HWND, Win32_UINT, Win32_WPARAM, Win32_LPARAM) @extern("DefWindowProcW"); extern fn Win32_BOOL dispatchMessage(Win32_MSG* lpMsg) @extern("DispatchMessageW"); extern fn Win32_BOOL endPaint(Win32_HWND, Win32_LPPAINTSTRUCT) @extern("EndPaint"); extern fn Win32_BOOL getMessageW(Win32_LPMSG, Win32_HWND, Win32_UINT, Win32_UINT) @extern("GetMessageW"); +extern fn Win32_BOOL getUpdateRect(Win32_HWND hWnd, Win32_LPRECT lpRect, Win32_BOOL bErase) @extern("GetUpdateRect"); +extern fn Win32_LONG_PTR getWindowLongPtrW(Win32_HWND hWnd, CInt nIndex) @extern("GetWindowLongPtrW"); +extern fn Win32_LONG getWindowLongW(Win32_HWND hWnd, CInt nIndex) @extern("GetWindowLongW"); extern fn Win32_HCURSOR loadCursorW(Win32_HINSTANCE instance, Win32_LPCWSTR cursorName) @extern("LoadCursorW"); extern fn Win32_HICON loadIconW(Win32_HINSTANCE instance, Win32_LPCWSTR iconName) @extern("LoadIconW"); extern fn int messageBoxW(Win32_HWND hWnd, Win32_LPCWSTR lpText, Win32_LPCWSTR lpCaption, Win32_UINT uType) @extern("MessageBoxW"); extern fn void postQuitMessage(CInt) @extern("PostQuitMessage"); extern fn Win32_ATOM registerClassExW(Win32_WNDCLASSEXW*) @extern("RegisterClassExW"); +extern fn Win32_LONG_PTR setWindowLongPtrW(Win32_HWND hWnd, CInt nIndex, Win32_LONG_PTR dwNewLong) @extern("SetWindowLongPtrW"); +extern fn Win32_LONG setWindowLongW(Win32_HWND hWnd, CInt nIndex, Win32_LONG dwNewLong) @extern("SetWindowLongW"); extern fn Win32_BOOL showWindow(Win32_HWND, CInt) @extern("ShowWindow"); extern fn Win32_BOOL translateMessage(Win32_MSG* lpMsg) @extern("TranslateMessage"); extern fn Win32_BOOL updateWindow(Win32_HWND) @extern("UpdateWindow"); +macro getWindowLongPtr(Win32_HWND hWnd, CInt nIndex) { + $if env::ARCH_64_BIT: + return getWindowLongPtrW(hWnd, nIndex); + $else + return getWindowLongW(hWnd, nIndex); + $endif +} + +macro setWindowLongPtr(Win32_HWND hWnd, CInt nIndex, dwNewLong) { + $if env::ARCH_64_BIT: + return setWindowLongPtrW(hWnd, nIndex, dwNewLong); + $else + return setWindowLongW(hWnd, nIndex, dwNewLong); + $endif +}