2
0

windows.odin 22 KB

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