user32.odin 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. // +build windows
  2. package sys_windows
  3. foreign import user32 "system:User32.lib"
  4. @(default_calling_convention="stdcall")
  5. foreign user32 {
  6. GetClassInfoW :: proc(hInstance: HINSTANCE, lpClassNAme: LPCWSTR, lpWndClass: ^WNDCLASSW) -> BOOL ---
  7. GetClassInfoExW :: proc(hInsatnce: HINSTANCE, lpszClass: LPCWSTR, lpwcx: ^WNDCLASSEXW) -> BOOL ---
  8. GetClassLongW :: proc(hWnd: HWND, nIndex: c_int) -> DWORD ---
  9. SetClassLongW :: proc(hWnd: HWND, nIndex: c_int, dwNewLong: LONG) -> DWORD ---
  10. GetWindowLongW :: proc(hWnd: HWND, nIndex: c_int) -> LONG ---
  11. SetWindowLongW :: proc(hWnd: HWND, nIndex: c_int, dwNewLong: LONG) -> LONG ---
  12. GetClassNameW :: proc(hWnd: HWND, lpClassName: LPWSTR, nMaxCount: c_int) -> c_int ---
  13. RegisterClassW :: proc(lpWndClass: ^WNDCLASSW) -> ATOM ---
  14. RegisterClassExW :: proc(^WNDCLASSEXW) -> ATOM ---
  15. CreateWindowExW :: proc(
  16. dwExStyle: DWORD,
  17. lpClassName: LPCWSTR,
  18. lpWindowName: LPCWSTR,
  19. dwStyle: DWORD,
  20. X: c_int,
  21. Y: c_int,
  22. nWidth: c_int,
  23. nHeight: c_int,
  24. hWndParent: HWND,
  25. hMenu: HMENU,
  26. hInstance: HINSTANCE,
  27. lpParam: LPVOID,
  28. ) -> HWND ---
  29. DestroyWindow :: proc(hWnd: HWND) -> BOOL ---
  30. ShowWindow :: proc(hWnd: HWND, nCmdShow: c_int) -> BOOL ---
  31. BringWindowToTop :: proc(hWnd: HWND) -> BOOL ---
  32. GetTopWindow :: proc(hWnd: HWND) -> HWND ---
  33. SetForegroundWindow :: proc(hWnd: HWND) -> BOOL ---
  34. GetForegroundWindow :: proc() -> HWND ---
  35. SetActiveWindow :: proc(hWnd: HWND) -> HWND ---
  36. GetActiveWindow :: proc() -> HWND ---
  37. GetMessageW :: proc(lpMsg: ^MSG, hWnd: HWND, wMsgFilterMin: UINT, wMsgFilterMax: UINT) -> BOOL ---
  38. TranslateMessage :: proc(lpMsg: ^MSG) -> BOOL ---
  39. DispatchMessageW :: proc(lpMsg: ^MSG) -> LRESULT ---
  40. PeekMessageA :: proc(lpMsg: ^MSG, hWnd: HWND, wMsgFilterMin: UINT, wMsgFilterMax: UINT, wRemoveMsg: UINT) -> BOOL ---
  41. PeekMessageW :: proc(lpMsg: ^MSG, hWnd: HWND, wMsgFilterMin: UINT, wMsgFilterMax: UINT, wRemoveMsg: UINT) -> BOOL ---
  42. PostMessageA :: proc(hWnd: HWND, Msg: UINT, wParam: WPARAM, lParam: LPARAM) -> BOOL ---
  43. PostMessageW :: proc(hWnd: HWND, Msg: UINT, wParam: WPARAM, lParam: LPARAM) -> BOOL ---
  44. SendMessageA :: proc(hWnd: HWND, Msg: UINT, wParam: WPARAM, lParam: LPARAM) -> LRESULT ---
  45. SendMessageW :: proc(hWnd: HWND, Msg: UINT, wParam: WPARAM, lParam: LPARAM) -> LRESULT ---
  46. PostThreadMessageA :: proc(idThread: DWORD, Msg: UINT, wParam: WPARAM, lParam: LPARAM) -> BOOL ---
  47. PostThreadMessageW :: proc(idThread: DWORD, Msg: UINT, wParam: WPARAM, lParam: LPARAM) -> BOOL ---
  48. PostQuitMessage :: proc(nExitCode: c_int) ---
  49. GetQueueStatus :: proc(flags: UINT) -> DWORD ---
  50. DefWindowProcA :: proc(hWnd: HWND, Msg: UINT, wParam: WPARAM, lParam: LPARAM) -> LRESULT ---
  51. DefWindowProcW :: proc(hWnd: HWND, Msg: UINT, wParam: WPARAM, lParam: LPARAM) -> LRESULT ---
  52. FindWindowA :: proc(lpClassName: LPCSTR, lpWindowName: LPCSTR) -> HWND ---
  53. FindWindowW :: proc(lpClassName: LPCWSTR, lpWindowName: LPCWSTR) -> HWND ---
  54. FindWindowExA :: proc(hWndParent: HWND, hWndChildAfter: HWND, lpszClass: LPCSTR, lpszWindow: LPCSTR) -> HWND ---
  55. FindWindowExW :: proc(hWndParent: HWND, hWndChildAfter: HWND, lpszClass: LPCWSTR, lpszWindow: LPCWSTR) -> HWND ---
  56. LoadIconA :: proc(hInstance: HINSTANCE, lpIconName: LPCSTR) -> HICON ---
  57. LoadIconW :: proc(hInstance: HINSTANCE, lpIconName: LPCWSTR) -> HICON ---
  58. LoadCursorA :: proc(hInstance: HINSTANCE, lpCursorName: LPCSTR) -> HCURSOR ---
  59. LoadCursorW :: proc(hInstance: HINSTANCE, lpCursorName: LPCWSTR) -> HCURSOR ---
  60. GetWindowRect :: proc(hWnd: HWND, lpRect: LPRECT) -> BOOL ---
  61. GetClientRect :: proc(hWnd: HWND, lpRect: LPRECT) -> BOOL ---
  62. ClientToScreen :: proc(hWnd: HWND, lpPoint: LPPOINT) -> BOOL ---
  63. ScreenToClient :: proc(hWnd: HWND, lpPoint: LPPOINT) -> BOOL ---
  64. SetWindowPos :: proc(
  65. hWnd: HWND,
  66. hWndInsertAfter: HWND,
  67. X: c_int,
  68. Y: c_int,
  69. cx: c_int,
  70. cy: c_int,
  71. uFlags: UINT,
  72. ) -> BOOL ---
  73. MoveWindow :: proc(hWnd: HWND, X, Y, hWidth, hHeight: c_int, bRepaint: BOOL) -> BOOL ---
  74. GetSystemMetrics :: proc(nIndex: c_int) -> c_int ---
  75. AdjustWindowRect :: proc(lpRect: LPRECT, dwStyle: DWORD, bMenu: BOOL) -> BOOL ---
  76. AdjustWindowRectEx :: proc(lpRect: LPRECT, dwStyle: DWORD, bMenu: BOOL, dwExStyle: DWORD) -> BOOL ---
  77. SystemParametersInfoW :: proc(uiAction, uiParam: UINT, pvParam: PVOID, fWinIni: UINT) -> BOOL ---
  78. GetWindowDC :: proc(hWnd: HWND) -> HDC ---
  79. GetDC :: proc(hWnd: HWND) -> HDC ---
  80. ReleaseDC :: proc(hWnd: HWND, hDC: HDC) -> c_int ---
  81. GetUpdateRect :: proc(hWnd: HWND, lpRect: LPRECT, bErase: BOOL) -> BOOL ---
  82. ValidateRect :: proc(hWnd: HWND, lpRect: ^RECT) -> BOOL ---
  83. InvalidateRect :: proc(hWnd: HWND, lpRect: ^RECT, bErase: BOOL) -> BOOL ---
  84. BeginPaint :: proc(hWnd: HWND, lpPaint: ^PAINTSTRUCT) -> HDC ---
  85. EndPaint :: proc(hWnd: HWND, lpPaint: ^PAINTSTRUCT) -> BOOL ---
  86. GetCapture :: proc() -> HWND ---
  87. SetCapture :: proc(hWnd: HWND) -> HWND ---
  88. ReleaseCapture :: proc() -> BOOL ---
  89. TrackMouseEvent :: proc(lpEventTrack: LPTRACKMOUSEEVENT) -> BOOL ---
  90. GetKeyState :: proc(nVirtKey: c_int) -> SHORT ---
  91. GetAsyncKeyState :: proc(vKey: c_int) -> SHORT ---
  92. MapVirtualKeyW :: proc(uCode: UINT, uMapType: UINT) -> UINT ---
  93. SetWindowsHookExW :: proc(idHook: c_int, lpfn: HOOKPROC, hmod: HINSTANCE, dwThreadId: DWORD) -> HHOOK ---
  94. UnhookWindowsHookEx :: proc(hhk: HHOOK) -> BOOL ---
  95. CallNextHookEx :: proc(hhk: HHOOK, nCode: c_int, wParam: WPARAM, lParam: LPARAM) -> LRESULT ---
  96. SetTimer :: proc(hWnd: HWND, nIDEvent: UINT_PTR, uElapse: UINT, lpTimerFunc: TIMERPROC) -> UINT_PTR ---
  97. KillTimer :: proc(hWnd: HWND, uIDEvent: UINT_PTR) -> BOOL ---
  98. // MessageBoxA :: proc(hWnd: HWND, lpText: LPCSTR, lpCaption: LPCSTR, uType: UINT) -> c_int ---
  99. MessageBoxW :: proc(hWnd: HWND, lpText: LPCWSTR, lpCaption: LPCWSTR, uType: UINT) -> c_int ---
  100. // MessageBoxExA :: proc(hWnd: HWND, lpText: LPCSTR, lpCaption: LPCSTR, uType: UINT, wLanguageId: WORD) -> c_int ---
  101. MessageBoxExW :: proc(hWnd: HWND, lpText: LPCWSTR, lpCaption: LPCWSTR, uType: UINT, wLanguageId: WORD) -> c_int ---
  102. ClipCursor :: proc(lpRect: LPRECT) -> BOOL ---
  103. GetCursorPos :: proc(lpPoint: LPPOINT) -> BOOL ---
  104. SetCursorPos :: proc(X: c_int, Y: c_int) -> BOOL ---
  105. SetCursor :: proc(hCursor: HCURSOR) -> HCURSOR ---
  106. }
  107. CreateWindowW :: #force_inline proc "stdcall" (
  108. lpClassName: LPCTSTR,
  109. lpWindowName: LPCTSTR,
  110. dwStyle: DWORD,
  111. X: c_int,
  112. Y: c_int,
  113. nWidth: c_int,
  114. nHeight: c_int,
  115. hWndParent: HWND,
  116. hMenu: HMENU,
  117. hInstance: HINSTANCE,
  118. lpParam: LPVOID,
  119. ) -> HWND {
  120. return CreateWindowExW(
  121. 0,
  122. lpClassName,
  123. lpWindowName,
  124. dwStyle,
  125. X,
  126. Y,
  127. nWidth,
  128. nHeight,
  129. hWndParent,
  130. hMenu,
  131. hInstance,
  132. lpParam,
  133. )
  134. }
  135. when ODIN_ARCH == .amd64 {
  136. @(default_calling_convention="stdcall")
  137. foreign user32 {
  138. GetClassLongPtrW :: proc(hWnd: HWND, nIndex: c_int) -> ULONG_PTR ---
  139. SetClassLongPtrW :: proc(hWnd: HWND, nIndex: c_int, dwNewLong: LONG_PTR) -> ULONG_PTR ---
  140. GetWindowLongPtrW :: proc(hWnd: HWND, nIndex: c_int) -> LONG_PTR ---
  141. SetWindowLongPtrW :: proc(hWnd: HWND, nIndex: c_int, dwNewLong: LONG_PTR) -> LONG_PTR ---
  142. }
  143. } else when ODIN_ARCH == .i386 {
  144. GetClassLongPtrW :: GetClassLongW
  145. SetClassLongPtrW :: SetClassLongW
  146. GetWindowLongPtrW :: GetWindowLongW
  147. SetWindowLongPtrW :: GetWindowLongW
  148. }
  149. GET_SC_WPARAM :: #force_inline proc "contextless" (wParam: WPARAM) -> c_int {
  150. return c_int(wParam) & 0xFFF0
  151. }
  152. GET_WHEEL_DELTA_WPARAM :: #force_inline proc "contextless" (wParam: WPARAM) -> c_short {
  153. return cast(c_short)HIWORD(cast(DWORD)wParam)
  154. }
  155. GET_KEYSTATE_WPARAM :: #force_inline proc "contextless" (wParam: WPARAM) -> WORD {
  156. return LOWORD(cast(DWORD)wParam)
  157. }
  158. GET_NCHITTEST_WPARAM :: #force_inline proc "contextless" (wParam: WPARAM) -> c_short {
  159. return cast(c_short)LOWORD(cast(DWORD)wParam)
  160. }
  161. GET_XBUTTON_WPARAM :: #force_inline proc "contextless" (wParam: WPARAM) -> WORD {
  162. return HIWORD(cast(DWORD)wParam)
  163. }