user32.odin 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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. EnumDisplaySettingsW :: proc(lpszDeviceName: LPCWSTR, iModeNum: DWORD, lpDevMode: ^DEVMODEW) -> BOOL ---
  107. BroadcastSystemMessageW :: proc(
  108. flags: DWORD,
  109. lpInfo: LPDWORD,
  110. Msg: UINT,
  111. wParam: WPARAM,
  112. lParam: LPARAM,
  113. ) -> c_long ---
  114. BroadcastSystemMessageExW :: proc(
  115. flags: DWORD,
  116. lpInfo: LPDWORD,
  117. Msg: UINT,
  118. wParam: WPARAM,
  119. lParam: LPARAM,
  120. pbsmInfo: PBSMINFO,
  121. ) -> c_long ---
  122. SendMessageTimeoutW :: proc(
  123. hWnd: HWND,
  124. Msg: UINT,
  125. wParam: WPARAM,
  126. lParam: LPARAM,
  127. fuFlags: UINT,
  128. uTimeout: UINT,
  129. lpdwResult: PDWORD_PTR,
  130. ) -> LRESULT ---
  131. GetSysColor :: proc(nIndex: c_int) -> DWORD ---
  132. GetSysColorBrush :: proc(nIndex: c_int) -> HBRUSH ---
  133. SetSysColors :: proc(cElements: c_int, lpaElements: ^INT, lpaRgbValues: ^COLORREF) -> BOOL ---
  134. MessageBeep :: proc(uType: UINT) -> BOOL ---
  135. IsDialogMessageW :: proc(hDlg: HWND, lpMsg: LPMSG) -> BOOL ---
  136. GetWindowTextLengthW :: proc(hWnd: HWND) -> c_int ---
  137. GetWindowTextW :: proc(hWnd: HWND, lpString: LPWSTR, nMaxCount: c_int) -> c_int ---
  138. SetWindowTextW :: proc(hWnd: HWND, lpString: LPCWSTR) -> BOOL ---
  139. CallWindowProcW :: proc(lpPrevWndFunc: WNDPROC, hWnd: HWND, Msg: UINT, wParam: WPARAM, lParam: LPARAM) -> LRESULT ---
  140. EnableWindow :: proc(hWnd: HWND, bEnable: BOOL) -> BOOL ---
  141. }
  142. CreateWindowW :: #force_inline proc "stdcall" (
  143. lpClassName: LPCTSTR,
  144. lpWindowName: LPCTSTR,
  145. dwStyle: DWORD,
  146. X: c_int,
  147. Y: c_int,
  148. nWidth: c_int,
  149. nHeight: c_int,
  150. hWndParent: HWND,
  151. hMenu: HMENU,
  152. hInstance: HINSTANCE,
  153. lpParam: LPVOID,
  154. ) -> HWND {
  155. return CreateWindowExW(
  156. 0,
  157. lpClassName,
  158. lpWindowName,
  159. dwStyle,
  160. X,
  161. Y,
  162. nWidth,
  163. nHeight,
  164. hWndParent,
  165. hMenu,
  166. hInstance,
  167. lpParam,
  168. )
  169. }
  170. when ODIN_ARCH == .amd64 {
  171. @(default_calling_convention="stdcall")
  172. foreign user32 {
  173. GetClassLongPtrW :: proc(hWnd: HWND, nIndex: c_int) -> ULONG_PTR ---
  174. SetClassLongPtrW :: proc(hWnd: HWND, nIndex: c_int, dwNewLong: LONG_PTR) -> ULONG_PTR ---
  175. GetWindowLongPtrW :: proc(hWnd: HWND, nIndex: c_int) -> LONG_PTR ---
  176. SetWindowLongPtrW :: proc(hWnd: HWND, nIndex: c_int, dwNewLong: LONG_PTR) -> LONG_PTR ---
  177. }
  178. } else when ODIN_ARCH == .i386 {
  179. GetClassLongPtrW :: GetClassLongW
  180. SetClassLongPtrW :: SetClassLongW
  181. GetWindowLongPtrW :: GetWindowLongW
  182. SetWindowLongPtrW :: GetWindowLongW
  183. }
  184. GET_SC_WPARAM :: #force_inline proc "contextless" (wParam: WPARAM) -> c_int {
  185. return c_int(wParam) & 0xFFF0
  186. }
  187. GET_WHEEL_DELTA_WPARAM :: #force_inline proc "contextless" (wParam: WPARAM) -> c_short {
  188. return cast(c_short)HIWORD(cast(DWORD)wParam)
  189. }
  190. GET_KEYSTATE_WPARAM :: #force_inline proc "contextless" (wParam: WPARAM) -> WORD {
  191. return LOWORD(cast(DWORD)wParam)
  192. }
  193. GET_NCHITTEST_WPARAM :: #force_inline proc "contextless" (wParam: WPARAM) -> c_short {
  194. return cast(c_short)LOWORD(cast(DWORD)wParam)
  195. }
  196. GET_XBUTTON_WPARAM :: #force_inline proc "contextless" (wParam: WPARAM) -> WORD {
  197. return HIWORD(cast(DWORD)wParam)
  198. }
  199. MAKEINTRESOURCEW :: #force_inline proc "contextless" (#any_int i: int) -> LPWSTR {
  200. return cast(LPWSTR)uintptr(WORD(i))
  201. }