windows.odin 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  1. foreign_system_library (
  2. "kernel32.lib" when ODIN_OS == "windows";
  3. "user32.lib" when ODIN_OS == "windows";
  4. "gdi32.lib" when ODIN_OS == "windows";
  5. "winmm.lib" when ODIN_OS == "windows";
  6. "shell32.lib" when ODIN_OS == "windows";
  7. )
  8. type (
  9. Handle rawptr;
  10. Hwnd Handle;
  11. Hdc Handle;
  12. Hinstance Handle;
  13. Hicon Handle;
  14. Hcursor Handle;
  15. Hmenu Handle;
  16. Hbrush Handle;
  17. Hgdiobj Handle;
  18. Hmodule Handle;
  19. Hmonitor Handle;
  20. Wparam uint;
  21. Lparam int;
  22. Lresult int;
  23. Bool i32;
  24. WndProc proc(Hwnd, u32, Wparam, Lparam) -> Lresult #cc_c;
  25. )
  26. type Point struct #ordered {
  27. x, y: i32,
  28. }
  29. type WndClassExA struct #ordered {
  30. size, style: u32,
  31. wnd_proc: WndProc,
  32. cls_extra, wnd_extra: i32,
  33. instance: Hinstance,
  34. icon: Hicon,
  35. cursor: Hcursor,
  36. background: Hbrush,
  37. menu_name, class_name: ^u8,
  38. sm: Hicon,
  39. }
  40. type Msg struct #ordered {
  41. hwnd: Hwnd,
  42. message: u32,
  43. wparam: Wparam,
  44. lparam: Lparam,
  45. time: u32,
  46. pt: Point,
  47. }
  48. type Rect struct #ordered {
  49. left: i32,
  50. top: i32,
  51. right: i32,
  52. bottom: i32,
  53. }
  54. type Filetime struct #ordered {
  55. lo, hi: u32,
  56. }
  57. type Systemtime struct #ordered {
  58. year, month: u16,
  59. day_of_week, day: u16,
  60. hour, minute, second, millisecond: u16,
  61. }
  62. type ByHandleFileInformation struct #ordered {
  63. file_attributes: u32,
  64. creation_time,
  65. last_access_time,
  66. last_write_time: Filetime,
  67. volume_serial_number,
  68. file_size_high,
  69. file_size_low,
  70. number_of_links,
  71. file_index_high,
  72. file_index_low: u32,
  73. }
  74. type FileAttributeData struct #ordered {
  75. file_attributes: u32,
  76. creation_time,
  77. last_access_time,
  78. last_write_time: Filetime,
  79. file_size_high,
  80. file_size_low: u32,
  81. }
  82. type FindData struct #ordered {
  83. file_attributes: u32,
  84. creation_time: Filetime,
  85. last_access_time: Filetime,
  86. last_write_time: Filetime,
  87. file_size_high: u32,
  88. file_size_low: u32,
  89. reserved0: u32,
  90. reserved1: u32,
  91. file_name: [MAX_PATH]u8,
  92. alternate_file_name: [14]u8,
  93. }
  94. type Security_Attributes struct #ordered {
  95. length: u32,
  96. security_descriptor: rawptr,
  97. inherit_handle: Bool,
  98. }
  99. type PixelFormatDescriptor struct #ordered {
  100. size,
  101. version,
  102. flags: u32,
  103. pixel_type,
  104. color_bits,
  105. red_bits,
  106. red_shift,
  107. green_bits,
  108. green_shift,
  109. blue_bits,
  110. blue_shift,
  111. alpha_bits,
  112. alpha_shift,
  113. accum_bits,
  114. accum_red_bits,
  115. accum_green_bits,
  116. accum_blue_bits,
  117. accum_alpha_bits,
  118. depth_bits,
  119. stencil_bits,
  120. aux_buffers,
  121. layer_type,
  122. reserved: u8,
  123. layer_mask,
  124. visible_mask,
  125. damage_mask: u32,
  126. }
  127. type Proc proc() #cc_c;
  128. const (
  129. MAPVK_VK_TO_CHAR = 2;
  130. MAPVK_VK_TO_VSC = 0;
  131. MAPVK_VSC_TO_VK = 1;
  132. MAPVK_VSC_TO_VK_EX = 3;
  133. )
  134. const INVALID_HANDLE = Handle(~int(0));
  135. const (
  136. FALSE: Bool = 0;
  137. TRUE = 1;
  138. )
  139. const (
  140. CS_VREDRAW = 0x0001;
  141. CS_HREDRAW = 0x0002;
  142. CS_OWNDC = 0x0020;
  143. CW_USEDEFAULT = -0x80000000;
  144. WS_OVERLAPPED = 0;
  145. WS_MAXIMIZEBOX = 0x00010000;
  146. WS_MINIMIZEBOX = 0x00020000;
  147. WS_THICKFRAME = 0x00040000;
  148. WS_SYSMENU = 0x00080000;
  149. WS_BORDER = 0x00800000;
  150. WS_CAPTION = 0x00C00000;
  151. WS_VISIBLE = 0x10000000;
  152. WS_POPUP = 0x80000000;
  153. WS_OVERLAPPEDWINDOW = WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_THICKFRAME|WS_MINIMIZEBOX|WS_MAXIMIZEBOX;
  154. WS_POPUPWINDOW = WS_POPUP | WS_BORDER | WS_SYSMENU;
  155. WM_DESTROY = 0x0002;
  156. WM_SIZE = 0x0005;
  157. WM_CLOSE = 0x0010;
  158. WM_ACTIVATEAPP = 0x001C;
  159. WM_QUIT = 0x0012;
  160. WM_KEYDOWN = 0x0100;
  161. WM_KEYUP = 0x0101;
  162. WM_SIZING = 0x0214;
  163. WM_SYSKEYDOWN = 0x0104;
  164. WM_SYSKEYUP = 0x0105;
  165. WM_WINDOWPOSCHANGED = 0x0047;
  166. WM_SETCURSOR = 0x0020;
  167. WM_CHAR = 0x0102;
  168. WM_ACTIVATE = 0x0006;
  169. WM_SETFOCUS = 0x0007;
  170. WM_KILLFOCUS = 0x0008;
  171. WM_USER = 0x0400;
  172. WM_MOUSEWHEEL = 0x020A;
  173. WM_MOUSEMOVE = 0x0200;
  174. WM_LBUTTONDOWN = 0x0201;
  175. WM_LBUTTONUP = 0x0202;
  176. WM_LBUTTONDBLCLK = 0x0203;
  177. WM_RBUTTONDOWN = 0x0204;
  178. WM_RBUTTONUP = 0x0205;
  179. WM_RBUTTONDBLCLK = 0x0206;
  180. WM_MBUTTONDOWN = 0x0207;
  181. WM_MBUTTONUP = 0x0208;
  182. WM_MBUTTONDBLCLK = 0x0209;
  183. PM_NOREMOVE = 0x0000;
  184. PM_REMOVE = 0x0001;
  185. PM_NOYIELD = 0x0002;
  186. BLACK_BRUSH = 4;
  187. SM_CXSCREEN = 0;
  188. SM_CYSCREEN = 1;
  189. SW_SHOW = 5;
  190. )
  191. const COLOR_BACKGROUND = Hbrush(int(1));
  192. const INVALID_SET_FILE_POINTER = ~u32(0);
  193. const HEAP_ZERO_MEMORY = 0x00000008;
  194. const INFINITE = 0xffffffff;
  195. const GWL_STYLE = -16;
  196. const Hwnd_TOP = Hwnd(uint(0));
  197. const BI_RGB = 0;
  198. const DIB_RGB_COLORS = 0x00;
  199. const SRCCOPY: u32 = 0x00cc0020;
  200. const (
  201. MONITOR_DEFAULTTONULL = 0x00000000;
  202. MONITOR_DEFAULTTOPRIMARY = 0x00000001;
  203. MONITOR_DEFAULTTONEAREST = 0x00000002;
  204. )
  205. const (
  206. SWP_FRAMECHANGED = 0x0020;
  207. SWP_NOOWNERZORDER = 0x0200;
  208. SWP_NOZORDER = 0x0004;
  209. SWP_NOSIZE = 0x0001;
  210. SWP_NOMOVE = 0x0002;
  211. )
  212. // Windows OpenGL
  213. const (
  214. PFD_TYPE_RGBA = 0;
  215. PFD_TYPE_COLORINDEX = 1;
  216. PFD_MAIN_PLANE = 0;
  217. PFD_OVERLAY_PLANE = 1;
  218. PFD_UNDERLAY_PLANE = -1;
  219. PFD_DOUBLEBUFFER = 1;
  220. PFD_STEREO = 2;
  221. PFD_DRAW_TO_WINDOW = 4;
  222. PFD_DRAW_TO_BITMAP = 8;
  223. PFD_SUPPORT_GDI = 16;
  224. PFD_SUPPORT_OPENGL = 32;
  225. PFD_GENERIC_FORMAT = 64;
  226. PFD_NEED_PALETTE = 128;
  227. PFD_NEED_SYSTEM_PALETTE = 0x00000100;
  228. PFD_SWAP_EXCHANGE = 0x00000200;
  229. PFD_SWAP_COPY = 0x00000400;
  230. PFD_SWAP_LAYER_BUFFERS = 0x00000800;
  231. PFD_GENERIC_ACCELERATED = 0x00001000;
  232. PFD_DEPTH_DONTCARE = 0x20000000;
  233. PFD_DOUBLEBUFFER_DONTCARE = 0x40000000;
  234. PFD_STEREO_DONTCARE = 0x80000000;
  235. )
  236. type GET_FILEEX_INFO_LEVELS i32;
  237. const (
  238. GetFileExInfoStandard: GET_FILEEX_INFO_LEVELS = 0;
  239. GetFileExMaxInfoLevel = 1;
  240. )
  241. foreign kernel32 {
  242. proc get_last_error () -> i32 #link_name "GetLastError";
  243. proc exit_process (exit_code: u32) #link_name "ExitProcess";
  244. proc get_module_handle_a(module_name: ^u8) -> Hinstance #link_name "GetModuleHandleA";
  245. proc sleep(ms: i32) -> i32 #link_name "Sleep";
  246. proc query_performance_frequency(result: ^i64) -> i32 #link_name "QueryPerformanceFrequency";
  247. proc query_performance_counter (result: ^i64) -> i32 #link_name "QueryPerformanceCounter";
  248. proc output_debug_string_a(c_str: ^u8) #link_name "OutputDebugStringA";
  249. proc get_command_line_a () -> ^u8 #link_name "GetCommandLineA";
  250. proc get_command_line_w () -> ^u16 #link_name "GetCommandLineW";
  251. proc get_system_metrics (index: i32) -> i32 #link_name "GetSystemMetrics";
  252. proc get_current_thread_id () -> u32 #link_name "GetCurrentThreadId";
  253. proc get_system_time_as_file_time(system_time_as_file_time: ^Filetime) #link_name "GetSystemTimeAsFileTime";
  254. proc file_time_to_local_file_time(file_time: ^Filetime, local_file_time: ^Filetime) -> Bool #link_name "FileTimeToLocalFileTime";
  255. proc file_time_to_system_time (file_time: ^Filetime, system_time: ^Systemtime) -> Bool #link_name "FileTimeToSystemTime";
  256. proc system_time_to_file_time (system_time: ^Systemtime, file_time: ^Filetime) -> Bool #link_name "SystemTimeToFileTime";
  257. proc close_handle (h: Handle) -> i32 #link_name "CloseHandle";
  258. proc get_std_handle(h: i32) -> Handle #link_name "GetStdHandle";
  259. proc create_file_a (filename: ^u8, desired_access, share_mode: u32,
  260. security: rawptr,
  261. creation, flags_and_attribs: u32, template_file: Handle) -> Handle #link_name "CreateFileA";
  262. proc read_file (h: Handle, buf: rawptr, to_read: u32, bytes_read: ^i32, overlapped: rawptr) -> Bool #link_name "ReadFile";
  263. proc write_file(h: Handle, buf: rawptr, len: i32, written_result: ^i32, overlapped: rawptr) -> Bool #link_name "WriteFile";
  264. proc get_file_size_ex (file_handle: Handle, file_size: ^i64) -> Bool #link_name "GetFileSizeEx";
  265. proc get_file_attributes_a (filename: ^u8) -> u32 #link_name "GetFileAttributesA";
  266. proc get_file_attributes_ex_a (filename: ^u8, info_level_id: GET_FILEEX_INFO_LEVELS, file_info: rawptr) -> Bool #link_name "GetFileAttributesExA";
  267. proc get_file_information_by_handle(file_handle: Handle, file_info: ^ByHandleFileInformation) -> Bool #link_name "GetFileInformationByHandle";
  268. proc get_file_type (file_handle: Handle) -> u32 #link_name "GetFileType";
  269. proc set_file_pointer(file_handle: Handle, distance_to_move: i32, distance_to_move_high: ^i32, move_method: u32) -> u32 #link_name "SetFilePointer";
  270. proc set_handle_information(obj: Handle, mask, flags: u32) -> Bool #link_name "SetHandleInformation";
  271. proc find_first_file_a(file_name : ^u8, data : ^FindData) -> Handle #link_name "FindFirstFileA";
  272. proc find_next_file_a (file : Handle, data : ^FindData) -> Bool #link_name "FindNextFileA";
  273. proc find_close (file : Handle) -> Bool #link_name "FindClose";
  274. proc heap_alloc (h: Handle, flags: u32, bytes: int) -> rawptr #link_name "HeapAlloc";
  275. proc heap_realloc (h: Handle, flags: u32, memory: rawptr, bytes: int) -> rawptr #link_name "HeapReAlloc";
  276. proc heap_free (h: Handle, flags: u32, memory: rawptr) -> Bool #link_name "HeapFree";
  277. proc get_process_heap() -> Handle #link_name "GetProcessHeap";
  278. proc create_semaphore_a (attributes: ^Security_Attributes, initial_count, maximum_count: i32, name: ^u8) -> Handle #link_name "CreateSemaphoreA";
  279. proc release_semaphore (semaphore: Handle, release_count: i32, previous_count: ^i32) -> Bool #link_name "ReleaseSemaphore";
  280. proc wait_for_single_object(handle: Handle, milliseconds: u32) -> u32 #link_name "WaitForSingleObject";
  281. proc interlocked_compare_exchange (dst: ^i32, exchange, comparand: i32) -> i32 #link_name "InterlockedCompareExchange";
  282. proc interlocked_exchange (dst: ^i32, desired: i32) -> i32 #link_name "InterlockedExchange";
  283. proc interlocked_exchange_add (dst: ^i32, desired: i32) -> i32 #link_name "InterlockedExchangeAdd";
  284. proc interlocked_and (dst: ^i32, desired: i32) -> i32 #link_name "InterlockedAnd";
  285. proc interlocked_or (dst: ^i32, desired: i32) -> i32 #link_name "InterlockedOr";
  286. proc interlocked_compare_exchange64(dst: ^i64, exchange, comparand: i64) -> i64 #link_name "InterlockedCompareExchange64";
  287. proc interlocked_exchange64 (dst: ^i64, desired: i64) -> i64 #link_name "InterlockedExchange64";
  288. proc interlocked_exchange_add64 (dst: ^i64, desired: i64) -> i64 #link_name "InterlockedExchangeAdd64";
  289. proc interlocked_and64 (dst: ^i64, desired: i64) -> i64 #link_name "InterlockedAnd64";
  290. proc interlocked_or64 (dst: ^i64, desired: i64) -> i64 #link_name "InterlockedOr64";
  291. proc mm_pause () #link_name "_mm_pause";
  292. proc read_write_barrier() #link_name "ReadWriteBarrier";
  293. proc write_barrier () #link_name "WriteBarrier";
  294. proc read_barrier () #link_name "ReadBarrier";
  295. proc load_library_a (c_str: ^u8) -> Hmodule #link_name "LoadLibraryA";
  296. proc free_library (h: Hmodule) #link_name "FreeLibrary";
  297. proc get_proc_address(h: Hmodule, c_str: ^u8) -> Proc #link_name "GetProcAddress";
  298. }
  299. foreign user32 {
  300. proc get_desktop_window () -> Hwnd #link_name "GetDesktopWindow";
  301. proc show_cursor (show : Bool) #link_name "ShowCursor";
  302. proc get_cursor_pos (p: ^Point) -> i32 #link_name "GetCursorPos";
  303. proc screen_to_client (h: Hwnd, p: ^Point) -> i32 #link_name "ScreenToClient";
  304. proc post_quit_message (exit_code: i32) #link_name "PostQuitMessage";
  305. proc set_window_text_a (hwnd: Hwnd, c_string: ^u8) -> Bool #link_name "SetWindowTextA";
  306. proc register_class_ex_a (wc: ^WndClassExA) -> i16 #link_name "RegisterClassExA";
  307. proc create_window_ex_a (ex_style: u32,
  308. class_name, title: ^u8,
  309. style: u32,
  310. x, y, w, h: i32,
  311. parent: Hwnd, menu: Hmenu, instance: Hinstance,
  312. param: rawptr) -> Hwnd #link_name "CreateWindowExA";
  313. proc show_window (hwnd: Hwnd, cmd_show: i32) -> Bool #link_name "ShowWindow";
  314. proc translate_message (msg: ^Msg) -> Bool #link_name "TranslateMessage";
  315. proc dispatch_message_a (msg: ^Msg) -> Lresult #link_name "DispatchMessageA";
  316. proc update_window (hwnd: Hwnd) -> Bool #link_name "UpdateWindow";
  317. proc get_message_a (msg: ^Msg, hwnd: Hwnd, msg_filter_min, msg_filter_max : u32) -> Bool #link_name "GetMessageA";
  318. proc peek_message_a (msg: ^Msg, hwnd: Hwnd,
  319. msg_filter_min, msg_filter_max, remove_msg: u32) -> Bool #link_name "PeekMessageA";
  320. proc post_message (hwnd: Hwnd, msg, wparam, lparam : u32) -> Bool #link_name "PostMessageA";
  321. proc def_window_proc_a (hwnd: Hwnd, msg: u32, wparam: Wparam, lparam: Lparam) -> Lresult #link_name "DefWindowProcA";
  322. proc adjust_window_rect (rect: ^Rect, style: u32, menu: Bool) -> Bool #link_name "AdjustWindowRect";
  323. proc get_active_window () -> Hwnd #link_name "GetActiveWindow";
  324. proc destroy_window (wnd: Hwnd) -> Bool #link_name "DestroyWindow";
  325. proc describe_pixel_format(dc: Hdc, pixel_format: i32, bytes : u32, pfd: ^PixelFormatDescriptor) -> i32 #link_name "DescribePixelFormat";
  326. proc get_monitor_info_a (monitor: Hmonitor, mi: ^MonitorInfo) -> Bool #link_name "GetMonitorInfoA";
  327. proc monitor_from_window (wnd: Hwnd, flags : u32) -> Hmonitor #link_name "MonitorFromWindow";
  328. proc set_window_pos (wnd: Hwnd, wndInsertAfter: Hwnd, x, y, width, height: i32, flags: u32) #link_name "SetWindowPos";
  329. proc get_window_placement (wnd: Hwnd, wndpl: ^WindowPlacement) -> Bool #link_name "GetWindowPlacement";
  330. proc set_window_placement (wnd: Hwnd, wndpl: ^WindowPlacement) -> Bool #link_name "SetWindowPlacement";
  331. proc get_window_rect (wnd: Hwnd, rect: ^Rect) -> Bool #link_name "GetWindowRect";
  332. proc get_window_long_ptr_a(wnd: Hwnd, index: i32) -> i64 #link_name "GetWindowLongPtrA";
  333. proc set_window_long_ptr_a(wnd: Hwnd, index: i32, new: i64) -> i64 #link_name "SetWindowLongPtrA";
  334. proc get_window_text (wnd: Hwnd, str: ^u8, maxCount: i32) -> i32 #link_name "GetWindowText";
  335. proc get_client_rect (hwnd: Hwnd, rect: ^Rect) -> Bool #link_name "GetClientRect";
  336. proc get_dc (h: Hwnd) -> Hdc #link_name "GetDC";
  337. proc release_dc (wnd: Hwnd, hdc: Hdc) -> i32 #link_name "ReleaseDC";
  338. proc map_virtual_key(scancode : u32, map_type : u32) -> u32 #link_name "MapVirtualKeyA";
  339. proc get_key_state (v_key: i32) -> i16 #link_name "GetKeyState";
  340. proc get_async_key_state(v_key: i32) -> i16 #link_name "GetAsyncKeyState";
  341. }
  342. foreign gdi32 {
  343. proc get_stock_object(fn_object: i32) -> Hgdiobj #link_name "GetStockObject";
  344. proc stretch_dibits( hdc: Hdc,
  345. x_dst, y_dst, width_dst, height_dst: i32,
  346. x_src, y_src, width_src, header_src: i32,
  347. bits: rawptr, bits_info: ^BitmapInfo,
  348. usage: u32,
  349. rop: u32) -> i32 #link_name "StretchDIBits";
  350. proc set_pixel_format (hdc: Hdc, pixel_format: i32, pfd: ^PixelFormatDescriptor) -> Bool #link_name "SetPixelFormat";
  351. proc choose_pixel_format(hdc: Hdc, pfd: ^PixelFormatDescriptor) -> i32 #link_name "ChoosePixelFormat";
  352. proc swap_buffers (hdc: Hdc) -> Bool #link_name "SwapBuffers";
  353. }
  354. foreign shell32 {
  355. proc command_line_to_argv_w(cmd_list: ^u16, num_args: ^i32) -> ^^u16 #link_name "CommandLineToArgvW";
  356. }
  357. foreign winmm {
  358. proc time_get_time() -> u32 #link_name "timeGetTime";
  359. }
  360. proc get_query_performance_frequency() -> i64 {
  361. var r: i64;
  362. query_performance_frequency(&r);
  363. return r;
  364. }
  365. proc HIWORD(wParam: Wparam) -> u16 { return u16((u32(wParam) >> 16) & 0xffff); }
  366. proc HIWORD(lParam: Lparam) -> u16 { return u16((u32(lParam) >> 16) & 0xffff); }
  367. proc LOWORD(wParam: Wparam) -> u16 { return u16(wParam); }
  368. proc LOWORD(lParam: Lparam) -> u16 { return u16(lParam); }
  369. proc is_key_down(key: KeyCode) -> bool #inline { return get_async_key_state(i32(key)) < 0; }
  370. const (
  371. MAX_PATH = 0x00000104;
  372. HANDLE_FLAG_INHERIT = 1;
  373. HANDLE_FLAG_PROTECT_FROM_CLOSE = 2;
  374. FILE_BEGIN = 0;
  375. FILE_CURRENT = 1;
  376. FILE_END = 2;
  377. FILE_SHARE_READ = 0x00000001;
  378. FILE_SHARE_WRITE = 0x00000002;
  379. FILE_SHARE_DELETE = 0x00000004;
  380. FILE_GENERIC_ALL = 0x10000000;
  381. FILE_GENERIC_EXECUTE = 0x20000000;
  382. FILE_GENERIC_WRITE = 0x40000000;
  383. FILE_GENERIC_READ = 0x80000000;
  384. FILE_APPEND_DATA = 0x0004;
  385. STD_INPUT_HANDLE = -10;
  386. STD_OUTPUT_HANDLE = -11;
  387. STD_ERROR_HANDLE = -12;
  388. CREATE_NEW = 1;
  389. CREATE_ALWAYS = 2;
  390. OPEN_EXISTING = 3;
  391. OPEN_ALWAYS = 4;
  392. TRUNCATE_EXISTING = 5;
  393. INVALID_FILE_ATTRIBUTES = -1;
  394. FILE_ATTRIBUTE_READONLY = 0x00000001;
  395. FILE_ATTRIBUTE_HIDDEN = 0x00000002;
  396. FILE_ATTRIBUTE_SYSTEM = 0x00000004;
  397. FILE_ATTRIBUTE_DIRECTORY = 0x00000010;
  398. FILE_ATTRIBUTE_ARCHIVE = 0x00000020;
  399. FILE_ATTRIBUTE_DEVICE = 0x00000040;
  400. FILE_ATTRIBUTE_NORMAL = 0x00000080;
  401. FILE_ATTRIBUTE_TEMPORARY = 0x00000100;
  402. FILE_ATTRIBUTE_SPARSE_FILE = 0x00000200;
  403. FILE_ATTRIBUTE_REPARSE_Point = 0x00000400;
  404. FILE_ATTRIBUTE_COMPRESSED = 0x00000800;
  405. FILE_ATTRIBUTE_OFFLINE = 0x00001000;
  406. FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = 0x00002000;
  407. FILE_ATTRIBUTE_ENCRYPTED = 0x00004000;
  408. FILE_TYPE_DISK = 0x0001;
  409. FILE_TYPE_CHAR = 0x0002;
  410. FILE_TYPE_PIPE = 0x0003;
  411. )
  412. type MonitorInfo struct #ordered {
  413. size: u32,
  414. monitor: Rect,
  415. work: Rect,
  416. flags: u32,
  417. }
  418. type WindowPlacement struct #ordered {
  419. length: u32,
  420. flags: u32,
  421. show_cmd: u32,
  422. min_pos: Point,
  423. max_pos: Point,
  424. normal_pos: Rect,
  425. }
  426. type BitmapInfoHeader struct #ordered {
  427. size: u32,
  428. width, height: i32,
  429. planes, bit_count: i16,
  430. compression: u32,
  431. size_image: u32,
  432. x_pels_per_meter: i32,
  433. y_pels_per_meter: i32,
  434. clr_used: u32,
  435. clr_important: u32,
  436. }
  437. type BitmapInfo struct #ordered {
  438. using header: BitmapInfoHeader,
  439. colors: [1]RgbQuad,
  440. }
  441. type RgbQuad struct #ordered { blue, green, red, reserved: u8 }
  442. type KeyCode enum i32 {
  443. Lbutton = 0x01,
  444. Rbutton = 0x02,
  445. Cancel = 0x03,
  446. Mbutton = 0x04,
  447. Back = 0x08,
  448. Tab = 0x09,
  449. Clear = 0x0C,
  450. Return = 0x0D,
  451. Shift = 0x10,
  452. Control = 0x11,
  453. Menu = 0x12,
  454. Pause = 0x13,
  455. Capital = 0x14,
  456. Kana = 0x15,
  457. Hangeul = 0x15,
  458. Hangul = 0x15,
  459. Junja = 0x17,
  460. Final = 0x18,
  461. Hanja = 0x19,
  462. Kanji = 0x19,
  463. Escape = 0x1B,
  464. Convert = 0x1C,
  465. NonConvert = 0x1D,
  466. Accept = 0x1E,
  467. ModeChange = 0x1F,
  468. Space = 0x20,
  469. Prior = 0x21,
  470. Next = 0x22,
  471. End = 0x23,
  472. Home = 0x24,
  473. Left = 0x25,
  474. Up = 0x26,
  475. Right = 0x27,
  476. Down = 0x28,
  477. Select = 0x29,
  478. Print = 0x2A,
  479. Execute = 0x2B,
  480. Snapshot = 0x2C,
  481. Insert = 0x2D,
  482. Delete = 0x2E,
  483. Help = 0x2F,
  484. Num0 = '0',
  485. Num1 = '1',
  486. Num2 = '2',
  487. Num3 = '3',
  488. Num4 = '4',
  489. Num5 = '5',
  490. Num6 = '6',
  491. Num7 = '7',
  492. Num8 = '8',
  493. Num9 = '9',
  494. A = 'A',
  495. B = 'B',
  496. C = 'C',
  497. D = 'D',
  498. E = 'E',
  499. F = 'F',
  500. G = 'G',
  501. H = 'H',
  502. I = 'I',
  503. J = 'J',
  504. K = 'K',
  505. L = 'L',
  506. M = 'M',
  507. N = 'N',
  508. O = 'O',
  509. P = 'P',
  510. Q = 'Q',
  511. R = 'R',
  512. S = 'S',
  513. T = 'T',
  514. U = 'U',
  515. V = 'V',
  516. W = 'W',
  517. X = 'X',
  518. Y = 'Y',
  519. Z = 'Z',
  520. Lwin = 0x5B,
  521. Rwin = 0x5C,
  522. Apps = 0x5D,
  523. Numpad0 = 0x60,
  524. Numpad1 = 0x61,
  525. Numpad2 = 0x62,
  526. Numpad3 = 0x63,
  527. Numpad4 = 0x64,
  528. Numpad5 = 0x65,
  529. Numpad6 = 0x66,
  530. Numpad7 = 0x67,
  531. Numpad8 = 0x68,
  532. Numpad9 = 0x69,
  533. Multiply = 0x6A,
  534. Add = 0x6B,
  535. Separator = 0x6C,
  536. Subtract = 0x6D,
  537. Decimal = 0x6E,
  538. Divide = 0x6F,
  539. F1 = 0x70,
  540. F2 = 0x71,
  541. F3 = 0x72,
  542. F4 = 0x73,
  543. F5 = 0x74,
  544. F6 = 0x75,
  545. F7 = 0x76,
  546. F8 = 0x77,
  547. F9 = 0x78,
  548. F10 = 0x79,
  549. F11 = 0x7A,
  550. F12 = 0x7B,
  551. F13 = 0x7C,
  552. F14 = 0x7D,
  553. F15 = 0x7E,
  554. F16 = 0x7F,
  555. F17 = 0x80,
  556. F18 = 0x81,
  557. F19 = 0x82,
  558. F20 = 0x83,
  559. F21 = 0x84,
  560. F22 = 0x85,
  561. F23 = 0x86,
  562. F24 = 0x87,
  563. Numlock = 0x90,
  564. Scroll = 0x91,
  565. Lshift = 0xA0,
  566. Rshift = 0xA1,
  567. Lcontrol = 0xA2,
  568. Rcontrol = 0xA3,
  569. Lmenu = 0xA4,
  570. Rmenu = 0xA5,
  571. ProcessKey = 0xE5,
  572. Attn = 0xF6,
  573. Crsel = 0xF7,
  574. Exsel = 0xF8,
  575. Ereof = 0xF9,
  576. Play = 0xFA,
  577. Zoom = 0xFB,
  578. Noname = 0xFC,
  579. Pa1 = 0xFD,
  580. OemClear = 0xFE,
  581. }