user32.odin 9.0 KB

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