windows.odin 30 KB

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