user32.odin 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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. UnregisterClassW :: proc(lpClassName: LPCWSTR, hInstance: HINSTANCE) -> BOOL ---
  16. CreateWindowExW :: proc(
  17. dwExStyle: DWORD,
  18. lpClassName: LPCWSTR,
  19. lpWindowName: LPCWSTR,
  20. dwStyle: DWORD,
  21. X: c_int,
  22. Y: c_int,
  23. nWidth: c_int,
  24. nHeight: c_int,
  25. hWndParent: HWND,
  26. hMenu: HMENU,
  27. hInstance: HINSTANCE,
  28. lpParam: LPVOID,
  29. ) -> HWND ---
  30. DestroyWindow :: proc(hWnd: HWND) -> BOOL ---
  31. ShowWindow :: proc(hWnd: HWND, nCmdShow: c_int) -> BOOL ---
  32. BringWindowToTop :: proc(hWnd: HWND) -> BOOL ---
  33. GetTopWindow :: proc(hWnd: HWND) -> HWND ---
  34. SetForegroundWindow :: proc(hWnd: HWND) -> BOOL ---
  35. GetForegroundWindow :: proc() -> HWND ---
  36. SetActiveWindow :: proc(hWnd: HWND) -> HWND ---
  37. GetActiveWindow :: proc() -> HWND ---
  38. GetMessageW :: proc(lpMsg: ^MSG, hWnd: HWND, wMsgFilterMin: UINT, wMsgFilterMax: UINT) -> BOOL ---
  39. TranslateMessage :: proc(lpMsg: ^MSG) -> BOOL ---
  40. DispatchMessageW :: proc(lpMsg: ^MSG) -> LRESULT ---
  41. PeekMessageA :: proc(lpMsg: ^MSG, hWnd: HWND, wMsgFilterMin: UINT, wMsgFilterMax: UINT, wRemoveMsg: UINT) -> BOOL ---
  42. PeekMessageW :: proc(lpMsg: ^MSG, hWnd: HWND, wMsgFilterMin: UINT, wMsgFilterMax: UINT, wRemoveMsg: UINT) -> BOOL ---
  43. PostMessageA :: proc(hWnd: HWND, Msg: UINT, wParam: WPARAM, lParam: LPARAM) -> BOOL ---
  44. PostMessageW :: proc(hWnd: HWND, Msg: UINT, wParam: WPARAM, lParam: LPARAM) -> BOOL ---
  45. SendMessageA :: proc(hWnd: HWND, Msg: UINT, wParam: WPARAM, lParam: LPARAM) -> LRESULT ---
  46. SendMessageW :: proc(hWnd: HWND, Msg: UINT, wParam: WPARAM, lParam: LPARAM) -> LRESULT ---
  47. PostThreadMessageA :: proc(idThread: DWORD, Msg: UINT, wParam: WPARAM, lParam: LPARAM) -> BOOL ---
  48. PostThreadMessageW :: proc(idThread: DWORD, Msg: UINT, wParam: WPARAM, lParam: LPARAM) -> BOOL ---
  49. PostQuitMessage :: proc(nExitCode: c_int) ---
  50. GetQueueStatus :: proc(flags: UINT) -> DWORD ---
  51. DefWindowProcA :: proc(hWnd: HWND, Msg: UINT, wParam: WPARAM, lParam: LPARAM) -> LRESULT ---
  52. DefWindowProcW :: proc(hWnd: HWND, Msg: UINT, wParam: WPARAM, lParam: LPARAM) -> LRESULT ---
  53. FindWindowA :: proc(lpClassName: LPCSTR, lpWindowName: LPCSTR) -> HWND ---
  54. FindWindowW :: proc(lpClassName: LPCWSTR, lpWindowName: LPCWSTR) -> HWND ---
  55. FindWindowExA :: proc(hWndParent: HWND, hWndChildAfter: HWND, lpszClass: LPCSTR, lpszWindow: LPCSTR) -> HWND ---
  56. FindWindowExW :: proc(hWndParent: HWND, hWndChildAfter: HWND, lpszClass: LPCWSTR, lpszWindow: LPCWSTR) -> HWND ---
  57. LoadIconA :: proc(hInstance: HINSTANCE, lpIconName: LPCSTR) -> HICON ---
  58. LoadIconW :: proc(hInstance: HINSTANCE, lpIconName: LPCWSTR) -> HICON ---
  59. LoadCursorA :: proc(hInstance: HINSTANCE, lpCursorName: LPCSTR) -> HCURSOR ---
  60. LoadCursorW :: proc(hInstance: HINSTANCE, lpCursorName: LPCWSTR) -> HCURSOR ---
  61. GetWindowRect :: proc(hWnd: HWND, lpRect: LPRECT) -> BOOL ---
  62. GetClientRect :: proc(hWnd: HWND, lpRect: LPRECT) -> BOOL ---
  63. ClientToScreen :: proc(hWnd: HWND, lpPoint: LPPOINT) -> BOOL ---
  64. ScreenToClient :: proc(hWnd: HWND, lpPoint: LPPOINT) -> BOOL ---
  65. SetWindowPos :: proc(
  66. hWnd: HWND,
  67. hWndInsertAfter: HWND,
  68. X: c_int,
  69. Y: c_int,
  70. cx: c_int,
  71. cy: c_int,
  72. uFlags: UINT,
  73. ) -> BOOL ---
  74. MoveWindow :: proc(hWnd: HWND, X, Y, hWidth, hHeight: c_int, bRepaint: BOOL) -> BOOL ---
  75. GetSystemMetrics :: proc(nIndex: c_int) -> c_int ---
  76. AdjustWindowRect :: proc(lpRect: LPRECT, dwStyle: DWORD, bMenu: BOOL) -> BOOL ---
  77. AdjustWindowRectEx :: proc(lpRect: LPRECT, dwStyle: DWORD, bMenu: BOOL, dwExStyle: DWORD) -> BOOL ---
  78. SystemParametersInfoW :: proc(uiAction, uiParam: UINT, pvParam: PVOID, fWinIni: UINT) -> BOOL ---
  79. GetWindowDC :: proc(hWnd: HWND) -> HDC ---
  80. GetDC :: proc(hWnd: HWND) -> HDC ---
  81. ReleaseDC :: proc(hWnd: HWND, hDC: HDC) -> c_int ---
  82. GetUpdateRect :: proc(hWnd: HWND, lpRect: LPRECT, bErase: BOOL) -> BOOL ---
  83. ValidateRect :: proc(hWnd: HWND, lpRect: ^RECT) -> BOOL ---
  84. InvalidateRect :: proc(hWnd: HWND, lpRect: ^RECT, bErase: BOOL) -> BOOL ---
  85. BeginPaint :: proc(hWnd: HWND, lpPaint: ^PAINTSTRUCT) -> HDC ---
  86. EndPaint :: proc(hWnd: HWND, lpPaint: ^PAINTSTRUCT) -> BOOL ---
  87. GetCapture :: proc() -> HWND ---
  88. SetCapture :: proc(hWnd: HWND) -> HWND ---
  89. ReleaseCapture :: proc() -> BOOL ---
  90. TrackMouseEvent :: proc(lpEventTrack: LPTRACKMOUSEEVENT) -> BOOL ---
  91. GetKeyState :: proc(nVirtKey: c_int) -> SHORT ---
  92. GetAsyncKeyState :: proc(vKey: c_int) -> SHORT ---
  93. MapVirtualKeyW :: proc(uCode: UINT, uMapType: UINT) -> UINT ---
  94. SetWindowsHookExW :: proc(idHook: c_int, lpfn: HOOKPROC, hmod: HINSTANCE, dwThreadId: DWORD) -> HHOOK ---
  95. UnhookWindowsHookEx :: proc(hhk: HHOOK) -> BOOL ---
  96. CallNextHookEx :: proc(hhk: HHOOK, nCode: c_int, wParam: WPARAM, lParam: LPARAM) -> LRESULT ---
  97. SetTimer :: proc(hWnd: HWND, nIDEvent: UINT_PTR, uElapse: UINT, lpTimerFunc: TIMERPROC) -> UINT_PTR ---
  98. KillTimer :: proc(hWnd: HWND, uIDEvent: UINT_PTR) -> BOOL ---
  99. // MessageBoxA :: proc(hWnd: HWND, lpText: LPCSTR, lpCaption: LPCSTR, uType: UINT) -> c_int ---
  100. MessageBoxW :: proc(hWnd: HWND, lpText: LPCWSTR, lpCaption: LPCWSTR, uType: UINT) -> c_int ---
  101. // MessageBoxExA :: proc(hWnd: HWND, lpText: LPCSTR, lpCaption: LPCSTR, uType: UINT, wLanguageId: WORD) -> c_int ---
  102. MessageBoxExW :: proc(hWnd: HWND, lpText: LPCWSTR, lpCaption: LPCWSTR, uType: UINT, wLanguageId: WORD) -> c_int ---
  103. ClipCursor :: proc(lpRect: LPRECT) -> BOOL ---
  104. GetCursorPos :: proc(lpPoint: LPPOINT) -> BOOL ---
  105. SetCursorPos :: proc(X: c_int, Y: c_int) -> BOOL ---
  106. SetCursor :: proc(hCursor: HCURSOR) -> HCURSOR ---
  107. EnumDisplaySettingsW :: proc(lpszDeviceName: LPCWSTR, iModeNum: DWORD, lpDevMode: ^DEVMODEW) -> BOOL ---
  108. BroadcastSystemMessageW :: proc(
  109. flags: DWORD,
  110. lpInfo: LPDWORD,
  111. Msg: UINT,
  112. wParam: WPARAM,
  113. lParam: LPARAM,
  114. ) -> c_long ---
  115. BroadcastSystemMessageExW :: proc(
  116. flags: DWORD,
  117. lpInfo: LPDWORD,
  118. Msg: UINT,
  119. wParam: WPARAM,
  120. lParam: LPARAM,
  121. pbsmInfo: PBSMINFO,
  122. ) -> c_long ---
  123. SendMessageTimeoutW :: proc(
  124. hWnd: HWND,
  125. Msg: UINT,
  126. wParam: WPARAM,
  127. lParam: LPARAM,
  128. fuFlags: UINT,
  129. uTimeout: UINT,
  130. lpdwResult: PDWORD_PTR,
  131. ) -> LRESULT ---
  132. GetSysColor :: proc(nIndex: c_int) -> DWORD ---
  133. GetSysColorBrush :: proc(nIndex: c_int) -> HBRUSH ---
  134. SetSysColors :: proc(cElements: c_int, lpaElements: ^INT, lpaRgbValues: ^COLORREF) -> BOOL ---
  135. MessageBeep :: proc(uType: UINT) -> BOOL ---
  136. IsDialogMessageW :: proc(hDlg: HWND, lpMsg: LPMSG) -> BOOL ---
  137. GetWindowTextLengthW :: proc(hWnd: HWND) -> c_int ---
  138. GetWindowTextW :: proc(hWnd: HWND, lpString: LPWSTR, nMaxCount: c_int) -> c_int ---
  139. SetWindowTextW :: proc(hWnd: HWND, lpString: LPCWSTR) -> BOOL ---
  140. CallWindowProcW :: proc(lpPrevWndFunc: WNDPROC, hWnd: HWND, Msg: UINT, wParam: WPARAM, lParam: LPARAM) -> LRESULT ---
  141. EnableWindow :: proc(hWnd: HWND, bEnable: BOOL) -> BOOL ---
  142. }
  143. CreateWindowW :: #force_inline proc "stdcall" (
  144. lpClassName: LPCTSTR,
  145. lpWindowName: LPCTSTR,
  146. dwStyle: DWORD,
  147. X: c_int,
  148. Y: c_int,
  149. nWidth: c_int,
  150. nHeight: c_int,
  151. hWndParent: HWND,
  152. hMenu: HMENU,
  153. hInstance: HINSTANCE,
  154. lpParam: LPVOID,
  155. ) -> HWND {
  156. return CreateWindowExW(
  157. 0,
  158. lpClassName,
  159. lpWindowName,
  160. dwStyle,
  161. X,
  162. Y,
  163. nWidth,
  164. nHeight,
  165. hWndParent,
  166. hMenu,
  167. hInstance,
  168. lpParam,
  169. )
  170. }
  171. when ODIN_ARCH == .amd64 {
  172. @(default_calling_convention="stdcall")
  173. foreign user32 {
  174. GetClassLongPtrW :: proc(hWnd: HWND, nIndex: c_int) -> ULONG_PTR ---
  175. SetClassLongPtrW :: proc(hWnd: HWND, nIndex: c_int, dwNewLong: LONG_PTR) -> ULONG_PTR ---
  176. GetWindowLongPtrW :: proc(hWnd: HWND, nIndex: c_int) -> LONG_PTR ---
  177. SetWindowLongPtrW :: proc(hWnd: HWND, nIndex: c_int, dwNewLong: LONG_PTR) -> LONG_PTR ---
  178. }
  179. } else when ODIN_ARCH == .i386 {
  180. GetClassLongPtrW :: GetClassLongW
  181. SetClassLongPtrW :: SetClassLongW
  182. GetWindowLongPtrW :: GetWindowLongW
  183. SetWindowLongPtrW :: GetWindowLongW
  184. }
  185. GET_SC_WPARAM :: #force_inline proc "contextless" (wParam: WPARAM) -> c_int {
  186. return c_int(wParam) & 0xFFF0
  187. }
  188. GET_WHEEL_DELTA_WPARAM :: #force_inline proc "contextless" (wParam: WPARAM) -> c_short {
  189. return cast(c_short)HIWORD(cast(DWORD)wParam)
  190. }
  191. GET_KEYSTATE_WPARAM :: #force_inline proc "contextless" (wParam: WPARAM) -> WORD {
  192. return LOWORD(cast(DWORD)wParam)
  193. }
  194. GET_NCHITTEST_WPARAM :: #force_inline proc "contextless" (wParam: WPARAM) -> c_short {
  195. return cast(c_short)LOWORD(cast(DWORD)wParam)
  196. }
  197. GET_XBUTTON_WPARAM :: #force_inline proc "contextless" (wParam: WPARAM) -> WORD {
  198. return HIWORD(cast(DWORD)wParam)
  199. }
  200. MAKEINTRESOURCEW :: #force_inline proc "contextless" (#any_int i: int) -> LPWSTR {
  201. return cast(LPWSTR)uintptr(WORD(i))
  202. }